1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00

Moving pruning to *Action

This commit is contained in:
Tim Düsterhus 2012-05-19 20:33:25 +02:00
parent 0958416f93
commit f72dfb4e54
5 changed files with 60 additions and 60 deletions

View File

@ -15,4 +15,24 @@ class ChatMessageAction extends \wcf\data\AbstractDatabaseObjectAction {
* @see \wcf\data\AbstractDatabaseObjectAction::$className * @see \wcf\data\AbstractDatabaseObjectAction::$className
*/ */
protected $className = '\wcf\data\chat\message\ChatMessageEditor'; protected $className = '\wcf\data\chat\message\ChatMessageEditor';
/**
* Removes old messages.
*
* @return integer Number of deleted messages.
*/
public function prune() {
$sql = "SELECT
".call_user_func(array($this->className, 'getDatabaseTableIndexName'))."
FROM
".call_user_func(array($this->className, 'getDatabaseTableName'))."
WHERE
time < ?";
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
$stmt->execute(array(TIME_NOW - CHAT_LOG_ARCHIVETIME));
$objectIDs = array();
while ($objectIDs[] = $stmt->fetchColumn());
return call_user_func(array($this->className, 'deleteAll'), $objectIDs);
}
} }

View File

@ -30,25 +30,4 @@ public static function create(array $parameters = array()) {
return parent::create($parameters); return parent::create($parameters);
} }
/**
* Removes old messages.
*
* @param integer $lifetime Delete messages older that this time.
* @return integer Number of deleted messages.
*/
public static function prune($lifetime = CHAT_LOG_ARCHIVETIME) {
$sql = "SELECT
".static::getDatabaseTableIndexName()."
FROM
".static::getDatabaseTableName()."
WHERE
time < ?";
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
$stmt->execute(array(TIME_NOW - $lifetime));
$objectIDs = array();
while ($objectIDs[] = $stmt->fetchColumn());
return self::deleteAll($objectIDs);
}
} }

View File

@ -35,21 +35,49 @@ public function create() {
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
$sql = "SELECT MAX(position) $sql = "SELECT MAX(position)
FROM wcf".WCF_N."_chat_room FROM ".call_user_func(array($this->className, 'getDatabaseTableName'))."
FOR UPDATE"; FOR UPDATE";
$stmt = WCF::getDB()->prepareStatement($sql); $stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute(); $stmt->execute();
$sql = "UPDATE wcf".WCF_N."_chat_room $editor = new ChatRoomEditor($room);
SET position = ".($stmt->fetchColumn() + 1)." $editor->update(array('position' => ($stmt->fetchColumn() + 1)));
WHERE roomID = ?";
$stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute(array($room->roomID));
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();
return $room; return $room;
} }
/**
* Deletes temporary rooms that are unused.
*
* @return integer Number of deleted rooms
*/
public function prune() {
$sql = "SELECT
".call_user_func(array($this->className, 'getDatabaseTableIndexName'))."
FROM
".call_user_func(array($this->className, 'getDatabaseTableName'))."
WHERE
permanent = ?
AND roomID NOT IN (
SELECT
fieldValue AS roomID
FROM
wcf".WCF_N."_user_storage
WHERE
packageID = ?
AND field = ?
AND fieldValue IS NOT NULL
)";
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
$stmt->execute(array(0, \wcf\util\ChatUtil::getPackageID(), 'roomID'));
$objectIDs = array();
while ($objectIDs[] = $stmt->fetchColumn());
return call_user_func(array($this->className, 'deleteAll'), $objectIDs);
}
/** /**
* Validates parameters to update sorting. * Validates parameters to update sorting.
*/ */

View File

@ -57,36 +57,6 @@ public static function deleteAll(array $objectIDs = array()) {
return parent::deleteAll($objectIDs); return parent::deleteAll($objectIDs);
} }
/**
* Deletes temporary rooms that are unused.
*
* @return integer Number of deleted rooms
*/
public static function prune() {
$sql = "SELECT
".static::getDatabaseTableIndexName()."
FROM
".static::getDatabaseTableName()."
WHERE
permanent = ?
AND roomID NOT IN (
SELECT
fieldValue AS roomID
FROM
wcf".WCF_N."_user_storage
WHERE
packageID = ?
AND field = ?
AND fieldValue IS NOT NULL
)";
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
$stmt->execute(array(0, \wcf\util\ChatUtil::getPackageID(), 'roomID'));
$objectIDs = array();
while ($objectIDs[] = $stmt->fetchColumn());
return self::deleteAll($objectIDs);
}
/** /**
* Clears the room cache. * Clears the room cache.
*/ */

View File

@ -1,5 +1,6 @@
<?php <?php
namespace wcf\system\cronjob; namespace wcf\system\cronjob;
use \wcf\data\chat;
/** /**
* Vaporizes unneeded data. * Vaporizes unneeded data.
@ -15,8 +16,10 @@ class ChatCleanupCronjob implements ICronjob {
* @see wcf\system\ICronjob::execute() * @see wcf\system\ICronjob::execute()
*/ */
public function execute(\wcf\data\cronjob\Cronjob $cronjob) { public function execute(\wcf\data\cronjob\Cronjob $cronjob) {
\wcf\data\chat\message\ChatMessageEditor::prune(); $messageAction = new chat\message\ChatMessageAction(array(), 'prune');
\wcf\data\chat\room\ChatRoomEditor::prune(); $messageAction->executeAction();
$roomAction = new chat\room\ChatRoomAction(array(), 'prune');
$roomAction->executeAction();
// kill dead users // kill dead users
$deadUsers = \wcf\util\ChatUtil::getDiedUsers(); $deadUsers = \wcf\util\ChatUtil::getDiedUsers();