diff --git a/Rocksolid_Light/rocksolid/newsportal.php b/Rocksolid_Light/rocksolid/newsportal.php index 88c6519..b521785 100644 --- a/Rocksolid_Light/rocksolid/newsportal.php +++ b/Rocksolid_Light/rocksolid/newsportal.php @@ -653,23 +653,24 @@ function groups_show($gruppen) } else { $lastarticleinfo['date'] = 0; } - - // Look up last article info for group (np does not write this file sometimes for some reason) - $database = $spooldir . '/articles-overview.db3'; - $table = 'overview'; - $articles_dbh = overview_db_open($database); - $articles_query = $articles_dbh->prepare('SELECT * FROM overview WHERE newsgroup=:group ORDER BY date DESC LIMIT 2'); - $articles_query->execute([ - 'group' => $g->name - ]); - $found = 0; - while ($row = $articles_query->fetch()) { - $found = 1; - break; - } - $articles_dbh = null; - if ($found == 1) { - $lastarticleinfo['date'] = $row['date']; + if ($lastarticleinfo['date'] < 1) { + // Look up last article info for group (np does not write this file sometimes for some reason) + $database = $spooldir . '/articles-overview.db3'; + $table = 'overview'; + $articles_dbh = overview_db_open($database); + $articles_query = $articles_dbh->prepare('SELECT * FROM overview WHERE newsgroup=:group ORDER BY date DESC LIMIT 2'); + $articles_query->execute([ + 'group' => $g->name + ]); + $found = 0; + while ($row = $articles_query->fetch()) { + $found = 1; + break; + } + $articles_dbh = null; + if ($found == 1) { + $lastarticleinfo['date'] = $row['date']; + } } if (isset($userdata[$g->name])) { $groupdisplay .= '

'; @@ -1499,7 +1500,7 @@ function mail_db_open($database, $table = 'messages') return ($dbh); } -function threads_db_open($database, $table="threads") +function threads_db_open($database, $table = "threads") { try { $dbh = new PDO('sqlite:' . $database); @@ -1569,7 +1570,8 @@ function overview_db_open($database, $table = 'overview') bytes TEXT, lines TEXT, xref TEXT, - unique (newsgroup, msgid))"); + unique (newsgroup, msgid), + unique (newsgroup, number))"); $stmt = $dbh->query('CREATE INDEX IF NOT EXISTS id_date on ' . $table . '(date)'); $stmt->execute(); $stmt = $dbh->query('CREATE INDEX IF NOT EXISTS id_newsgroup on ' . $table . '(newsgroup)'); diff --git a/Rocksolid_Light/rslight/scripts/expire.php b/Rocksolid_Light/rslight/scripts/expire.php index 681ac38..77515f8 100755 --- a/Rocksolid_Light/rslight/scripts/expire.php +++ b/Rocksolid_Light/rslight/scripts/expire.php @@ -15,6 +15,8 @@ if (posix_getsid($pid) === false || ! is_file($lockfile)) { exit(); } +// pcntl_setpriority(0); + $webserver_group = $CONFIG['webserver_user']; $logfile = $logdir . '/expire.log'; @@ -42,26 +44,19 @@ foreach ($grouplist as $groupline) { echo "Expire $group articles before $showme\n"; file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expiring articles before " . $showme, FILE_APPEND); if ($CONFIG['article_database'] == '1') { - echo "Expiring article database...\n"; - file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expiring article database...", FILE_APPEND); $database = $spooldir . '/' . $group . '-articles.db3'; if (is_file($database)) { $articles_dbh = article_db_open($database); - $articles_query = $articles_dbh->prepare('DELETE FROM articles WHERE newsgroup=:newsgroup AND date<:expireme'); - $articles_query->execute([ - ':newsgroup' => $group, - ':expireme' => $expireme - ]); - $articles_dbh = null; + $articles_stmt = $articles_dbh->prepare('DELETE FROM articles WHERE newsgroup=:newsgroup AND number=:number'); } } // Expire tradspool and remove from newsportal - echo "Expiring overview database and writing history...\n"; - file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $group . " Expiring overview database and writing history...", FILE_APPEND); + 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); $database = $spooldir . '/articles-overview.db3'; $dbh = overview_db_open($database); - $query = $dbh->prepare('SELECT * FROM overview WHERE newsgroup=:newsgroup AND date<:expireme'); + $query = $dbh->prepare('SELECT number FROM overview WHERE newsgroup=:newsgroup AND date<:expireme'); $query->execute([ ':newsgroup' => $group, ':expireme' => $expireme @@ -76,8 +71,20 @@ foreach ($grouplist as $groupline) { if (is_file($spooldir . '/articles/' . $grouppath . '/' . $row['number'])) { unlink($spooldir . '/articles/' . $grouppath . '/' . $row['number']); } + 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); + } + } add_to_history($group, $row['number'], $row['msgid'], $status, $statusdate, $statusreason, $statusnotes); - thread_cache_removearticle($group, $row['number']); $i ++; } $stmt->execute([ @@ -85,6 +92,9 @@ foreach ($grouplist as $groupline) { ':expireme' => $expireme ]); $dbh = null; + if ($articles_dbh) { + $articles_dbh = null; + } unlink($lockfile); touch($spooldir . '/' . $config_name . '-expire-timer'); echo "Expired " . $i . " articles for " . $group . "\n"; diff --git a/Rocksolid_Light/rslight/scripts/spoolnews.php b/Rocksolid_Light/rslight/scripts/spoolnews.php index 0e9dcf1..734d0d0 100755 --- a/Rocksolid_Light/rslight/scripts/spoolnews.php +++ b/Rocksolid_Light/rslight/scripts/spoolnews.php @@ -221,6 +221,19 @@ function get_articles($ns, $group) } $dbh = null; + // Check history database for deleted message-ids + $database = $spooldir . '/history.db3'; + $table = 'history'; + $dbh = history_db_open($database, $table); + $stmt = $dbh->prepare("SELECT msgid FROM $table WHERE newsgroup=:newsgroup"); + $stmt->bindParam(':newsgroup', $nntp_group); + $stmt->execute(); + while ($row = $stmt->fetch()) { + $msgids[$row['msgid']] = true; + break; + } + $dbh = null; + // Overview database $database = $spooldir . '/articles-overview.db3'; $table = 'overview'; @@ -269,7 +282,7 @@ function get_articles($ns, $group) $response = line_read($ns); if (strcmp(substr($response, 0, 3), "220") != 0) { echo "\n" . $response; - file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Unexpected response to ARTICLE command: " . $response, FILE_APPEND); + file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " " . $response, FILE_APPEND); $article ++; continue; } @@ -476,7 +489,12 @@ function create_spool_groups($in_groups, $out_groups) fseek($groupout, 0); $found = 0; while (($buffer = fgets($groupout)) !== false) { - if (stripos($buffer, $thisgroup[0]) !== false) { + // $in_groups = $file_groups = $config_path . "groups.txt"; + // $out_groups = $local_groupfile = $spooldir . "/" . $config_name . "/local_groups.txt"; + // $out_groups = $remote_groupfile = $spooldir . "/" . $config_name . "/" . $CONFIG['remote_server'] . ":" . $CONFIG['remote_port'] . ".txt"; + // $thisgroup[0] is from $in_groups + // $buffer is from $out_groups + if (trim($thisgroup[0]) == trim($buffer)) { $found = 1; break; } diff --git a/Rocksolid_Light/version.txt b/Rocksolid_Light/version.txt index ac39a10..f374f66 100644 --- a/Rocksolid_Light/version.txt +++ b/Rocksolid_Light/version.txt @@ -1 +1 @@ -0.9.0 +0.9.1