From 8231373c801c9f93571d0d2112a2525c6aab0f43 Mon Sep 17 00:00:00 2001 From: Retro_Guy Date: Tue, 2 Jan 2024 07:54:56 -0700 Subject: [PATCH] Handle stream error in spoolnews.php to avoid skipping groups. --- Rocksolid_Light/rocksolid/lib/thread.inc.php | 15 +++++++++-- Rocksolid_Light/rslight/scripts/spoolnews.php | 25 ++++++++++++++----- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Rocksolid_Light/rocksolid/lib/thread.inc.php b/Rocksolid_Light/rocksolid/lib/thread.inc.php index 746beac..27a384c 100644 --- a/Rocksolid_Light/rocksolid/lib/thread.inc.php +++ b/Rocksolid_Light/rocksolid/lib/thread.inc.php @@ -296,12 +296,23 @@ function thread_mycompare($a, $b) function thread_load_newsserver(&$ns, $groupname, $poll) { global $spooldir, $logdir, $maxarticles, $maxfetch, $initialfetch, $maxarticles_extra, $config_name; - global $text_error, $text_thread, $compress_spoolfiles, $server; + global $text_error, $text_thread, $compress_spoolfiles, $server, $CONFIG; global $www_charset, $iconv_enable, $thread_show, $thread_sort_order; $logfile = $logdir . '/newsportal.log'; $maxfetch = 0; $idstring = "0.36," . $server . "," . $compress_spoolfiles . "," . $maxarticles . "," . $maxarticles_extra . "," . $maxfetch . "," . $initialfetch . "," . $www_charset . ',' . $iconv_enable . ',' . $thread_show["replies"]; - $overviewformat = thread_overview_read($ns); + if ($CONFIG['enable_nntp'] == '1') { + $overviewfmt = array( + "Subject:", + "From:", + "Date:", + "Message-ID:", + "References:", + "Bytes:" + ); + } else { + $overviewformat = thread_overview_read($ns); + } $spoolfilename = $spooldir . '/' . $groupname . '-data.db3'; fputs($ns, "GROUP $groupname\r\n"); // select a group $groupinfo = explode(" ", line_read($ns)); diff --git a/Rocksolid_Light/rslight/scripts/spoolnews.php b/Rocksolid_Light/rslight/scripts/spoolnews.php index dd055f3..2710250 100644 --- a/Rocksolid_Light/rslight/scripts/spoolnews.php +++ b/Rocksolid_Light/rslight/scripts/spoolnews.php @@ -24,6 +24,10 @@ include "config.inc.php"; include ("$file_newsportal"); include $config_dir . '/gpg.conf'; +set_error_handler(function (int $number, string $message) { + echo "Handler captured error $number: '$message'" . PHP_EOL; +}); + if ($CONFIG['remote_server'] != '') { $remote_groupfile = $spooldir . "/" . $config_name . "/" . $CONFIG['remote_server'] . ":" . $CONFIG['remote_port'] . ".txt"; } @@ -139,21 +143,28 @@ if ($CONFIG['remote_server'] != '') { get_articles($ns, $name[0]); if ($enable_rslight == 1) { - if (filemtime($spooldir . '/' . $name[0] . '-thread-timer') + 600 < time()) { + $timer_file = $spooldir . '/tmp/' . $name[0] . '-thread-timer'; + if (filemtime($timer_file) + 600 < time()) { + touch($timer_file); if (! $ns2) { $ns2 = nntp_open(); + echo "\nOPENING $ns2: " . $ns2 . "\n"; } if (! $ns2) { file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Failed to connect to " . $CONFIG['remote_server'] . ":" . $CONFIG['remote_port'], FILE_APPEND); // exit(); } else { file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Updating threads for: " . $name[0] . "...", FILE_APPEND); - thread_load_newsserver($ns2, $name[0], 0); + try { + thread_load_newsserver($ns2, $name[0], 0); + } catch (Exception $exc) { + echo "\nFatal exception caught: " . $exc->getMessage(); + } catch (Error $err) { + echo "\nFatal error caught: " . $err->getMessage(); + } file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Threads updated for: " . $name[0], FILE_APPEND); - // nntp_close($ns2); } - touch($spooldir . '/' . $name[0] . '-thread-timer'); - } + } } } if ($ns2) { @@ -240,7 +251,9 @@ function get_articles($ns, $group) } # Pull articles and save them in our spool - @mkdir($grouppath, 0755, 'recursive'); + if (! is_dir($grouppath)) { + mkdir($grouppath, 0755, 'recursive'); + } $i = 0; // GET INDIVIDUAL ARTICLE while ($article <= $detail[3]) {