/** * Unban user * @since Version 3.2 * @version 3.2 * @param int $banId * @param int|bool $userId * @return boolean */ public function unBanUser($banId, $userId = null) { $success = false; /** * Empty the cache */ try { $this->Memcached->delete("railpage:bancontrol.users"); $this->Memcached->delete(self::CACHE_KEY_ALL); } catch (Exception $e) { // throw it away } try { $this->Redis->delete("railpage:bancontrol"); } catch (Exception $e) { // throw it away } if ($banId instanceof User) { $userId = $banId->id; } if ($userId == null) { $query = "SELECT user_id FROM bancontrol WHERE id = ?"; $userId = $this->db->fetchOne($query, $banId); } if ($userId > 0) { $data = array("ban_active" => 0); $where = array("user_id = " . $userId); $this->db->update("bancontrol", $data, $where); $success = true; $cachekey_user = sprintf(self::CACHE_KEY_USER, $userId); $this->Memcached->save($cachekey_user, false, strtotime("+5 weeks")); } if ($success) { // Tell the world that they've been unbanned $ThisUser = UserFactory::CreateUser($userId); $ThisUser->active = 1; $ThisUser->location = ""; $ThisUser->signature = ""; $ThisUser->avatar = ""; $ThisUser->interests = ""; $ThisUser->occupation = ""; try { $ThisUser->commit(); $Smarty = AppCore::getSmarty(); // Send the ban email $Smarty->Assign("userdata_username", $ThisUser->username); // Send the confirmation email $Notification = new Notification(); $Notification->addRecipient($ThisUser->id, $ThisUser->username, $ThisUser->contact_email); $Notification->body = $Smarty->Fetch($Smarty->ResolveTemplate("email_unban")); $Notification->subject = "Railpage account re-activation"; $Notification->transport = Notifications::TRANSPORT_EMAIL; $Notification->commit()->dispatch(); return true; } catch (Exception $e) { global $Error; if (isset($Error)) { $Error->save($e, $_SESSION['user_id']); } Debug::logException($e); } } return false; }