2011-11-27 19:20:13 +00:00
|
|
|
<?php
|
|
|
|
namespace wcf\data\chat\room;
|
2012-02-04 20:57:39 +00:00
|
|
|
use \wcf\system\WCF;
|
2011-11-27 19:20:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides functions to edit chat rooms.
|
|
|
|
*
|
|
|
|
* @author Tim Düsterhus
|
2012-01-28 16:50:33 +00:00
|
|
|
* @copyright 2010-2012 Tim Düsterhus
|
2011-11-27 19:20:13 +00:00
|
|
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
2012-03-12 16:18:15 +00:00
|
|
|
* @package be.bastelstu.wcf.chat
|
2011-11-27 19:20:13 +00:00
|
|
|
* @subpackage data.chat.room
|
|
|
|
*/
|
2011-12-13 21:18:04 +00:00
|
|
|
class ChatRoomEditor extends \wcf\data\DatabaseObjectEditor implements \wcf\data\IEditableCachedObject {
|
2011-11-27 19:20:13 +00:00
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\data\DatabaseObjectDecorator::$baseClass
|
2011-11-27 19:20:13 +00:00
|
|
|
*/
|
|
|
|
protected static $baseClass = '\wcf\data\chat\room\ChatRoom';
|
|
|
|
|
2012-03-08 21:07:46 +00:00
|
|
|
|
2012-02-04 20:57:39 +00:00
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\data\DatabaseObjectEditor::deleteAll()
|
2012-02-04 20:57:39 +00:00
|
|
|
*/
|
|
|
|
public static function deleteAll(array $objectIDs = array()) {
|
2012-03-08 21:07:46 +00:00
|
|
|
$packageID = \wcf\util\ChatUtil::getPackageID();
|
2012-02-04 20:57:39 +00:00
|
|
|
|
|
|
|
WCF::getDB()->beginTransaction();
|
|
|
|
foreach ($objectIDs as $objectID) {
|
2012-02-05 17:29:16 +00:00
|
|
|
\wcf\system\language\I18nHandler::getInstance()->remove('wcf.chat.room.title'.$objectID, $packageID);
|
|
|
|
\wcf\system\language\I18nHandler::getInstance()->remove('wcf.chat.room.topic'.$objectID, $packageID);
|
2012-02-04 20:57:39 +00:00
|
|
|
}
|
|
|
|
|
2012-03-22 15:26:52 +00:00
|
|
|
// The transaction is being committed in parent::deleteAll()
|
|
|
|
// The beginTransaction() call in there is simply ignored.
|
|
|
|
return parent::deleteAll($objectIDs);
|
2012-02-04 20:57:39 +00:00
|
|
|
}
|
2012-03-08 21:07:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes temporary rooms that are unused.
|
|
|
|
*
|
|
|
|
* @return integer Number of deleted rooms
|
|
|
|
*/
|
|
|
|
public static function prune() {
|
|
|
|
$sql = "SELECT
|
2012-04-15 16:00:59 +00:00
|
|
|
".static::getDatabaseTableIndexName()."
|
2012-03-08 21:07:46 +00:00
|
|
|
FROM
|
2012-04-15 16:00:59 +00:00
|
|
|
".static::getDatabaseTableName()."
|
2012-03-08 21:07:46 +00:00
|
|
|
WHERE
|
2012-04-15 16:00:59 +00:00
|
|
|
permanent = ?
|
|
|
|
AND roomID NOT IN (
|
2012-03-08 21:07:46 +00:00
|
|
|
SELECT
|
|
|
|
fieldValue AS roomID
|
|
|
|
FROM
|
|
|
|
wcf".WCF_N."_user_storage
|
|
|
|
WHERE
|
|
|
|
packageID = ?
|
2012-04-15 16:00:59 +00:00
|
|
|
AND field = ?
|
|
|
|
AND fieldValue IS NOT NULL
|
|
|
|
)";
|
2012-03-08 21:07:46 +00:00
|
|
|
$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.
|
|
|
|
*/
|
|
|
|
public static function resetCache() {
|
|
|
|
\wcf\system\cache\CacheHandler::getInstance()->clear(WCF_DIR.'cache', 'cache.chatrooms.php');
|
|
|
|
}
|
2011-11-27 19:20:13 +00:00
|
|
|
}
|