From d0b1c388ebefb2d6b4b4d8e54cb836074aa42c20 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 48fd1eab..39e3ad52 100644 --- a/inc/bans.php +++ b/inc/bans.php @@ -349,9 +349,20 @@ class Bans { rebuildThemes('bans'); } - static public function purge() { - 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 436b6b2d..06044551 100644 --- 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());