mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-28 09:20:58 +01:00
bans.php: refactor to expose the moratorium on ban deletion from the database.
Also fixes the 'purge_bans' configuration for non-cache deployments.
This commit is contained in:
parent
c057c6df29
commit
ede7591702
@ -341,12 +341,13 @@ class Bans {
|
|||||||
rebuildThemes('bans');
|
rebuildThemes('bans');
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function purge($require_seen) {
|
static public function purge($require_seen, $moratorium) {
|
||||||
if ($require_seen) {
|
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 {
|
} 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->bindValue(':curr_time', time());
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
|
@ -1569,8 +1569,7 @@
|
|||||||
// Enable the moving of single replies
|
// Enable the moving of single replies
|
||||||
$config['move_replies'] = false;
|
$config['move_replies'] = false;
|
||||||
|
|
||||||
// How often (minimum) to purge the ban list of expired bans (which have been seen). Only works when
|
// How often (minimum) to purge the ban list of expired bans (which have been seen).
|
||||||
// $config['cache'] is enabled and working.
|
|
||||||
$config['purge_bans'] = 60 * 60 * 12; // 12 hours
|
$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).
|
// Do DNS lookups on IP addresses to get their hostname for the moderator IP pages (?/IP/x.x.x.x).
|
||||||
|
@ -908,12 +908,12 @@ function checkBan($board = false) {
|
|||||||
if ($config['cache']['enabled']) {
|
if ($config['cache']['enabled']) {
|
||||||
$last_time_purged = cache::get('purged_bans_last');
|
$last_time_purged = cache::get('purged_bans_last');
|
||||||
if ($last_time_purged !== false && time() - $last_time_purged > $config['purge_bans']) {
|
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());
|
cache::set('purged_bans_last', time());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Purge every time.
|
// Purge every time.
|
||||||
Bans::purge($config['require_ban_view']);
|
Bans::purge($config['require_ban_view'], $config['purge_bans']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ require dirname(__FILE__) . '/inc/cli.php';
|
|||||||
|
|
||||||
echo "Clearing expired bans...";
|
echo "Clearing expired bans...";
|
||||||
$start = microtime(true);
|
$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;
|
$delta = microtime(true) - $start;
|
||||||
echo "Deleted $deleted_count expired bans in $delta seconds!";
|
echo "Deleted $deleted_count expired bans in $delta seconds!";
|
||||||
modLog("Deleted expired bans in {$delta}s with tools/maintenance.php");
|
modLog("Deleted expired bans in {$delta}s with tools/maintenance.php");
|
||||||
|
Loading…
Reference in New Issue
Block a user