$existing_value, 'pppoe' => $existing_value, 'default' => $existing_value ]; } } else { // Use new default structure echo "Using default template for '$key'\n"; $migrated_notifications[$key] = $new_default[$key]; } } // Copy other notification types as-is $other_keys = ['balance_send', 'balance_received', 'invoice_paid', 'invoice_balance', 'user_registration']; foreach ($other_keys as $key) { if (isset($existing_notifications[$key])) { $migrated_notifications[$key] = $existing_notifications[$key]; } else { $migrated_notifications[$key] = $new_default[$key]; } } // Create backup of original file if (file_exists($notifications_file)) { $backup_file = $UPLOAD_PATH . DIRECTORY_SEPARATOR . 'notifications.backup.' . date('Y-m-d_H-i-s') . '.json'; copy($notifications_file, $backup_file); echo "Created backup: $backup_file\n"; } // Save migrated notifications $result = file_put_contents($notifications_file, json_encode($migrated_notifications, JSON_PRETTY_PRINT)); if ($result !== false) { echo "Migration completed successfully!\n"; echo "New notification structure saved to: $notifications_file\n"; echo "\nMigration Summary:\n"; echo "- Converted " . count($plan_specific_keys) . " plan-specific templates\n"; echo "- Preserved " . count($other_keys) . " other notification types\n"; echo "- Backup created for safety\n"; echo "\nYou can now customize plan-type-specific templates in the admin panel.\n"; } else { echo "Error: Failed to save migrated notifications\n"; exit(1); } // Test the new structure echo "\nTesting new notification structure...\n"; $test_notifications = json_decode(file_get_contents($notifications_file), true); foreach ($plan_specific_keys as $key) { if (isset($test_notifications[$key]) && is_array($test_notifications[$key])) { echo "✓ Template '$key' is properly structured\n"; } else { echo "✗ Template '$key' has issues\n"; } } echo "\nMigration completed!\n";