84 lines
2.9 KiB
PHP
84 lines
2.9 KiB
PHP
<?php
|
||
/**
|
||
* @api-readonly
|
||
* Cache blade views list - shows when each cache view was last updated
|
||
*/
|
||
use Illuminate\Support\Facades\Storage;
|
||
|
||
$cacheViewsList = [];
|
||
|
||
// Cache klasörünün varlığını kontrol et
|
||
$cacheDirectory = storage_path('documents/cache');
|
||
|
||
if (is_dir($cacheDirectory)) {
|
||
// Tüm _last_updated.txt dosyalarını bul
|
||
$files = glob($cacheDirectory . '/*_last_updated.txt');
|
||
|
||
foreach ($files as $file) {
|
||
$fileName = basename($file);
|
||
|
||
// Cache adını çıkar (_last_updated.txt kısmını kaldır)
|
||
$cacheName = str_replace('_last_updated.txt', '', $fileName);
|
||
|
||
// Dosya içeriğini oku (tarih bilgisi)
|
||
$lastUpdated = file_get_contents($file);
|
||
$lastUpdated = trim($lastUpdated);
|
||
|
||
// Dosya bilgilerini al
|
||
$fileModTime = filemtime($file);
|
||
|
||
// View path'i bul (cache dosyasından)
|
||
$cacheFile = $cacheDirectory . '/' . $cacheName . '.blade.php';
|
||
$cacheExists = file_exists($cacheFile);
|
||
$cacheFileSize = $cacheExists ? filesize($cacheFile) : 0;
|
||
|
||
// Ne kadar zaman önce güncellendiğini hesapla
|
||
$timeDiff = '';
|
||
if ($lastUpdated) {
|
||
try {
|
||
$updateTime = strtotime($lastUpdated);
|
||
$now = time();
|
||
$diffSeconds = $now - $updateTime;
|
||
|
||
if ($diffSeconds < 60) {
|
||
$timeDiff = $diffSeconds . ' saniye önce';
|
||
} elseif ($diffSeconds < 3600) {
|
||
$timeDiff = floor($diffSeconds / 60) . ' dakika önce';
|
||
} elseif ($diffSeconds < 86400) {
|
||
$timeDiff = floor($diffSeconds / 3600) . ' saat önce';
|
||
} else {
|
||
$timeDiff = floor($diffSeconds / 86400) . ' gün önce';
|
||
}
|
||
} catch (\Exception $e) {
|
||
$timeDiff = '-';
|
||
}
|
||
}
|
||
|
||
$cacheViewsList[] = [
|
||
'id' => count($cacheViewsList) + 1,
|
||
'cache_name' => $cacheName,
|
||
'last_updated' => $lastUpdated ?: '-',
|
||
'time_ago' => $timeDiff ?: '-',
|
||
'cache_file_exists' => $cacheExists,
|
||
'cache_file_size' => $cacheExists ? formatBytes($cacheFileSize) : '-',
|
||
'cache_file_size_bytes' => $cacheFileSize,
|
||
'file_mod_time' => date('Y-m-d H:i:s', $fileModTime)
|
||
];
|
||
}
|
||
|
||
// Son güncelleme tarihine göre sırala (en yeni en üstte)
|
||
usort($cacheViewsList, function($a, $b) {
|
||
return strtotime($b['last_updated']) - strtotime($a['last_updated']);
|
||
});
|
||
}
|
||
|
||
// Sonucu JSON olarak döndür
|
||
header('Content-Type: application/json');
|
||
echo json_encode([
|
||
'success' => true,
|
||
'timestamp' => date('Y-m-d H:i:s'),
|
||
'total_count' => count($cacheViewsList),
|
||
'data' => $cacheViewsList
|
||
], JSON_PRETTY_PRINT);
|
||
?>
|