Rename rslight_db_open to overview_db_open as it makes more sense.

This commit is contained in:
Retro_Guy 2023-08-13 10:00:48 -07:00
parent 4f34941398
commit ff0e31daca
13 changed files with 34 additions and 188 deletions

View File

@ -36,7 +36,7 @@
if(strpos($id, '@') !== false) {
if($CONFIG['article_database'] == '1') {
$database = $spooldir.'/articles-overview.db3';
$articles_dbh = rslight_db_open($database);
$articles_dbh = overview_db_open($database);
$articles_query = $articles_dbh->prepare('SELECT * FROM overview WHERE msgid=:messageid');
$articles_query->execute(['messageid' => $id]);
$found = 0;

View File

@ -836,7 +836,7 @@ function thread_format_lastmessage($c,$group='') {
// Tradspool
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$dbh = overview_db_open($database, $table);
$stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:newsgroup AND date=:date ORDER BY date DESC");
$stmt->bindParam(':newsgroup', $group);
$stmt->bindParam(':date', $c->date_thread);

View File

@ -672,7 +672,7 @@ function groups_show($gruppen) {
// Look up last article info for group
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$articles_dbh = rslight_db_open($database);
$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;
@ -1449,7 +1449,7 @@ function mail_db_open($database, $table='messages') {
return($dbh);
}
function rslight_db_open($database, $table='overview') {
function overview_db_open($database, $table='overview') {
try {
$dbh = new PDO('sqlite:'.$database);
} catch (PDOException $e) {
@ -1694,7 +1694,7 @@ function get_db_data_from_msgid($msgid, $group) {
if(!is_file($database)) {
return false;
}
$articles_dbh = rslight_db_open($database);
$articles_dbh = article_db_open($database);
$articles_query = $articles_dbh->prepare('SELECT * FROM articles WHERE msgid=:messageid');
$articles_query->execute(['messageid' => $msgid]);
$found = 0;
@ -1713,7 +1713,7 @@ function get_db_data_from_msgid($msgid, $group) {
function get_data_from_msgid($msgid) {
global $spooldir;
$database = $spooldir.'/articles-overview.db3';
$articles_dbh = rslight_db_open($database);
$articles_dbh = overview_db_open($database);
$articles_query = $articles_dbh->prepare('SELECT * FROM overview WHERE msgid=:messageid');
$articles_query->execute(['messageid' => $msgid]);
$found = 0;

View File

@ -141,7 +141,7 @@ if($this_overboard['version'] !== $version) {
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$dbh = overview_db_open($database, $table);
$query = $dbh->prepare('SELECT * FROM '.$table.' WHERE newsgroup=:findgroup AND date >= '.$cachedate.' ORDER BY date DESC LIMIT '.$maxdisplay);
$articles = array();
$db_articles = array();

View File

@ -324,7 +324,7 @@ function get_header_search($group, $terms) {
# Prepare search database
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$dbh = overview_db_open($database, $table);
$overview = array();
foreach($grouplist as $thisgroup) {

View File

@ -12,7 +12,7 @@ count_users();
function count_articles() {
GLOBAL $CONFIG, $spooldir;
$database = $spooldir.'/articles-overview.db3';
$dbh = rslight_db_open($database);
$dbh = overview_db_open($database);
$count = $dbh->query('SELECT COUNT(DISTINCT msgid) FROM overview')->fetchColumn();
$dbh = null;
return $count;

View File

@ -46,7 +46,7 @@ file_put_contents($logfile, "\n".format_log_date()." ".$config_name." ".$group."
echo "Expiring overview database...\n";
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." ".$group." Expiring overview database...", FILE_APPEND);
$database = $spooldir.'/articles-overview.db3';
$dbh = rslight_db_open($database);
$dbh = overview_db_open($database);
$query = $dbh->prepare('DELETE FROM overview WHERE newsgroup=:newsgroup AND date<:expireme');
$query->execute([':newsgroup' => $group, ':expireme' => $expireme]);
$dbh = null;
@ -63,7 +63,7 @@ file_put_contents($logfile, "\n".format_log_date()." ".$config_name." ".$group."
}
} else { // Expire tradspool
$database = $spooldir.'/articles-overview.db3';
$dbh = rslight_db_open($database);
$dbh = overview_db_open($database);
$query = $dbh->prepare('SELECT FROM overview WHERE newsgroup=:newsgroup AND date<:expireme');
$query->execute([':newsgroup' => $group, ':expireme' => $expireme]);
$grouppath = preg_replace('/\./', '/', $group);

View File

@ -189,7 +189,7 @@ function remove_articles($group) {
global $spooldir, $CONFIG, $workpath, $path, $config_name, $logfile;
$group = trim($group);
# Prepare databases
$dbh = rslight_db_open($spooldir.'/articles-overview.db3');
$dbh = overview_db_open($spooldir.'/articles-overview.db3');
$clear_stmt = $dbh->prepare("DELETE FROM overview WHERE newsgroup=:group");
$clear_stmt->bindParam(':group', $group);
$clear_stmt->execute();
@ -210,7 +210,7 @@ function import_articles($group) {
$new_article_stmt = $new_article_dbh->prepare($new_article_sql);
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$dbh = overview_db_open($database, $table);
$clear_stmt = $dbh->prepare("DELETE FROM overview WHERE newsgroup=:group");
$clear_stmt->bindParam(':group', $group);
$clear_stmt->execute();

View File

@ -1,156 +0,0 @@
<?php
/* This script allows importing a group .db3 file from a backup
* or another rslight site, and other features.
*
* Use -help to see features.
*/
include "config.inc.php";
include ("$file_newsportal");
$logfile=$logdir.'/import.log';
$lockfile = $lockdir . '/'.$config_name.'-spoolnews.lock';
$pid = file_get_contents($lockfile);
if (posix_getsid($pid) === false || !is_file($lockfile)) {
print "Starting Import...\n";
file_put_contents($lockfile, getmypid()); // create lockfile
} else {
print "Import currently running\n";
exit;
}
if(!isset($argv[1])) {
$argv[1] = "-help";
}
if($argv[1][0] == '-') {
switch ($argv[1]) {
case "-version":
echo 'Version '.$rslight_version."\n";
break;
case "-import":
if(isset($argv[2])) {
import($argv[2]);
} else {
echo "No group selected\n";
break;
}
break;
default:
echo "-help: This help page\n";
echo "-version: Display version\n";
echo "-import: Import articles manually entered into tradspool\n";
echo " (-import alt.test)\n";
echo " You must first add group name to <config_dir>/<section>/groups.txt manually\n";
break;
}
exit();
} else {
exit();
}
function import($group) {
global $logfile, $workpath, $spooldir;
$workpath=$spooldir."/";
$path=$workpath."articles/";
$group = trim($group);
if($group == '') {
echo "No group selected\n";
return;
} else {
$grouppath = preg_replace("/\./", "/", $group);
$grouparticles = scandir($spooldir.'/articles/'.$grouppath);
echo "Importing: ".$group."\n";
import_articles($group, $grouppath, $grouparticles);
}
echo "\nImport Done\r\n";
return;
}
function import_articles($group, $grouppath, $grouparticles) {
global $spooldir, $CONFIG, $workpath, $path, $config_name, $logfile;
$group_overviewfile = $spooldir."/".$group."-overview";
$gover = file($group_overviewfile);
foreach($gover as $group_overview) {
$overview_msgid = explode("\t", $group_overview);
$msgids[trim($overview_msgid[4])] = true;
}
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$sql = 'INSERT INTO '.$table.'(newsgroup, number, msgid, date, name, subject) VALUES(?,?,?,?,?,?)';
$stmt = $dbh->prepare($sql);
foreach($grouparticles as $article) {
if($article == '.' || $article == '..') {
continue;
}
$this_article = $spooldir.'articles/'.$grouppath.'/'.$article;
$article_content = file($this_article);
$lines=0;
$bytes=0;
$ref=0;
$is_header=1;
$body="";
$skip=0;
unset($mid);
foreach($article_content as $response) {
$bytes = $bytes + mb_strlen($response, '8bit');
if(trim($response) == "") {
$is_header=0;
$lines++;
}
if($is_header == 1) {
$response = str_replace("\t", " ", $response);
if(stripos($response, "Message-ID: ") === 0) {
$mid=explode(': ', $response, 2);
$ref=0;
}
if($msgids[trim($mid[1])] == true) {
echo "Duplicate Message-ID for ".$group.":".$article."\n";
$skip=1;
break;
}
if(stripos($response, "From: ") === 0) {
$from=explode(': ', $response, 2);
}
if(stripos($response, "Date: ") === 0) {
$finddate=explode(': ', $response, 2);
$article_date = strtotime($finddate[1]);
}
if(stripos($response, "Subject: ") === 0) {
$subject=explode('Subject: ', $response, 2);
$ref=0;
}
if(stripos($response, "Xref: ") === 0) {
if(isset($CONFIG['enable_nntp']) && $CONFIG['enable_nntp'] == true) {
$response="Xref: ".$CONFIG['pathhost']." ".$group.":".$article;
}
$xref=$response;
$ref=0;
}
if(stripos($response, "References: ") === 0) {
$this_references=explode('References: ', $response);
$references = $this_references[1];
$ref=1;
}
if((stripos($response, ':') === false) && (strpos($response, '>'))) {
if($ref == 1) {
$references=$references.$response;
}
}
} else {
$lines++;
}
}
if($skip == 0) {
// Write to overview. Fix $article to proper article number. Check for duplicate.
echo "Adding ".$group.":".$article." to overview\n";
$stmt->execute([$group, $article, trim($mid[1]), $article_date, trim($from[1]), trim($subject[1])]);
file_put_contents($group_overviewfile, $article."\t".trim($subject[1])."\t".trim($from[1])."\t".trim($finddate[1])."\t".trim($mid[1])."\t".trim($references)."\t".$bytes."\t".$lines."\t".$xref."\n", FILE_APPEND);
continue;
}
}
$dbh = null;
}
?>

View File

@ -92,7 +92,7 @@ function delete_message($messageid, $group) {
}
if($config_name) {
$database = $spooldir.'/articles-overview.db3';
$dbh = rslight_db_open($database);
$dbh = overview_db_open($database);
$query = $dbh->prepare('DELETE FROM overview WHERE msgid=:messageid');
$query->execute(['messageid' => $messageid]);
$dbh = null;
@ -111,7 +111,7 @@ function delete_message($messageid, $group) {
// Tradspool
if($CONFIG['article_database'] != '1') {
$database = $spooldir.'/articles-overview.db3';
$dbh = rslight_db_open($database);
$dbh = overview_db_open($database);
$query = $dbh->prepare('SELECT FROM overview WHERE newsgroup=:newsgroup AND msgid<:msgid');
$query->execute([':newsgroup' => $group, ':msgid' => $messageid]);
$grouppath = preg_replace('/\./', '/', $group);

View File

@ -455,7 +455,7 @@ function process_post($message, $group) {
$duplicate=0;
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$dbh = overview_db_open($database, $table);
$stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:thisgroup AND msgid=:msgid ORDER BY number");
$stmt->execute(['thisgroup' => $group, ':msgid' => $msgid]);
while($found = $stmt->fetch()) {
@ -491,7 +491,7 @@ function get_next($nntp_group) {
$nntp_article++;
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$dbh = overview_db_open($database, $table);
$stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:newsgroup AND number=:number");
$stmt->bindParam(':newsgroup', $nntp_group);
$stmt->bindParam(':number', $nntp_article);
@ -521,7 +521,7 @@ function get_last($nntp_group) {
$nntp_article--;
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$dbh = overview_db_open($database, $table);
$stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:newsgroup AND number=:number");
$stmt->bindParam(':newsgroup', $nntp_group);
$stmt->bindParam(':number', $nntp_article);
@ -682,12 +682,14 @@ function get_xover($articles, $msgsock) {
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:thisgroup AND number BETWEEN :first AND :last ORDER BY number");
$stmt->execute(['thisgroup' => $nntp_group, ':first' => $first, ':last' => $last]);
$msg = '';
while($row = $stmt->fetch()) {
$msg.= $row['number']."\t".$row['subject']."\t".$row['name']."\t".$row['datestring']."\t".$row['msgid']."\t".$row['refs']."\t".$row['bytes']."\t".$row['lines']."\t".$row['xref']."\r\n";
$dbh = overview_db_open($database, $table);
$stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:thisgroup AND number=:number"); // Why doesn't BETWEEN work properly here?
for($i=$first; $i<=$last; $i++) {
$stmt->execute(['thisgroup' => $nntp_group, ':number' => $i]);
while($row = $stmt->fetch()) {
$msg.= $row['number']."\t".$row['subject']."\t".$row['name']."\t".$row['datestring']."\t".$row['msgid']."\t".$row['refs']."\t".$row['bytes']."\t".$row['lines']."\t".$row['xref']."\r\n";
}
}
$dbh = null;
$msg.=".\r\n";
@ -713,7 +715,7 @@ function get_stat($article) {
if(!is_file($database)) {
return false;
}
$dbh = rslight_db_open($database);
$dbh = overview_db_open($database);
$query = $articles_dbh->prepare('SELECT * FROM overview WHERE number=:number AND newsgroup=:newsgroup');
$query->execute(['number' => $article, 'newsgroup' => $nntp_group]);
$found = 0;
@ -1139,7 +1141,7 @@ $date_i,$mid_i,$references_i,$bytes_i,$lines_i,$xref_i,$body) {
# Prepare overview database
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$dbh = overview_db_open($database, $table);
if(!$dbh) {
file_put_contents($logfile, "\n".format_log_date()." ".$section." Failed to connect to database: ".$database, FILE_APPEND);
$return_val = "441 Posting failed (overview db error)\r\n";
@ -1206,7 +1208,7 @@ function find_article_by_msgid($msgid) {
global $spooldir;
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$dbh = overview_db_open($database, $table);
$stmt = $dbh->prepare("SELECT * FROM $table WHERE msgid like :terms");
$stmt->bindParam(':terms', $msgid);
$stmt->execute();
@ -1224,7 +1226,7 @@ function get_article_list($thisgroup) {
global $spooldir;
$database = $spooldir."/articles-overview.db3";
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$dbh = overview_db_open($database, $table);
$stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:thisgroup ORDER BY number");
$stmt->execute(['thisgroup' => $thisgroup]);
$ok_article=array();

View File

@ -209,7 +209,7 @@ function get_articles($ns, $group) {
// Create list of message-ids
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$dbh = overview_db_open($database, $table);
$stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:newsgroup");
$stmt->bindParam(':newsgroup', $nntp_group);
$stmt->execute();
@ -222,7 +222,7 @@ function get_articles($ns, $group) {
// Overview database
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$dbh = overview_db_open($database, $table);
$sql = 'INSERT OR IGNORE INTO overview(newsgroup, number, msgid, date, datestring, name, subject, refs, bytes, lines, xref) VALUES(?,?,?,?,?,?,?,?,?,?,?)';
$stmt = $dbh->prepare($sql);
@ -471,7 +471,7 @@ function get_article_list($thisgroup) {
global $spooldir;
$database = $spooldir."/articles-overview.db3";
$table = 'overview';
$dbh = rslight_db_open($database, $table);
$dbh = overview_db_open($database, $table);
$stmt = $dbh->prepare("SELECT * FROM $table WHERE newsgroup=:thisgroup ORDER BY number");
$stmt->execute(['thisgroup' => $thisgroup]);
$ok_article=array();

View File

@ -1 +1 @@
0.8.5
0.9.0