Add per group expire settings and use db for expire
This commit is contained in:
parent
0e6fdb9b1c
commit
d2d4588e13
|
@ -1215,4 +1215,25 @@ function rslight_db_open($database, $table) {
|
||||||
subject TEXT)");
|
subject TEXT)");
|
||||||
return($dbh);
|
return($dbh);
|
||||||
}
|
}
|
||||||
|
function get_config_value($configfile,$request) {
|
||||||
|
global $config_dir;
|
||||||
|
|
||||||
|
if ($configFileHandle = @fopen($config_dir.'/'.$configfile, 'r'))
|
||||||
|
{
|
||||||
|
while (!feof($configFileHandle))
|
||||||
|
{
|
||||||
|
$buffer = fgets($configFileHandle);
|
||||||
|
if(strpos($buffer, $request.':') !== FALSE) {
|
||||||
|
$dataline=$buffer;
|
||||||
|
fclose($configFileHandle);
|
||||||
|
$datafound = explode(':',$dataline);
|
||||||
|
return $datafound[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($configFileHandle);
|
||||||
|
return FALSE;
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -3,10 +3,6 @@
|
||||||
include "config.inc.php";
|
include "config.inc.php";
|
||||||
include ("$file_newsportal");
|
include ("$file_newsportal");
|
||||||
|
|
||||||
if(!isset($CONFIG['expire_days']) || $CONFIG['expire_days'] < 1) {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$lockfile = sys_get_temp_dir() . '/'.$config_name.'-spoolnews.lock';
|
$lockfile = sys_get_temp_dir() . '/'.$config_name.'-spoolnews.lock';
|
||||||
$pid = file_get_contents($lockfile);
|
$pid = file_get_contents($lockfile);
|
||||||
if (posix_getsid($pid) === false || !is_file($lockfile)) {
|
if (posix_getsid($pid) === false || !is_file($lockfile)) {
|
||||||
|
@ -20,13 +16,29 @@
|
||||||
$webserver_group=$CONFIG['webserver_user'];
|
$webserver_group=$CONFIG['webserver_user'];
|
||||||
$logfile=$logdir.'/expire.log';
|
$logfile=$logdir.'/expire.log';
|
||||||
|
|
||||||
$expireme=time() - ($CONFIG['expire_days'] * 86400);
|
$database = $spooldir.'/'.$config_name.'-overview.db3';
|
||||||
|
$table = 'overview';
|
||||||
|
$dbh = rslight_db_open($database, $table);
|
||||||
|
$query = $dbh->prepare('DELETE FROM '.$table.' WHERE newsgroup=:newsgroup AND number=:number');
|
||||||
|
|
||||||
$grouplist = file($config_dir.'/'.$config_name.'/groups.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
$grouplist = file($config_dir.'/'.$config_name.'/groups.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
foreach($grouplist as $groupline) {
|
foreach($grouplist as $groupline) {
|
||||||
|
$expireme = 0;
|
||||||
|
if($CONFIG['expire_days'] > 0) {
|
||||||
|
$expireme=time() - ($CONFIG['expire_days'] * 86400);
|
||||||
|
}
|
||||||
$groupname=explode(' ', $groupline);
|
$groupname=explode(' ', $groupline);
|
||||||
$group=$groupname[0];
|
$group=$groupname[0];
|
||||||
|
if($days = get_config_value('expire.conf', $group)) {
|
||||||
|
if($days > 0) {
|
||||||
|
$expireme = time() - ($days * 86400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($expireme < 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$grouppath = preg_replace('/\./', '/', $group);
|
$grouppath = preg_replace('/\./', '/', $group);
|
||||||
|
|
||||||
$this_overview=$spooldir.'/'.$group.'-overview';
|
$this_overview=$spooldir.'/'.$group.'-overview';
|
||||||
$out_overview=$this_overview.'.new';
|
$out_overview=$this_overview.'.new';
|
||||||
|
|
||||||
|
@ -39,6 +51,7 @@
|
||||||
echo "Expiring: ".$break[4]." IN: ".$group." #".$break[0]."\r\n";
|
echo "Expiring: ".$break[4]." IN: ".$group." #".$break[0]."\r\n";
|
||||||
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Expiring: ".$break[4]." IN: ".$group." #".$break[0], FILE_APPEND);
|
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Expiring: ".$break[4]." IN: ".$group." #".$break[0], FILE_APPEND);
|
||||||
unlink($spooldir.'/articles/'.$grouppath.'/'.$break[0]);
|
unlink($spooldir.'/articles/'.$grouppath.'/'.$break[0]);
|
||||||
|
$query->execute([':newsgroup' => $group, ':number' => $break[0]]);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
fputs($out_overviewfp, $line);
|
fputs($out_overviewfp, $line);
|
||||||
|
@ -50,26 +63,6 @@
|
||||||
chown($this_overview, $CONFIG['webserver_user']);
|
chown($this_overview, $CONFIG['webserver_user']);
|
||||||
chgrp($this_overview, $webserver_group);
|
chgrp($this_overview, $webserver_group);
|
||||||
}
|
}
|
||||||
// Remove from section overview
|
$dbh = null;
|
||||||
$this_overview=$spooldir.'/'.$config_name.'-overview';
|
|
||||||
$out_overview=$this_overview.'.new';
|
|
||||||
$overviewfp=fopen($this_overview, 'r');
|
|
||||||
$out_overviewfp=fopen($out_overview, 'w');
|
|
||||||
|
|
||||||
while($line=fgets($overviewfp)) {
|
|
||||||
$break=preg_split("/(:#rsl#:|\t)/", $line, 6);
|
|
||||||
// $break=explode("\t", $line);
|
|
||||||
if($break[3] < $expireme) {
|
|
||||||
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Removing from overview: ".$break[2], FILE_APPEND);
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
fputs($out_overviewfp, $line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose($overviewfp);
|
|
||||||
fclose($out_overviewfp);
|
|
||||||
rename($out_overview, $this_overview);
|
|
||||||
chown($this_overview, $CONFIG['webserver_user']);
|
|
||||||
chgrp($this_overview, $webserver_group);
|
|
||||||
unlink($lockfile);
|
unlink($lockfile);
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue