1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-24 15:40:12 +01:00

bans.php: group deletion policy

This commit is contained in:
Zankaria 2024-07-01 21:52:03 +02:00 committed by Zankaria
parent 2298d4433f
commit 82b8eb1e74

View File

@ -4,6 +4,10 @@ use Vichan\Functions\Format;
use Lifo\IP\CIDR; use Lifo\IP\CIDR;
class Bans { class Bans {
static private function shouldDelete(array $ban, bool $require_ban_view) {
return $ban['expires'] && ($ban['seen'] || !$require_ban_view) && $ban['expires'] < time();
}
static private function deleteBans(array $ban_ids) { static private function deleteBans(array $ban_ids) {
$len = count($ban_ids); $len = count($ban_ids);
if ($len === 1) { if ($len === 1) {
@ -50,7 +54,7 @@ class Bans {
$to_delete_list = []; $to_delete_list = [];
while ($ban = $query->fetch(PDO::FETCH_ASSOC)) { while ($ban = $query->fetch(PDO::FETCH_ASSOC)) {
if ($ban['expires'] && ($ban['seen'] || !$require_ban_view) && $ban['expires'] < time()) { if (self::shouldDelete($ban, $require_ban_view)) {
$to_delete_list[] = $ban['id']; $to_delete_list[] = $ban['id'];
} elseif ($ban['id'] === $ban_id) { } elseif ($ban['id'] === $ban_id) {
if ($ban['post']) { if ($ban['post']) {
@ -106,7 +110,7 @@ class Bans {
$to_delete_list = []; $to_delete_list = [];
while ($ban = $query->fetch(PDO::FETCH_ASSOC)) { while ($ban = $query->fetch(PDO::FETCH_ASSOC)) {
if ($ban['expires'] && ($ban['seen'] || !$require_ban_view) && $ban['expires'] < time()) { if (self::shouldDelete($ban, $require_ban_view)) {
$to_delete_list[] = $ban['id']; $to_delete_list[] = $ban['id'];
} else { } else {
if ($ban['post']) { if ($ban['post']) {