fixed removing bans from memcached cache upon unbanning by mod

This commit is contained in:
Savetheinternet 2011-07-27 13:44:09 +10:00
parent 4c1935a6b6
commit ba1ac9fdd8

17
mod.php
View File

@ -1432,16 +1432,16 @@
if($mod['type'] < $config['mod']['unban']) error($config['error']['noaccess']); if($mod['type'] < $config['mod']['unban']) error($config['error']['noaccess']);
foreach($_POST as $post => $value) { foreach($_POST as $post => $value) {
if(preg_match('/^ban_(.+)$/', $post, $m)) { if(preg_match('/^ban_(\w+)_(.+)$/', $post, $m)) {
$m[1] = str_replace('_', '.', $m[1]); $m[1] = str_replace('_', '.', $m[2]);
$query = prepare("DELETE FROM `bans` WHERE `ip` = :ip"); $query = prepare("DELETE FROM `bans` WHERE `ip` = :ip");
$query->bindValue(':ip', $m[1]); $query->bindValue(':ip', $m[2]);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if($config['memcached']['enabled']) { if($config['memcached']['enabled']) {
// Remove cached ban // Remove cached ban
// TODO // TODO
$memcached->delete("ban_${m[1]}"); $memcached->delete("ban_{$m[1]}_${m[2]}");
} }
} }
} }
@ -1474,7 +1474,7 @@
'<td style="white-space: nowrap">' . '<td style="white-space: nowrap">' .
// Checkbox // Checkbox
'<input type="checkbox" name="ban_' . $ban['ip'] . '" id="ban_' . $ban['ip'] . '" /> ' . '<input type="checkbox" name="ban_' . $ban['board'] . '_' . $ban['ip'] . '" id="ban_' . $ban['ip'] . '" /> ' .
// IP address // IP address
(preg_match('/^(\d+\.\d+\.\d+\.\d+|' . $config['ipv6_regex'] . ')$/', $ban['ip']) ? (preg_match('/^(\d+\.\d+\.\d+\.\d+|' . $config['ipv6_regex'] . ')$/', $ban['ip']) ?
@ -2093,8 +2093,11 @@
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if($config['memcached']['enabled']) { if($config['memcached']['enabled']) {
// Remove cached ban // Remove cached ban(s)
$memcached->delete("ban_${ip}"); $boards = listBoards();
foreach($boards as &$_board) {
$memcached->delete("ban_{$_board['id']}_${ip}");
}
} }
} elseif($mod['type'] >= $config['mod']['create_notes'] && isset($_POST['note'])) { } elseif($mod['type'] >= $config['mod']['create_notes'] && isset($_POST['note'])) {
$query = prepare("INSERT INTO `ip_notes` VALUES(NULL, :ip, :mod, :time, :body)"); $query = prepare("INSERT INTO `ip_notes` VALUES(NULL, :ip, :mod, :time, :body)");