Add checking all groups to properly write Xref for 'import' in maintenance.php.

This commit is contained in:
Retro_Guy 2023-11-15 04:55:08 -07:00
parent a064a028fd
commit c3c0d8b683
2 changed files with 34 additions and 16 deletions

View File

@ -1457,6 +1457,31 @@ function get_date_interval($value)
return $variance;
}
function create_xref_from_msgid($msgid, $thisgroup = null, $thisnumber = null)
{
global $spooldir, $CONFIG;
$database = $spooldir . '/articles-overview.db3';
$table = 'overview';
$overview_dbh = overview_db_open($database, $table);
$overview_stmt = $overview_dbh->prepare("SELECT * FROM overview WHERE msgid=:msgid");
$overview_stmt->bindParam(':msgid', $msgid);
$overview_stmt->execute();
$found = false;
$xref = "Xref: " . $CONFIG['pathhost'];
while ($row = $overview_stmt->fetch()) {
if ($row['newsgroup'] == $thisgroup && $thisgroup != null) {
$found = true;
}
$xref .= ' ' . $row['newsgroup'] . ':' . $row['number'];
}
if (!$found) {
$xref .= ' ' . $thisgroup . ':' . $thisnumber;
}
$overview_dbh = null;
return ($xref);
}
function get_search_snippet($body, $content_type = '')
{
$body = quoted_printable_decode($body);
@ -1909,7 +1934,7 @@ function insert_article_from_array($this_article)
$msgids[$row['msgid']] = true;
}
$dbh = null;
if ($msgids[$this_article['mid']] == true) {
echo "\nDuplicate Message-ID for: " . $group . ":" . $this_article['local'];
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Duplicate Message-ID for: " . $group . ":" . $this_article['local'], FILE_APPEND);
@ -1961,7 +1986,7 @@ function insert_article_from_array($this_article)
} else {
if ($article_date > time())
$article_date = time();
touch($grouppath . "/" . $this_article['local'], $article_date);
touch($grouppath . "/" . $this_article['local'], $article_date);
}
echo "\nRetrieved: " . $group . " " . $this_article['local'];

View File

@ -231,13 +231,13 @@ function import_articles($group)
$new_article_stmt = $new_article_dbh->prepare($new_article_sql);
$database = $spooldir . '/articles-overview.db3';
$table = 'overview';
$dbh = overview_db_open($database, $table);
$clear_stmt = $dbh->prepare("DELETE FROM overview WHERE newsgroup=:group");
$overview_dbh = overview_db_open($database, $table);
$clear_stmt = $overview_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);
$overview_sql = 'INSERT OR IGNORE INTO overview(newsgroup, number, msgid, date, datestring, name, subject, refs, bytes, lines, xref) VALUES(?,?,?,?,?,?,?,?,?,?,?)';
$overview_stmt = $overview_dbh->prepare($overview_sql);
// Incoming db
$article_dbh = article_db_open($spooldir . '/' . $group . '-articles.db3');
@ -269,14 +269,6 @@ function import_articles($group)
$from[1] = $row['name'];
$subject[1] = $row['subject'];
$article_date = $row['date'];
if (stripos($response, "Xref: ") === 0) {
if (isset($CONFIG['enable_nntp']) && $CONFIG['enable_nntp'] == true) {
$response = "Xref: " . $CONFIG['pathhost'] . " " . $group . ":" . $local;
}
$xref = $response;
$ref = 0;
}
if (stripos($response, "Content-Type: ") === 0) {
preg_match('/.*charset=.*/', $response, $te);
$content_type = explode("Content-Type: text/plain; charset=", $te[0]);
@ -301,6 +293,7 @@ function import_articles($group)
// add to database
// CREATE SEARCH SNIPPET
$this_snippet = get_search_snippet($body, $content_type[1]);
$xref = create_xref_from_msgid($msgid, $group, $local);
$new_article_stmt->execute([
$group,
$local,
@ -311,7 +304,7 @@ function import_articles($group)
$row['article'],
$this_snippet
]);
$stmt->execute([
$overview_stmt->execute([
$group,
$local,
$mid[1],
@ -335,7 +328,7 @@ function import_articles($group)
}
$new_article_dbh = null;
$article_dbh = null;
$dbh = null;
$overview_dbh = null;
unlink($spooldir . '/' . $group . '-articles.db3');
rename($spooldir . '/' . $group . '-articles.db3-new', $spooldir . '/' . $group . '-articles.db3');
unlink($spooldir . '/' . $group . '-info.txt');