2021-02-17 07:56:55 +01:00
|
|
|
<?php
|
|
|
|
/* This script allows importing a group .db3 file from a backup
|
|
|
|
* or another rslight site.
|
|
|
|
*
|
|
|
|
* Place the article database file group.name-articles.db3 in
|
|
|
|
* your spool directory, and change user/group to your web user.
|
|
|
|
* Run this script as your web user from your $webdir/spoolnews dir:
|
|
|
|
* php $config_dir/scripts/import.php group.name
|
|
|
|
*
|
2021-03-15 10:56:01 +01:00
|
|
|
* To import/upgrade all group.db3 files, do not list group.name
|
|
|
|
* after the above command.
|
|
|
|
*
|
2021-02-17 07:56:55 +01:00
|
|
|
* This will create the overview files necessary to import the group
|
|
|
|
* into your site.
|
|
|
|
* Next: Add the group to the groups.txt file of the section you wish
|
|
|
|
* it to appear:
|
|
|
|
* $config_dir/<section>/groups.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
include "config.inc.php";
|
|
|
|
include ("$file_newsportal");
|
|
|
|
|
|
|
|
$logfile=$logdir.'/import.log';
|
|
|
|
|
|
|
|
# END MAIN CONFIGURATION
|
|
|
|
|
|
|
|
$workpath=$spooldir."/";
|
|
|
|
$path=$workpath."articles/";
|
|
|
|
|
2021-07-03 04:08:34 +02:00
|
|
|
$lockfile = $lockdir . '/'.$config_name.'-spoolnews.lock';
|
2021-02-17 07:56:55 +01:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2021-02-19 08:16:40 +01:00
|
|
|
$group = trim($argv[1]);
|
2021-03-11 07:55:01 +01:00
|
|
|
if($group == '') {
|
|
|
|
$group_files = scandir($workpath);
|
|
|
|
foreach($group_files as $this_file) {
|
|
|
|
if(strpos($this_file, '-articles.db3') === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$group = preg_replace('/-articles.db3/', '', $this_file);
|
|
|
|
echo 'Importing: '.$group."\n";
|
|
|
|
import_articles($group);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
import_articles($group);
|
|
|
|
}
|
2021-02-21 00:55:48 +01:00
|
|
|
echo "\nImport Done\r\n";
|
2021-02-17 07:56:55 +01:00
|
|
|
|
|
|
|
function import_articles($group) {
|
|
|
|
global $spooldir, $CONFIG, $workpath, $path, $config_name, $logfile;
|
2021-02-19 08:16:40 +01:00
|
|
|
$overview_file = $workpath.'/'.$group."-overview";
|
2021-02-17 07:56:55 +01:00
|
|
|
# Prepare databases
|
|
|
|
// Overview db
|
2021-03-11 07:55:01 +01:00
|
|
|
$new_article_dbh = article_db_open($spooldir.'/'.$group.'-articles.db3-new');
|
|
|
|
$new_article_sql = 'INSERT INTO articles(newsgroup, number, msgid, date, name, subject, article, search_snippet) VALUES(?,?,?,?,?,?,?,?)';
|
|
|
|
$new_article_stmt = $new_article_dbh->prepare($new_article_sql);
|
2021-02-17 07:56:55 +01:00
|
|
|
$database = $spooldir.'/articles-overview.db3';
|
|
|
|
$table = 'overview';
|
|
|
|
$dbh = rslight_db_open($database, $table);
|
2021-02-21 00:55:48 +01:00
|
|
|
$clear_stmt = $dbh->prepare("DELETE FROM overview WHERE newsgroup=:group");
|
|
|
|
$clear_stmt->bindParam(':group', $group);
|
|
|
|
$clear_stmt->execute();
|
|
|
|
unlink($overview_file);
|
|
|
|
|
2021-02-17 07:56:55 +01:00
|
|
|
$sql = 'INSERT INTO '.$table.'(newsgroup, number, msgid, date, name, subject) VALUES(?,?,?,?,?,?)';
|
|
|
|
$stmt = $dbh->prepare($sql);
|
|
|
|
// Incoming db
|
|
|
|
$article_dbh = article_db_open($spooldir.'/'.$group.'-articles.db3');
|
2021-02-21 00:55:48 +01:00
|
|
|
$article_stmt = $article_dbh->query('SELECT DISTINCT * FROM articles');
|
2021-02-17 07:56:55 +01:00
|
|
|
while ($row = $article_stmt->fetch()) {
|
|
|
|
$local = $row['number'];
|
|
|
|
$this_article = preg_split("/\r\n|\n|\r/", $row['article']);
|
|
|
|
$lines=0;
|
|
|
|
$bytes=0;
|
|
|
|
$ref=0;
|
|
|
|
$banned=0;
|
|
|
|
$is_header=1;
|
2021-03-11 07:55:01 +01:00
|
|
|
$body="";
|
2021-02-17 07:56:55 +01:00
|
|
|
foreach($this_article as $response)
|
|
|
|
{
|
|
|
|
$bytes = $bytes + mb_strlen($response, '8bit');
|
|
|
|
if(trim($response) == "" || $lines > 0) {
|
|
|
|
$is_header=0;
|
|
|
|
$lines++;
|
|
|
|
}
|
|
|
|
if($is_header == 1) {
|
|
|
|
$response = str_replace("\t", " ", $response);
|
|
|
|
// Find article date
|
|
|
|
if(stripos($response, "Date: ") === 0) {
|
|
|
|
$finddate=explode(': ', $response, 2);
|
|
|
|
$ref=0;
|
|
|
|
}
|
|
|
|
// Get overview data
|
|
|
|
$mid[1] = $row['msgid'];
|
|
|
|
$from[1] = $row['name'];
|
|
|
|
$subject[1] = $row['subject'];
|
2021-02-21 00:55:48 +01:00
|
|
|
$article_date = $row['date'];
|
2021-02-17 07:56:55 +01:00
|
|
|
|
|
|
|
if(stripos($response, "Xref: ") === 0) {
|
|
|
|
if(isset($CONFIG['enable_nntp']) && $CONFIG['enable_nntp'] == true) {
|
|
|
|
$response="Xref: ".$CONFIG['pathhost']." ".$group.":".$local;
|
|
|
|
}
|
|
|
|
$xref=$response;
|
|
|
|
$ref=0;
|
|
|
|
}
|
2021-03-11 07:55:01 +01:00
|
|
|
if(stripos($response, "Content-Type: ") === 0) {
|
|
|
|
preg_match('/.*charset=.*/', $response, $te);
|
|
|
|
$content_type = explode("Content-Type: text/plain; charset=", $te[0]);
|
|
|
|
}
|
2021-02-17 07:56:55 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$response=str_replace("\n","",str_replace("\r","",$response));
|
2021-03-11 07:55:01 +01:00
|
|
|
} else {
|
|
|
|
$body.=$response."\n";
|
2021-02-17 07:56:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$lines=$lines-1;
|
|
|
|
$bytes = $bytes + ($lines * 2);
|
|
|
|
// add to database
|
2021-03-11 07:55:01 +01:00
|
|
|
// CREATE SEARCH SNIPPET
|
|
|
|
$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]);
|
|
|
|
|
2021-02-21 00:55:48 +01:00
|
|
|
$stmt->execute([$group, $local, $mid[1], $article_date, $from[1], $subject[1]]);
|
2021-02-19 08:16:40 +01:00
|
|
|
file_put_contents($overview_file, $local."\t".$subject[1]."\t".$from[1]."\t".$finddate[1]."\t".$mid[1]."\t".$references."\t".$bytes."\t".$lines."\t".$xref."\n", FILE_APPEND);
|
2021-02-17 07:56:55 +01:00
|
|
|
echo "\nImported: ".$group." ".$local;
|
|
|
|
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Imported: ".$group.":".$local, FILE_APPEND);
|
|
|
|
$i++;
|
2021-02-19 08:16:40 +01:00
|
|
|
$references="";
|
2021-02-17 07:56:55 +01:00
|
|
|
}
|
2021-03-11 07:55:01 +01:00
|
|
|
$new_article_dbh = null;
|
2021-02-17 07:56:55 +01:00
|
|
|
$article_dbh = null;
|
|
|
|
$dbh = null;
|
2021-03-12 03:06:34 +01:00
|
|
|
unlink($spooldir.'/'.$group.'-articles.db3');
|
2021-03-11 07:55:01 +01:00
|
|
|
rename($spooldir.'/'.$group.'-articles.db3-new', $spooldir.'/'.$group.'-articles.db3');
|
2021-04-09 04:22:49 +02:00
|
|
|
unlink($spooldir.'/'.$group.'-data.dat');
|
|
|
|
unlink($spooldir.'/'.$group.'-info.txt');
|
2021-02-17 07:56:55 +01:00
|
|
|
}
|
|
|
|
?>
|