<?php
// Production Cleanup Script
echo "<h2>M-AUTO Production Cleanup</h2>";
echo "<p>This script removes development and testing files before production deployment.</p>";
// Files to remove in production
$files_to_remove = [
// Development scripts
'server_check.php',
'export_database.php',
'deployment_checklist.php',
'update_includes.php',
'update_urls.php',
'cleanup_for_production.php',
// Test files
'test_car_gallery.php',
'test_fuel_type.php',
'quick_test_gallery.php',
'setup.php',
// Schema update files (keep only the main one)
'update_schema_users_role.php',
'update_schema_v2.php',
'update_schema_v3.php',
'update_schema_v4.php',
'update_schema_v5.php',
'update_schema_about.php',
'update_schema_car_gallery.php',
'update_schema_fuel_type.php',
'update_schema_videos.php',
// Backup files (if any)
'database_backup_*.sql'
];
$removed_count = 0;
$not_found_count = 0;
echo "<h3>Removing Development Files:</h3>";
foreach ($files_to_remove as $file) {
if (strpos($file, '*') !== false) {
// Handle wildcard files
$pattern = str_replace('*', '', $file);
$matching_files = glob($pattern . '*');
foreach ($matching_files as $matching_file) {
if (file_exists($matching_file)) {
if (unlink($matching_file)) {
echo "<div style='color: green;'>✓ Removed: $matching_file</div>";
$removed_count++;
} else {
echo "<div style='color: red;'>✗ Failed to remove: $matching_file</div>";
}
}
}
} else {
// Handle regular files
if (file_exists($file)) {
if (unlink($file)) {
echo "<div style='color: green;'>✓ Removed: $file</div>";
$removed_count++;
} else {
echo "<div style='color: red;'>✗ Failed to remove: $file</div>";
}
} else {
echo "<div style='color: gray;'>- Not found: $file</div>";
$not_found_count++;
}
}
}
// Remove empty directories if any
$dirs_to_check = ['temp', 'tmp', 'cache'];
echo "<h3>Checking for Empty Directories:</h3>";
foreach ($dirs_to_check as $dir) {
if (is_dir($dir)) {
$files = scandir($dir);
if (count($files) <= 2) { // Only . and ..
if (rmdir($dir)) {
echo "<div style='color: green;'>✓ Removed empty directory: $dir</div>";
} else {
echo "<div style='color: orange;'>⚠ Could not remove directory: $dir</div>";
}
} else {
echo "<div style='color: blue;'>ℹ Directory not empty: $dir</div>";
}
}
}
// Check for log files
echo "<h3>Checking for Log Files:</h3>";
$log_files = glob('*.log');
if (!empty($log_files)) {
foreach ($log_files as $log_file) {
if (unlink($log_file)) {
echo "<div style='color: green;'>✓ Removed log file: $log_file</div>";
$removed_count++;
} else {
echo "<div style='color: red;'>✗ Failed to remove log file: $log_file</div>";
}
}
} else {
echo "<div style='color: gray;'>- No log files found</div>";
}
// Summary
echo "<hr>";
echo "<h3>Cleanup Summary</h3>";
echo "<div style='background: #d4edda; padding: 15px; border-radius: 5px; color: #155724;'>";
echo "<strong>Files Removed:</strong> $removed_count<br>";
echo "<strong>Files Not Found:</strong> $not_found_count<br>";
echo "<strong>Status:</strong> Production cleanup completed successfully!";
echo "</div>";
// Final recommendations
echo "<hr>";
echo "<h3>Final Production Checklist</h3>";
echo "<div style='background: #d1ecf1; padding: 15px; border-radius: 5px; color: #0c5460;'>";
echo "<strong>Before going live:</strong><br>";
echo "1. ✓ Development files removed<br>";
echo "2. □ Update database credentials in includes/config.php<br>";
echo "3. □ Test all functionality<br>";
echo "4. □ Install SSL certificate<br>";
echo "5. □ Enable HTTPS redirect<br>";
echo "6. □ Set up monitoring and backups<br>";
echo "7. □ Update DNS settings to point to new server<br>";
echo "8. □ Test from different devices and browsers";
echo "</div>";
echo "<div style='background: #fff3cd; padding: 15px; border-radius: 5px; color: #856404; margin-top: 15px;'>";
echo "<strong>⚠ Important:</strong><br>";
echo "This cleanup script will delete itself when run. Make sure you have completed all necessary tasks before running it on the production server.";
echo "</div>";
echo "<p><strong>Cleanup completed on:</strong> " . date('Y-m-d H:i:s') . "</p>";
?>