public function applyBan($NewBan = null, $OldBan = null)
{
if (!$NewBan && !$OldBan) {
return;
}
$OldUsers = array();
$NewUsers = array();
$NewUserIDs = array();
$AllBans = $this->allBans();
if ($NewBan) {
// Get a list of users affected by the new ban.
if (isset($NewBan['BanID'])) {
$AllBans[$NewBan['BanID']] = $NewBan;
}
// Protect against a lack of inet6_ntoa, which wasn't introduced until MySQL 5.6.3.
try {
$NewUsers = $this->SQL->select('u.UserID, u.Banned')->from('User u')->where($this->banWhere($NewBan))->where('Admin', 0)->get()->resultArray();
} catch (Exception $e) {
Logger::log(Logger::ERROR, $e->getMessage());
$NewUsers = [];
}
$NewUserIDs = array_column($NewUsers, 'UserID');
} elseif (isset($OldBan['BanID'])) {
unset($AllBans[$OldBan['BanID']]);
}
if ($OldBan) {
// Get a list of users affected by the old ban.
// Protect against a lack of inet6_ntoa, which wasn't introduced until MySQL 5.6.3.
try {
$OldUsers = $this->SQL->select('u.UserID, u.LastIPAddress, u.Name, u.Email, u.Banned')->from('User u')->where($this->banWhere($OldBan))->get()->resultArray();
} catch (Exception $e) {
Logger::log(Logger::ERROR, $e->getMessage());
$OldUsers = [];
}
}
// Check users that need to be unbanned.
foreach ($OldUsers as $User) {
if (in_array($User['UserID'], $NewUserIDs)) {
continue;
}
// TODO check the user against the other bans.
$this->saveUser($User, false);
}
// Check users that need to be banned.
foreach ($NewUsers as $User) {
if (self::isBanned($User['Banned'], BanModel::BAN_AUTOMATIC)) {
continue;
}
$this->saveUser($User, true, $NewBan);
}
}