1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2025-01-22 02:00:40 +00:00

Don't delete expired suspensions

This commit is contained in:
Tim Düsterhus 2013-06-22 14:40:54 +02:00
parent c6e146a038
commit 08451f44fe
13 changed files with 85 additions and 32 deletions

View File

@ -18,7 +18,13 @@
<div class="container containerPadding marginTop">
<fieldset>
<legend>{lang}wcf.global.filter{/lang}</legend>
<dl>
<dd>
<label><input type="checkbox" id="displayRevoked" name="displayRevoked" value="1"{if $displayRevoked} checked="checked"{/if} /> {lang}chat.acp.suspension.displayRevoked{/lang}</label>
</dd>
</dl>
<dl>
<dt><label for="username">{lang}wcf.user.username{/lang}</label></dt>
<dd>

View File

@ -80,6 +80,13 @@ class ChatSuspensionListPage extends \wcf\page\SortablePage {
*/
public $filterRoomID = null;
/**
* display revoked suspensions
*
* @var integer
*/
public $displayRevoked = 0;
/**
* @see \wcf\page\IPage::readParameters()
*/
@ -105,6 +112,9 @@ class ChatSuspensionListPage extends \wcf\page\SortablePage {
// get room IDs by request
if (isset($_REQUEST['roomID']) && $_REQUEST['roomID'] != -1) $this->filterRoomID = intval($_REQUEST['roomID']);
if (isset($_REQUEST['suspensionType']) && !empty($_REQUEST['suspensionType'])) $this->filterSuspensionType = intval($_REQUEST['suspensionType']);
// display revoked
if (isset($_REQUEST['displayRevoked'])) $this->displayRevoked = intval($_REQUEST['displayRevoked']);
}
/**
@ -120,7 +130,8 @@ class ChatSuspensionListPage extends \wcf\page\SortablePage {
'issuerUsername' => $this->filterIssuerUsername,
'suspensionType' => $this->filterSuspensionType,
'userID' => $this->filterUserID,
'issuerUserID' => $this->filterIssuerUserID
'issuerUserID' => $this->filterIssuerUserID,
'displayRevoked' => $this->displayRevoked
));
}
@ -141,7 +152,10 @@ class ChatSuspensionListPage extends \wcf\page\SortablePage {
$this->objectList->sqlConditionJoins .= $conditionJoins;
$this->objectList->sqlJoins .= $conditionJoins;
$this->objectList->getConditionBuilder()->add('expires >= ?', array(TIME_NOW));
if (!$this->displayRevoked) {
$this->objectList->getConditionBuilder()->add('expires >= ?', array(TIME_NOW));
$this->objectList->getConditionBuilder()->add('revoked = ?', array(0));
}
$this->objectList->getConditionBuilder()->add('(room_table.permanent = ? OR suspension.roomID IS NULL)', array(1));
if ($this->filterSuspensionType !== null) $this->objectList->getConditionBuilder()->add('suspension.type = ?', array($this->filterSuspensionType));
if ($this->filterUserID !== null) $this->objectList->getConditionBuilder()->add('suspension.userID = ?', array($this->filterUserID));

View File

@ -31,7 +31,7 @@ class Suspension extends \chat\data\CHATDatabaseObject {
* @return boolean
*/
public function isValid() {
return $this->expires > TIME_NOW;
return $this->expires > TIME_NOW && !$this->revoked;
}
/**
@ -53,15 +53,18 @@ class Suspension extends \chat\data\CHATDatabaseObject {
if ($suspensions === false) throw new \wcf\system\exception\SystemException();
}
catch (\wcf\system\exception\SystemException $e) {
$condition = new \wcf\system\database\util\PreparedStatementConditionBuilder();
$condition->add('userID = ?', array($user->userID));
$condition->add('expires > ?', array(TIME_NOW));
$condition->add('revoked = ?', array(0));
$sql = "SELECT
*
FROM
chat".WCF_N."_suspension
WHERE
userID = ?
AND expires > ?";
".$condition;
$stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute(array($user->userID, TIME_NOW));
$stmt->execute($condition->getParameters());
$suspensions = array();
while ($suspension = $stmt->fetchObject('\chat\data\suspension\Suspension')) {
@ -76,7 +79,7 @@ class Suspension extends \chat\data\CHATDatabaseObject {
/**
* Returns the appropriate suspension for user, room and type.
* Returns false if no suspension was found.
* Returns false if no active suspension was found.
*
* @param \wcf\data\user\User $user
* @param \chat\data\room\Room $room
@ -84,23 +87,22 @@ class Suspension extends \chat\data\CHATDatabaseObject {
* @return \chat\data\suspension\Suspension
*/
public static function getSuspensionByUserRoomAndType(\wcf\data\user\User $user, \chat\data\room\Room $room, $type) {
$condition = new \wcf\system\database\util\PreparedStatementConditionBuilder();
$condition->add('userID = ?', array($user->userID));
$condition->add('type = ?', array($type));
$condition->add('expires > ?', array(TIME_NOW));
$condition->add('revoked = ?', array(0));
if ($room->roomID) $condition->add('roomID = ?', array($room->roomID));
else $condition->add('roomID IS NULL');
$sql = "SELECT
*
FROM
chat".WCF_N."_suspension
WHERE
userID = ?
AND type = ?";
$parameter = array($user->userID, $type);
if ($room->roomID) {
$sql .= " AND roomID = ?";
$parameter[] = $room->roomID;
}
else $sql .= " AND roomID IS NULL";
".$condition;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($parameter);
$statement->execute($condition->getParameters());
$row = $statement->fetchArray();
if (!$row) return false;

View File

@ -17,9 +17,9 @@ class SuspensionAction extends \wcf\data\AbstractDatabaseObjectAction {
protected $className = '\chat\data\suspension\SuspensionEditor';
/**
* Deletes expired suspensions.
* Revokes expired suspensions.
*
* @return integer Number of deleted suspensions
* @return array<integer> Revoked suspensions
*/
public function prune() {
$sql = "SELECT
@ -34,6 +34,26 @@ class SuspensionAction extends \wcf\data\AbstractDatabaseObjectAction {
while ($objectID = $stmt->fetchColumn()) $objectIDs[] = $objectID;
return call_user_func(array($this->className, 'deleteAll'), $objectIDs);
$suspensionAction = new self($objectIDs, 'revoke');
$suspensionAction->executeAction();
return $objectIDs;
}
/**
* Revokes suspensions.
*/
public function revoke() {
if (!isset($this->parameters['revoker'])) {
$this->parameters['revoker'] = null;
}
$objectAction = new self($this->objectIDs, 'update', array(
'data' => array(
'revoked' => 1,
'revoker' => $this->parameters['revoker']
)
));
$objectAction->executeAction();
}
}

View File

@ -23,7 +23,7 @@ class GmuteCommand extends MuteCommand {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
}
$action = new suspension\SuspensionAction(array($suspension), 'delete');
$action = new suspension\SuspensionAction(array($suspension), 'revoke');
$action->executeAction();
}

View File

@ -22,7 +22,9 @@ class GunbanCommand extends UnmuteCommand {
$room = new \chat\data\room\Room(null, array('roomID' => null));
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, suspension\Suspension::TYPE_BAN)) {
$action = new suspension\SuspensionAction(array($suspension), 'delete');
$action = new suspension\SuspensionAction(array($suspension), 'revoke', array(
'revoker' => WCF::getUser()->userID
));
$action->executeAction();
}
else {

View File

@ -22,7 +22,9 @@ class GunmuteCommand extends UnmuteCommand {
$room = new \chat\data\room\Room(null, array('roomID' => null));
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, suspension\Suspension::TYPE_MUTE)) {
$action = new suspension\SuspensionAction(array($suspension), 'delete');
$action = new suspension\SuspensionAction(array($suspension), 'revoke', array(
'revoker' => WCF::getUser()->userID
));
$action->executeAction();
}
else {

View File

@ -61,7 +61,7 @@ class MuteCommand extends \chat\system\command\AbstractRestrictedCommand {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
}
$action = new suspension\SuspensionAction(array($suspension), 'delete');
$action = new suspension\SuspensionAction(array($suspension), 'revoke');
$action->executeAction();
}

View File

@ -20,7 +20,9 @@ class UnbanCommand extends UnmuteCommand {
*/
public function executeAction() {
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_BAN)) {
$action = new suspension\SuspensionAction(array($suspension), 'delete');
$action = new suspension\SuspensionAction(array($suspension), 'revoke', array(
'revoker' => WCF::getUser()->userID
));
$action->executeAction();
}
else {

View File

@ -41,7 +41,9 @@ class UnmuteCommand extends \chat\system\command\AbstractRestrictedCommand {
*/
public function executeAction() {
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_MUTE)) {
$action = new suspension\SuspensionAction(array($suspension), 'delete');
$action = new suspension\SuspensionAction(array($suspension), 'revoke', array(
'revoker' => WCF::getUser()->userID
));
$action->executeAction();
}
else {

View File

@ -51,8 +51,10 @@ CREATE TABLE chat1_suspension (
time INT(10) NOT NULL,
issuer INT(10) DEFAULT NULL,
reason VARCHAR(255) NOT NULL DEFAULT '',
revoked TINYINT(1) NOT NULL DEFAULT 0,
revoker INT(10) DEFAULT NULL,
UNIQUE KEY suspension (userID, roomID, type),
KEY suspension (userID, roomID, type),
KEY (roomID),
KEY (type),
KEY (expires)
@ -74,6 +76,7 @@ ALTER TABLE chat1_room ADD FOREIGN KEY (owner) REFERENCES wcf1_user (userID) ON
ALTER TABLE chat1_suspension ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE CASCADE;
ALTER TABLE chat1_suspension ADD FOREIGN KEY (roomID) REFERENCES chat1_room (roomID) ON DELETE CASCADE;
ALTER TABLE chat1_suspension ADD FOREIGN KEY (issuer) REFERENCES wcf1_user (userID) ON DELETE SET NULL;
ALTER TABLE chat1_suspension ADD FOREIGN KEY (revoker) REFERENCES wcf1_user (userID) ON DELETE SET NULL;
ALTER TABLE wcf1_user ADD FOREIGN KEY (chatRoomID) REFERENCES chat1_room (roomID) ON DELETE SET NULL;

View File

@ -66,7 +66,7 @@
</category>
<category name="chat.error">
<item name="chat.error.notFound"><![CDATA[Der Befehl wurde nicht gefunden.]]></item>
<item name="chat.error.notFound"><![CDATA[Der Befehl „{$exception->getCommand()}“ wurde nicht gefunden.]]></item>
<item name="chat.error.userNotFound"><![CDATA[Der Benutzer „{$exception->getUsername()}“ wurde nicht gefunden.]]></item>
<item name="chat.error.permissionDenied"><![CDATA[Sie dürfen diesen Befehl nicht verwenden.]]></item>
<item name="chat.error.duplicateTab"><![CDATA[Der Chat wurde in einem weiteren Tab geöffnet.]]></item>

View File

@ -5,7 +5,7 @@
<packagedescription><![CDATA[Chat for WoltLab Community Framework™.]]></packagedescription>
<packagedescription language="de"><![CDATA[Chat für WoltLab Community Framework™.]]></packagedescription>
<isapplication>1</isapplication>
<version>3.0.0 Alpha 55</version><!-- Codename: Codenames are overrated -->
<version>3.0.0 Alpha 59</version><!-- Codename: Codenames are overrated -->
<date>2011-11-26</date>
</packageinformation>