2020-11-29 01:55:31 +01:00
|
|
|
<?php
|
2023-08-20 13:58:18 +02:00
|
|
|
include "config.inc.php";
|
|
|
|
include ("$file_newsportal");
|
2020-11-29 01:55:31 +01:00
|
|
|
|
2023-08-20 13:58:18 +02:00
|
|
|
if (filemtime($spooldir . '/' . $config_name . '-expire-timer') + 86400 > time()) {
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$lockfile = $lockdir . '/' . $config_name . '-spoolnews.lock';
|
|
|
|
$pid = file_get_contents($lockfile);
|
|
|
|
if (posix_getsid($pid) === false || ! is_file($lockfile)) {
|
2020-11-29 01:55:31 +01:00
|
|
|
print "Starting expire...\n";
|
|
|
|
file_put_contents($lockfile, getmypid()); // create lockfile
|
2023-08-20 13:58:18 +02:00
|
|
|
} else {
|
2020-11-29 01:55:31 +01:00
|
|
|
print "expire currently running\n";
|
2023-08-20 13:58:18 +02:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2023-08-23 21:25:21 +02:00
|
|
|
// pcntl_setpriority(0);
|
|
|
|
|
2023-08-20 13:58:18 +02:00
|
|
|
$webserver_group = $CONFIG['webserver_user'];
|
|
|
|
$logfile = $logdir . '/expire.log';
|
|
|
|
|
|
|
|
$grouplist = file($config_dir . '/' . $config_name . '/groups.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
|
|
foreach ($grouplist as $groupline) {
|
|
|
|
$groupname = explode(' ', $groupline);
|
|
|
|
$group = $groupname[0];
|
|
|
|
if ($group[0] == ':') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$expire_conf = $CONFIG['expire_days'];
|
|
|
|
$expire_user = get_config_value('expire.conf', $group);
|
2020-11-29 01:55:31 +01:00
|
|
|
|
2023-08-20 13:58:18 +02:00
|
|
|
if ($expire_user !== false) {
|
|
|
|
$expire = $expire_user;
|
|
|
|
} else {
|
|
|
|
$expire = $expire_conf;
|
|
|
|
}
|
|
|
|
if ($expire < 1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$expireme = time() - ($expire * 86400);
|
|
|
|
$showme = date('d M, Y', $expireme);
|
2020-12-19 02:14:39 +01:00
|
|
|
|
2023-08-20 13:58:18 +02:00
|
|
|
echo "Expire $group articles before $showme\n";
|
2023-08-20 14:01:55 +02:00
|
|
|
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expiring articles before " . $showme, FILE_APPEND);
|
2023-08-20 13:58:18 +02:00
|
|
|
if ($CONFIG['article_database'] == '1') {
|
|
|
|
$database = $spooldir . '/' . $group . '-articles.db3';
|
|
|
|
if (is_file($database)) {
|
|
|
|
$articles_dbh = article_db_open($database);
|
2023-08-23 21:25:21 +02:00
|
|
|
$articles_stmt = $articles_dbh->prepare('DELETE FROM articles WHERE newsgroup=:newsgroup AND number=:number');
|
2023-08-20 13:58:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Expire tradspool and remove from newsportal
|
2023-08-23 21:25:21 +02:00
|
|
|
echo "Expiring articles database, overview database and writing history...\n";
|
|
|
|
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expiring articles database, overview database and writing history...", FILE_APPEND);
|
2023-08-16 18:41:13 +02:00
|
|
|
|
2023-08-20 13:58:18 +02:00
|
|
|
$database = $spooldir . '/articles-overview.db3';
|
2023-08-16 18:41:13 +02:00
|
|
|
$dbh = overview_db_open($database);
|
2023-08-23 21:25:21 +02:00
|
|
|
$query = $dbh->prepare('SELECT number FROM overview WHERE newsgroup=:newsgroup AND date<:expireme');
|
2023-08-20 13:58:18 +02:00
|
|
|
$query->execute([
|
|
|
|
':newsgroup' => $group,
|
|
|
|
':expireme' => $expireme
|
|
|
|
]);
|
2023-08-25 13:21:06 +02:00
|
|
|
$get_row = array();
|
|
|
|
while ($query_row = $query->fetch()) {
|
|
|
|
$get_row[] = $query_row;
|
|
|
|
}
|
2023-08-19 17:03:25 +02:00
|
|
|
$stmt = $dbh->prepare('DELETE FROM overview WHERE newsgroup=:newsgroup AND date<:expireme');
|
2023-08-16 18:41:13 +02:00
|
|
|
$grouppath = preg_replace('/\./', '/', $group);
|
|
|
|
$status = "deleted";
|
|
|
|
$statusdate = time();
|
|
|
|
$statusreason = "expired";
|
2023-08-20 13:58:18 +02:00
|
|
|
$i = 0;
|
2023-08-25 13:21:06 +02:00
|
|
|
foreach($get_row as $row) {
|
2023-08-20 13:58:18 +02:00
|
|
|
if (is_file($spooldir . '/articles/' . $grouppath . '/' . $row['number'])) {
|
|
|
|
unlink($spooldir . '/articles/' . $grouppath . '/' . $row['number']);
|
2023-08-08 14:54:15 +02:00
|
|
|
}
|
2023-08-23 21:25:21 +02:00
|
|
|
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expiring:" . $row['number'], FILE_APPEND);
|
|
|
|
if ($CONFIG['article_database'] == '1') {
|
|
|
|
try {
|
|
|
|
$articles_dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
$articles_stmt->execute([
|
|
|
|
':newsgroup' => $group,
|
|
|
|
':number' => $row['number']
|
|
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo 'Caught exception: ' . $e->getMessage();
|
|
|
|
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Caught exception: " . $e->getMessage(), FILE_APPEND);
|
|
|
|
}
|
|
|
|
}
|
2023-08-16 18:41:13 +02:00
|
|
|
add_to_history($group, $row['number'], $row['msgid'], $status, $statusdate, $statusreason, $statusnotes);
|
2023-08-20 13:58:18 +02:00
|
|
|
$i ++;
|
2020-11-29 01:55:31 +01:00
|
|
|
}
|
2023-08-20 13:58:18 +02:00
|
|
|
$stmt->execute([
|
|
|
|
':newsgroup' => $group,
|
|
|
|
':expireme' => $expireme
|
|
|
|
]);
|
2023-08-16 18:41:13 +02:00
|
|
|
$dbh = null;
|
2023-08-23 21:25:21 +02:00
|
|
|
if ($articles_dbh) {
|
2023-08-26 12:43:11 +02:00
|
|
|
// Delete any extraneous articles from group-articles database
|
|
|
|
$articles_stmt = $articles_dbh->prepare('DELETE FROM articles WHERE newsgroup=:newsgroup AND date<:expireme');
|
|
|
|
$articles_stmt->execute([
|
|
|
|
':newsgroup' => $group,
|
|
|
|
':expireme' => $expireme
|
|
|
|
]);
|
2023-08-23 21:25:21 +02:00
|
|
|
$articles_dbh = null;
|
|
|
|
}
|
2023-08-16 18:41:13 +02:00
|
|
|
unlink($lockfile);
|
2023-08-20 13:58:18 +02:00
|
|
|
touch($spooldir . '/' . $config_name . '-expire-timer');
|
|
|
|
echo "Expired " . $i . " articles for " . $group . "\n";
|
|
|
|
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expired " . $i . " articles", FILE_APPEND);
|
2023-08-19 17:03:25 +02:00
|
|
|
}
|
2020-11-29 01:55:31 +01:00
|
|
|
?>
|