From ede7591702e0237ce476ae9ecce1424662ee840c Mon Sep 17 00:00:00 2001 From: Zankaria Date: Thu, 11 Jul 2024 22:48:19 +0200 Subject: [PATCH] bans.php: refactor to expose the moratorium on ban deletion from the database. Also fixes the 'purge_bans' configuration for non-cache deployments. --- inc/bans.php | 7 ++++--- inc/config.php | 3 +-- inc/functions.php | 4 ++-- tools/maintenance.php | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/inc/bans.php b/inc/bans.php index 0e462a7b..8566eb04 100644 --- a/inc/bans.php +++ b/inc/bans.php @@ -341,12 +341,13 @@ class Bans { rebuildThemes('bans'); } - static public function purge($require_seen) { + static public function purge($require_seen, $moratorium) { if ($require_seen) { - $query = prepare("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` < :curr_time AND `seen` = 1"); + $query = prepare("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` + :moratorium < :curr_time AND `seen` = 1"); } else { - $query = prepare("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` < :curr_time"); + $query = prepare("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` + :moratorium < :curr_time"); } + $query->bindValue(':moratorium', $moratorium); $query->bindValue(':curr_time', time()); $query->execute() or error(db_error($query)); diff --git a/inc/config.php b/inc/config.php index 880de88b..7828be88 100644 --- a/inc/config.php +++ b/inc/config.php @@ -1569,8 +1569,7 @@ // Enable the moving of single replies $config['move_replies'] = false; - // How often (minimum) to purge the ban list of expired bans (which have been seen). Only works when - // $config['cache'] is enabled and working. + // How often (minimum) to purge the ban list of expired bans (which have been seen). $config['purge_bans'] = 60 * 60 * 12; // 12 hours // Do DNS lookups on IP addresses to get their hostname for the moderator IP pages (?/IP/x.x.x.x). diff --git a/inc/functions.php b/inc/functions.php index 386f7b38..2cb97c50 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -908,12 +908,12 @@ function checkBan($board = false) { if ($config['cache']['enabled']) { $last_time_purged = cache::get('purged_bans_last'); if ($last_time_purged !== false && time() - $last_time_purged > $config['purge_bans']) { - Bans::purge($config['require_ban_view']); + Bans::purge($config['require_ban_view'], $config['purge_bans']); cache::set('purged_bans_last', time()); } } else { // Purge every time. - Bans::purge($config['require_ban_view']); + Bans::purge($config['require_ban_view'], $config['purge_bans']); } } } diff --git a/tools/maintenance.php b/tools/maintenance.php index cdc1089d..3db3ea98 100644 --- a/tools/maintenance.php +++ b/tools/maintenance.php @@ -7,7 +7,7 @@ require dirname(__FILE__) . '/inc/cli.php'; echo "Clearing expired bans..."; $start = microtime(true); -$deleted_count = Bans::purge($config['require_ban_view']); +$deleted_count = Bans::purge($config['require_ban_view'], $config['purge_bans']); $delta = microtime(true) - $start; echo "Deleted $deleted_count expired bans in $delta seconds!"; modLog("Deleted expired bans in {$delta}s with tools/maintenance.php");