From cbaf19cb7a4294a2c983b5407080dcd2a9845aca Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sun, 30 Jun 2024 17:01:53 +0200 Subject: [PATCH] bans.php: make the purge configurable --- inc/bans.php | 17 ++++++++++++++--- inc/functions.php | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/inc/bans.php b/inc/bans.php index ee0d086d..a8f9118d 100644 --- a/inc/bans.php +++ b/inc/bans.php @@ -342,9 +342,20 @@ class Bans { rebuildThemes('bans'); } - static public function purge() { - $query = query("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` < " . time() . " AND `seen` = 1") or error(db_error()); - rebuildThemes('bans'); + static public function purge($require_seen) { + if ($require_seen) { + $query = prepare("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` < :curr_time AND `seen` = 1"); + } else { + $query = prepare("DELETE FROM ``bans`` WHERE `expires` IS NOT NULL AND `expires` < :curr_time"); + } + $query->bindValue(':curr_time', time()); + $query->execute() or error(db_error($query)); + + $affected = $query->rowCount(); + if ($affected > 0) { + rebuildThemes('bans'); + } + return $affected; } static public function delete($ban_id, $modlog = false, $boards = false, $dont_rebuild = false) { diff --git a/inc/functions.php b/inc/functions.php index 31e5dfac..369242cb 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -907,7 +907,7 @@ function checkBan($board = false) { return; } - Bans::purge(); + Bans::purge($config['require_ban_view']); if ($config['cache']['enabled']) cache::set('purged_bans_last', time());