cinema-studio-pro/backend/cleanup.php
2026-01-13 14:52:37 +05:30

64 lines
1.7 KiB
PHP

<?php
/**
* Cleanup Script for Expired Images
* Run this via cron every hour to delete images older than 24 hours
*
* Cron example (runs every hour):
* 0 * * * * /usr/bin/php /path/to/cleanup.php >> /path/to/cleanup.log 2>&1
*/
require_once 'session_manager.php';
// Check if running from command line or web
$isCLI = php_sapi_name() === 'cli';
if (!$isCLI) {
// If accessed via web, require authentication or disable
// For now, we'll allow it but you should add authentication in production
header('Content-Type: application/json');
}
try {
$result = SessionManager::cleanupExpiredImages();
$output = [
'success' => true,
'message' => "Cleanup completed successfully",
'cleaned_images' => $result['cleaned'],
'errors' => $result['errors'],
'timestamp' => $result['timestamp']
];
if ($isCLI) {
echo "=== Image Cleanup Report ===\n";
echo "Timestamp: {$result['timestamp']}\n";
echo "Images cleaned: {$result['cleaned']}\n";
if (!empty($result['errors'])) {
echo "Errors encountered: " . count($result['errors']) . "\n";
foreach ($result['errors'] as $error) {
echo " - $error\n";
}
}
echo "===========================\n\n";
} else {
echo json_encode($output, JSON_PRETTY_PRINT);
}
exit(0);
} catch (Exception $e) {
$output = [
'success' => false,
'error' => $e->getMessage(),
'timestamp' => date('Y-m-d H:i:s')
];
if ($isCLI) {
echo "ERROR: {$e->getMessage()}\n";
exit(1);
} else {
http_response_code(500);
echo json_encode($output, JSON_PRETTY_PRINT);
exit(1);
}
}