Add 'overrides' for some vars and try to read/write history as necessary.
This commit is contained in:
parent
65b8d86e25
commit
ae4136777b
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
include "../common/config.inc.php";
|
||||
|
||||
ini_set('memory_limit', '1536M');
|
||||
|
||||
/* Config file name should be the basename
|
||||
/*
|
||||
* Config file name should be the basename
|
||||
* of your path where you installed rslight
|
||||
* plus .inc.php.
|
||||
* So if installed in /var/www/html/rocksolid
|
||||
|
@ -18,13 +18,15 @@ if(file_exists($config_dir.$config_name.'.inc.php')) {
|
|||
}
|
||||
$installed_path = getcwd();
|
||||
|
||||
/* $config_path is a directory off the $config_dir
|
||||
/*
|
||||
* $config_path is a directory off the $config_dir
|
||||
* where specific files such as groups.txt
|
||||
* are located
|
||||
*/
|
||||
$config_path = $config_dir . $config_name . "/";
|
||||
$script_path = $config_dir . "/scripts/";
|
||||
$CONFIG = include ($config_file);
|
||||
$OVERRIDES = include ($config_dir . '/overrides.inc.php');
|
||||
|
||||
$logdir = $spooldir . '/log';
|
||||
$lockdir = $spooldir . '/lock';
|
||||
|
|
|
@ -1823,6 +1823,16 @@ function add_to_history($group, $number, $msgid, $status, $statusdate, $statusre
|
|||
$history_dbh = null;
|
||||
}
|
||||
|
||||
function clear_history_by_group($group) {
|
||||
global $spooldir;
|
||||
$history = $spooldir . '/history.db3';
|
||||
$history_dbh = history_db_open($history);
|
||||
$clear_stmt = $history_dbh->prepare("DELETE FROM history WHERE newsgroup=:group");
|
||||
$clear_stmt->bindParam(':group', $group);
|
||||
$clear_stmt->execute();
|
||||
$history_dbh = null;
|
||||
}
|
||||
|
||||
function get_db_data_from_msgid($msgid, $group)
|
||||
{
|
||||
global $spooldir;
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
return [
|
||||
// expire.php
|
||||
'max_articles_per_group' => 10000,
|
||||
|
||||
// spoolnews.php
|
||||
'maxarticles_per_run' => 100,
|
||||
'maxfirstrequest' => 100
|
||||
];
|
||||
?>
|
|
@ -15,8 +15,6 @@ if (posix_getsid($pid) === false || ! is_file($lockfile)) {
|
|||
exit();
|
||||
}
|
||||
|
||||
// pcntl_setpriority(0);
|
||||
|
||||
$webserver_group = $CONFIG['webserver_user'];
|
||||
$logfile = $logdir . '/expire.log';
|
||||
|
||||
|
@ -27,22 +25,32 @@ foreach ($grouplist as $groupline) {
|
|||
if ($group[0] == ':') {
|
||||
continue;
|
||||
}
|
||||
// Delete over $max_articles_per_group if so configured in $OVERRIDES
|
||||
$expire_conf = $CONFIG['expire_days'];
|
||||
$override_days = convert_max_articles_to_days($group);
|
||||
$expire_user = get_config_value('expire.conf', $group);
|
||||
|
||||
/*
|
||||
* Order of preference is:
|
||||
* 1. value in $config_dir/expire.conf
|
||||
* 2. value in section config file OR $config_dir/overrides.inc.php
|
||||
* whichever is lower
|
||||
*/
|
||||
$expire = $expire_conf;
|
||||
if ($override_days) {
|
||||
$expire = $override_days;
|
||||
}
|
||||
if ($expire_user !== false) {
|
||||
$expire = $expire_user;
|
||||
} else {
|
||||
$expire = $expire_conf;
|
||||
}
|
||||
$expire = trim($expire);
|
||||
if ($expire < 1) {
|
||||
continue;
|
||||
}
|
||||
$expireme = time() - ($expire * 86400);
|
||||
$showme = date('d M, Y', $expireme);
|
||||
|
||||
echo "Expire $group articles before $showme\n";
|
||||
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expiring articles before " . $showme, FILE_APPEND);
|
||||
echo "Expire $group articles before " . $showme . " (" . $expire . ") days\n";
|
||||
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expiring articles before " . $showme . " (" . $expire . ") days", FILE_APPEND);
|
||||
if ($CONFIG['article_database'] == '1') {
|
||||
$database = $spooldir . '/' . $group . '-articles.db3';
|
||||
if (is_file($database)) {
|
||||
|
@ -110,4 +118,34 @@ 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);
|
||||
}
|
||||
?>
|
||||
|
||||
function convert_max_articles_to_days($group)
|
||||
{
|
||||
global $spooldir, $OVERRIDES, $CONFIG;
|
||||
if ($OVERRIDES['max_articles_per_group'] > 0) {
|
||||
$count = $OVERRIDES['max_articles_per_group'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
$database = $spooldir . '/articles-overview.db3';
|
||||
$overview_dbh = overview_db_open($database);
|
||||
$overview_query = $overview_dbh->prepare('SELECT * FROM overview WHERE newsgroup=:newsgroup ORDER BY date DESC LIMIT :count');
|
||||
$overview_query->execute([
|
||||
':newsgroup' => $group,
|
||||
':count' => $count
|
||||
]);
|
||||
$i = 0;
|
||||
while ($row = $overview_query->fetch()) {
|
||||
$i ++;
|
||||
if ($i == $count) {
|
||||
$found = $row;
|
||||
}
|
||||
}
|
||||
$overview_dbh = null;
|
||||
if ($found) {
|
||||
$days = ((time() - $found['date']) / 86400);
|
||||
return (round($days));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -214,6 +214,7 @@ function import_articles($group) {
|
|||
$clear_stmt = $dbh->prepare("DELETE FROM overview WHERE newsgroup=:group");
|
||||
$clear_stmt->bindParam(':group', $group);
|
||||
$clear_stmt->execute();
|
||||
clear_history_by_group($group);
|
||||
$sql = 'INSERT OR IGNORE INTO overview(newsgroup, number, msgid, date, datestring, name, subject, refs, bytes, lines, xref) VALUES(?,?,?,?,?,?,?,?,?,?,?)';
|
||||
$stmt = $dbh->prepare($sql);
|
||||
|
||||
|
@ -282,6 +283,10 @@ function import_articles($group) {
|
|||
$this_snippet = get_search_snippet($body, $content_type[1]);
|
||||
$new_article_stmt->execute([$group, $local, $mid[1], $article_date, $from[1], $subject[1], $row['article'], $this_snippet]);
|
||||
$stmt->execute([$group, $local, $mid[1], $article_date, $finddate[1], $from[1], $subject[1], $references, $bytes, $lines, $xref]);
|
||||
$status = "respooled";
|
||||
$statusdate = time();
|
||||
$statusreason = "repair";
|
||||
add_to_history($group, $local, $mid[1], $status, $statusdate, $statusreason, $statusnotes);
|
||||
echo "\nImported: ".$group." ".$local;
|
||||
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Imported: ".$group.":".$local, FILE_APPEND);
|
||||
$i++;
|
||||
|
|
|
@ -34,11 +34,16 @@ $logfile = $logdir . '/spoolnews.log';
|
|||
# END MAIN CONFIGURATION
|
||||
@mkdir($spooldir . "/" . $config_name, 0755, 'recursive');
|
||||
|
||||
if (! isset($maxarticles_per_run)) {
|
||||
// Defaults
|
||||
$maxarticles_per_run = 100;
|
||||
}
|
||||
if (! isset($maxfirstrequest)) {
|
||||
$maxfirstrequest = 100;
|
||||
|
||||
// Overrides
|
||||
if ($OVERRIDES['maxarticles_per_run'] > 0) {
|
||||
$maxarticles_per_run = $OVERRIDES['maxarticles_per_run'];
|
||||
}
|
||||
if ($OVERRIDES['maxfirstrequest'] > 0) {
|
||||
$maxfirstrequest = $OVERRIDES['maxfirstrequest'];
|
||||
}
|
||||
|
||||
if (! isset($CONFIG['enable_nntp']) || $CONFIG['enable_nntp'] != true) {
|
||||
|
@ -420,6 +425,10 @@ function get_articles($ns, $group)
|
|||
}
|
||||
echo "\nRetrieved: " . $group . " " . $article;
|
||||
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Wrote to spool: " . $CONFIG['remote_server'] . " " . $group . ":" . $article, FILE_APPEND);
|
||||
$status = "spooled";
|
||||
$statusdate = time();
|
||||
$statusreason = "imported";
|
||||
add_to_history($group, $local, $mid[1], $status, $statusdate, $statusreason, $statusnotes);
|
||||
$i ++;
|
||||
$article ++;
|
||||
$local ++;
|
||||
|
|
Loading…
Reference in New Issue