Fix expire.php to properly handle ttl and upgrade changes (delete old files when using diskcache).

This commit is contained in:
Retro_Guy 2024-06-25 02:32:40 -07:00
parent f66db66487
commit e78bf1b769
1 changed files with 24 additions and 15 deletions

View File

@ -6,6 +6,7 @@ include ("$file_newsportal");
$tmr = $spooldir . '/' . $config_name . '-expire-timer';
if (file_exists($tmr)) {
if (filemtime($tmr) + 86400 > time()) {
echo $tmr . " exists and is not expired\n";
exit();
}
}
@ -16,7 +17,7 @@ if (file_exists($lockfile)) {
} else {
$pid = false;
}
if (!$pid) {
if (! $pid) {
print "Starting expire...\n";
file_put_contents($lockfile, getmypid()); // create lockfile
} else {
@ -110,18 +111,6 @@ foreach ($grouplist as $groupline) {
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Caught exception: " . $e->getMessage(), FILE_APPEND);
}
}
// Delete article from cache
if ($enable_cache) {
$article_key = $cache_key_prefix . '_' . 'article.db3-' . $group . ':' . $row['number'];
$result = cache_delete($article_key, $memcacheD);
if ($enable_cache_logging) {
if ($result) {
file_put_contents($cache_log, "\n" . format_log_date() . " Deleted $article_key", FILE_APPEND);
} else {
file_put_contents($cache_log, "\n" . format_log_date() . " Failed to delete (or not found) $article_key", FILE_APPEND);
}
}
}
add_to_history($group, $row['number'], $row['msgid'], $status, $statusdate, $statusreason, $statusnotes);
$i ++;
}
@ -139,7 +128,7 @@ foreach ($grouplist as $groupline) {
]);
$articles_dbh = null;
}
if ($i > 50) {
echo "Rebuilding threads for " . $group . "...\n";
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Rebuilding threads...", FILE_APPEND);
@ -155,6 +144,26 @@ foreach ($grouplist as $groupline) {
echo "Expired " . $i . " articles for " . $group . "\n";
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expired " . $i . " articles", FILE_APPEND);
}
// Expire cache
// Delete article from cache
if ($enable_cache == 'diskcache') {
if ($enable_cache_logging) {
file_put_contents($cache_log, "\n" . format_log_date() . " Expiring cache files", FILE_APPEND);
}
$cache_files = scandir($cache_dir);
foreach ($cache_files as $file) {
$file_name = $cache_dir . $file;
if (is_file($file_name) && (filemtime($file_name) < (time() - $cache_ttl))) {
if ($enable_cache_logging) {
file_put_contents($cache_log, "\n" . format_log_date() . " Expired: " . $file_name, FILE_APPEND);
}
unlink($file_name);
}
}
if ($enable_cache_logging) {
file_put_contents($cache_log, "\n" . format_log_date() . " Expired cache files", FILE_APPEND);
}
}
unlink($lockfile);
touch($tmr);
@ -212,4 +221,4 @@ function convert_max_articles_to_days($group)
} else {
return false;
}
}
}