Clean old bugs in expire.php and add cache support.
This commit is contained in:
parent
c1c53e3d71
commit
47139a9467
|
@ -2,12 +2,21 @@
|
||||||
include "config.inc.php";
|
include "config.inc.php";
|
||||||
include ("$file_newsportal");
|
include ("$file_newsportal");
|
||||||
|
|
||||||
if (filemtime($spooldir . '/' . $config_name . '-expire-timer') + 86400 > time()) {
|
// Check timer
|
||||||
exit();
|
$tmr = $spooldir . '/' . $config_name . '-expire-timer';
|
||||||
|
if (file_exists($tmr)) {
|
||||||
|
if (filemtime($tmr) + 86400 > time()) {
|
||||||
|
exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Check if spoolnews running for section
|
||||||
$lockfile = $lockdir . '/' . $config_name . '-spoolnews.lock';
|
$lockfile = $lockdir . '/' . $config_name . '-spoolnews.lock';
|
||||||
$pid = file_get_contents($lockfile);
|
if (file_exists($lockfile)) {
|
||||||
if (posix_getsid($pid) === false || ! is_file($lockfile)) {
|
$pid = posix_getsid(file_get_contents($lockfile));
|
||||||
|
} else {
|
||||||
|
$pid = false;
|
||||||
|
}
|
||||||
|
if (!$pid) {
|
||||||
print "Starting expire...\n";
|
print "Starting expire...\n";
|
||||||
file_put_contents($lockfile, getmypid()); // create lockfile
|
file_put_contents($lockfile, getmypid()); // create lockfile
|
||||||
} else {
|
} else {
|
||||||
|
@ -18,6 +27,10 @@ if (posix_getsid($pid) === false || ! is_file($lockfile)) {
|
||||||
$webserver_group = $CONFIG['webserver_user'];
|
$webserver_group = $CONFIG['webserver_user'];
|
||||||
$logfile = $logdir . '/expire.log';
|
$logfile = $logdir . '/expire.log';
|
||||||
|
|
||||||
|
if (file_exists($config_dir . '/cache.inc.php')) {
|
||||||
|
include $config_dir . '/cache.inc.php';
|
||||||
|
}
|
||||||
|
|
||||||
$grouplist = file($config_dir . '/' . $config_name . '/groups.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
$grouplist = file($config_dir . '/' . $config_name . '/groups.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
foreach ($grouplist as $groupline) {
|
foreach ($grouplist as $groupline) {
|
||||||
$groupname = explode(' ', $groupline);
|
$groupname = explode(' ', $groupline);
|
||||||
|
@ -64,17 +77,17 @@ foreach ($grouplist as $groupline) {
|
||||||
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expiring articles database, overview database and writing history...", FILE_APPEND);
|
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expiring articles database, overview database and writing history...", FILE_APPEND);
|
||||||
|
|
||||||
$database = $spooldir . '/articles-overview.db3';
|
$database = $spooldir . '/articles-overview.db3';
|
||||||
$dbh = overview_db_open($database);
|
$overview_dbh = overview_db_open($database);
|
||||||
$query = $dbh->prepare('SELECT number FROM overview WHERE newsgroup=:newsgroup AND CAST(date AS int)<:expireme');
|
$overview_query = $overview_dbh->prepare('SELECT number,msgid FROM overview WHERE newsgroup=:newsgroup AND CAST(date AS int)<:expireme');
|
||||||
$query->execute([
|
$overview_query->execute([
|
||||||
':newsgroup' => $group,
|
':newsgroup' => $group,
|
||||||
':expireme' => $expireme
|
':expireme' => $expireme
|
||||||
]);
|
]);
|
||||||
$get_row = array();
|
$get_row = array();
|
||||||
while ($query_row = $query->fetch()) {
|
while ($query_row = $overview_query->fetch()) {
|
||||||
$get_row[] = $query_row;
|
$get_row[] = $query_row;
|
||||||
}
|
}
|
||||||
$stmt = $dbh->prepare('DELETE FROM overview WHERE newsgroup=:newsgroup AND CAST(date AS int)<:expireme');
|
$stmt = $overview_dbh->prepare('DELETE FROM overview WHERE newsgroup=:newsgroup AND CAST(date AS int)<:expireme');
|
||||||
$grouppath = preg_replace('/\./', '/', $group);
|
$grouppath = preg_replace('/\./', '/', $group);
|
||||||
$status = "deleted";
|
$status = "deleted";
|
||||||
$statusdate = time();
|
$statusdate = time();
|
||||||
|
@ -97,6 +110,18 @@ foreach ($grouplist as $groupline) {
|
||||||
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Caught exception: " . $e->getMessage(), FILE_APPEND);
|
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);
|
add_to_history($group, $row['number'], $row['msgid'], $status, $statusdate, $statusreason, $statusnotes);
|
||||||
$i ++;
|
$i ++;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +129,7 @@ foreach ($grouplist as $groupline) {
|
||||||
':newsgroup' => $group,
|
':newsgroup' => $group,
|
||||||
':expireme' => $expireme
|
':expireme' => $expireme
|
||||||
]);
|
]);
|
||||||
$dbh = null;
|
$overview_dbh = null;
|
||||||
if ($articles_dbh) {
|
if ($articles_dbh) {
|
||||||
// Delete any extraneous articles from group-articles database
|
// Delete any extraneous articles from group-articles database
|
||||||
$articles_stmt = $articles_dbh->prepare('DELETE FROM articles WHERE newsgroup=:newsgroup AND CAST(date AS int)<:expireme');
|
$articles_stmt = $articles_dbh->prepare('DELETE FROM articles WHERE newsgroup=:newsgroup AND CAST(date AS int)<:expireme');
|
||||||
|
@ -114,8 +139,7 @@ foreach ($grouplist as $groupline) {
|
||||||
]);
|
]);
|
||||||
$articles_dbh = null;
|
$articles_dbh = null;
|
||||||
}
|
}
|
||||||
unlink($lockfile);
|
|
||||||
touch($spooldir . '/' . $config_name . '-expire-timer');
|
|
||||||
if ($i > 50) {
|
if ($i > 50) {
|
||||||
echo "Rebuilding threads for " . $group . "...\n";
|
echo "Rebuilding threads for " . $group . "...\n";
|
||||||
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Rebuilding threads...", FILE_APPEND);
|
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Rebuilding threads...", FILE_APPEND);
|
||||||
|
@ -131,6 +155,8 @@ foreach ($grouplist as $groupline) {
|
||||||
echo "Expired " . $i . " articles for " . $group . "\n";
|
echo "Expired " . $i . " articles for " . $group . "\n";
|
||||||
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expired " . $i . " articles", FILE_APPEND);
|
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expired " . $i . " articles", FILE_APPEND);
|
||||||
}
|
}
|
||||||
|
unlink($lockfile);
|
||||||
|
touch($tmr);
|
||||||
|
|
||||||
function vacuum_group_database($group)
|
function vacuum_group_database($group)
|
||||||
{
|
{
|
||||||
|
@ -172,6 +198,7 @@ function convert_max_articles_to_days($group)
|
||||||
':count' => $count
|
':count' => $count
|
||||||
]);
|
]);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
$found = false;
|
||||||
while ($row = $overview_query->fetch()) {
|
while ($row = $overview_query->fetch()) {
|
||||||
$i ++;
|
$i ++;
|
||||||
if ($i == $count) {
|
if ($i == $count) {
|
||||||
|
|
Loading…
Reference in New Issue