Add cache handling to maintenance.php and eclipse keeps changing formatting in newsportal.php.

This commit is contained in:
Retro_Guy 2024-06-11 03:22:21 -07:00
parent 68f94d4f6e
commit 7390e2a9bc
2 changed files with 67 additions and 52 deletions

View File

@ -2932,6 +2932,7 @@ function delete_message_from_overboard($config_name, $group, $messageid)
$cachefile = $spooldir . "/" . $config_name . "-overboard.dat"; $cachefile = $spooldir . "/" . $config_name . "-overboard.dat";
if (is_file($cachefile)) { if (is_file($cachefile)) {
$cached_overboard = unserialize(file_get_contents($cachefile)); $cached_overboard = unserialize(file_get_contents($cachefile));
if (isset($cached_overboard['msgids'][$messageid])) {
if ($target = $cached_overboard['msgids'][$messageid]) { if ($target = $cached_overboard['msgids'][$messageid]) {
unset($cached_overboard['threads'][$target['date']]); unset($cached_overboard['threads'][$target['date']]);
unset($cached_overboard['msgids'][$messageid]); unset($cached_overboard['msgids'][$messageid]);
@ -2939,9 +2940,11 @@ function delete_message_from_overboard($config_name, $group, $messageid)
file_put_contents($cachefile, serialize($cached_overboard)); file_put_contents($cachefile, serialize($cached_overboard));
} }
} }
}
$cachefile = $spooldir . "/" . $group . "-overboard.dat"; $cachefile = $spooldir . "/" . $group . "-overboard.dat";
if (is_file($cachefile)) { if (is_file($cachefile)) {
$cached_overboard = unserialize(file_get_contents($cachefile)); $cached_overboard = unserialize(file_get_contents($cachefile));
if (isset($cached_overboard['msgids'][$messageid])) {
if ($target = $cached_overboard['msgids'][$messageid]) { if ($target = $cached_overboard['msgids'][$messageid]) {
unset($cached_overboard['threads'][$target['date']]); unset($cached_overboard['threads'][$target['date']]);
unset($cached_overboard['msgids'][$messageid]); unset($cached_overboard['msgids'][$messageid]);
@ -2950,9 +2953,11 @@ function delete_message_from_overboard($config_name, $group, $messageid)
} }
} }
} }
}
function cache_add($cache_key, $data, $cache_ttl, $memcacheD = null) { function cache_add($cache_key, $data, $cache_ttl, $memcacheD = null)
global $enable_cache, $cache_dir, $cache_log; {
global $enable_cache, $cache_dir, $cache_log, $low_spool_disk_space;
$cache_key = base64_encode($cache_key); $cache_key = base64_encode($cache_key);
if ($enable_cache == 'memcached') { if ($enable_cache == 'memcached') {
if ($memcacheD) { if ($memcacheD) {
@ -2973,7 +2978,8 @@ function cache_add($cache_key, $data, $cache_ttl, $memcacheD = null) {
return false; return false;
} }
function cache_delete($cache_key, $memcacheD = null) { function cache_delete($cache_key, $memcacheD = null)
{
global $enable_cache, $cache_dir; global $enable_cache, $cache_dir;
$cache_key = base64_encode($cache_key); $cache_key = base64_encode($cache_key);
if ($enable_cache == 'memcached') { if ($enable_cache == 'memcached') {
@ -2991,7 +2997,8 @@ function cache_delete($cache_key, $memcacheD = null) {
return false; return false;
} }
function cache_get($cache_key, $memcacheD = null) { function cache_get($cache_key, $memcacheD = null)
{
global $enable_cache, $cache_dir; global $enable_cache, $cache_dir;
$cache_key = base64_encode($cache_key); $cache_key = base64_encode($cache_key);
if ($enable_cache == 'memcached') { if ($enable_cache == 'memcached') {

View File

@ -67,6 +67,9 @@ if ($argv[1][0] == '-') {
default: default:
echo "-help: This help page\n"; echo "-help: This help page\n";
echo "-version: Display version\n"; echo "-version: Display version\n";
echo "******************* IMPORTANT **************************\n";
echo "*** PLEASE DISABLE cron.php WHEN RUNNING THIS SCRIPT ***\n";
echo "********************************************************\n";
echo "-clean: Remove extraneous group db3 files\n"; echo "-clean: Remove extraneous group db3 files\n";
echo "-import: Import articles from a .db3 file (-import alt.test-articles)\n"; echo "-import: Import articles from a .db3 file (-import alt.test-articles)\n";
echo " You must first add group name to <config_dir>/<section>/groups.txt manually\n"; echo " You must first add group name to <config_dir>/<section>/groups.txt manually\n";
@ -172,7 +175,8 @@ function reset_group($group, $remove = 0)
$config_location = $spooldir . '/' . $section; $config_location = $spooldir . '/' . $section;
$config_files = array_diff(scandir($config_location), array( $config_files = array_diff(scandir($config_location), array(
'..', '..',
'.' '.',
'outgoing'
)); ));
foreach ($config_files as $config_file) { foreach ($config_files as $config_file) {
@ -200,18 +204,22 @@ function remove_articles($group)
$group = trim($group); $group = trim($group);
# Overview # Overview
$dbh = overview_db_open($spooldir . '/articles-overview.db3'); $overview_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();
$dbh = null;
# History $fetch_stmt = $overview_dbh->prepare("SELECT msgid FROM overview WHERE newsgroup=:group");
$dbh = history_db_open($spooldir . '/history.db3'); $fetch_stmt->bindParam(':group', $group);
$clear_stmt = $dbh->prepare("DELETE FROM history WHERE newsgroup=:group"); $fetch_stmt->execute();
$clear_stmt->bindParam(':group', $group); $del_array = array();
$clear_stmt->execute(); while ($row = $fetch_stmt->fetch()) {
$dbh = null; if (isset($row['msgid'])) {
$del_array[] = $row['msgid'];
}
}
$overview_dbh = null;
foreach($del_array as $delme) {
delete_message($delme, $group);
echo "Deleting " . $delme . " from " . $group . "\n";
}
rename($spooldir . '/' . $group . '-articles.db3', $spooldir . '/' . $group . '-articles.db3-removed'); rename($spooldir . '/' . $group . '-articles.db3', $spooldir . '/' . $group . '-articles.db3-removed');
unlink($spooldir . '/' . $group . '-data.db3'); unlink($spooldir . '/' . $group . '-data.db3');