Files
citrus-cms/resources/views/admin-ajax/delete-today-logs.blade.php
T
2026-04-28 21:15:09 +03:00

42 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
use Illuminate\Support\Facades\Storage;
use Carbon\Carbon;
// CSRF token kontrolü
if (!isset($_POST['_token']) || !csrf_token()) {
echo json_encode(['status' => 'error', 'message' => 'CSRF token error']);
exit();
}
try {
// Bugünün tarihini al
$today = Carbon::today()->format('Y-m-d');
$logsPath = storage_path('logs');
$deletedCount = 0;
// Tüm log dosyalarını tara
$logFiles = glob($logsPath . '/*.log');
foreach ($logFiles as $logFile) {
$fileName = basename($logFile);
// Laravel log dosya formatı: laravel-YYYY-MM-DD.log
if (preg_match('/truncgil-' . $today . '\.log$/', $fileName)) {
if (unlink($logFile)) {
$deletedCount++;
}
}
}
echo json_encode([
'status' => 'success',
'message' => $deletedCount . ' log files have been successfully deleted',
'deleted_count' => $deletedCount
]);
} catch (Exception $e) {
echo json_encode([
'status' => 'error',
'message' => 'An error occurred while deleting log files: ' . $e->getMessage()
]);
}
?>