1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00

Adapt to cache system changes

This commit is contained in:
Tim Düsterhus 2013-02-04 19:27:03 +01:00
parent 98281b502b
commit 1bb655d08c
7 changed files with 13 additions and 37 deletions

View File

@ -1,7 +1,6 @@
<?php <?php
namespace chat\data\room; namespace chat\data\room;
use \chat\data\suspension\Suspension; use \chat\data\suspension\Suspension;
use \wcf\system\cache\CacheHandler;
use \wcf\system\WCF; use \wcf\system\WCF;
/** /**
@ -24,13 +23,6 @@ class Room extends \chat\data\CHATDatabaseObject implements \wcf\system\request\
*/ */
protected static $databaseTableIndexName = 'roomID'; protected static $databaseTableIndexName = 'roomID';
/**
* Caches rooms.
*
* @var array<wcf\data\chat\room\ChatRoom>
*/
protected static $cache = null;
/** /**
* @see \wcf\data\chat\room\ChatRoom::getTitle(); * @see \wcf\data\chat\room\ChatRoom::getTitle();
*/ */
@ -121,16 +113,7 @@ public function countUsers() {
* Loads the room cache. * Loads the room cache.
*/ */
public static function getCache() { public static function getCache() {
if (self::$cache === null) { return \chat\system\cache\builder\RoomCacheBuilder::getInstance()->getData();
CacheHandler::getInstance()->addResource(
'chatRooms',
CHAT_DIR.'cache/cache.rooms.php',
'\chat\system\cache\builder\RoomCacheBuilder'
);
self::$cache = CacheHandler::getInstance()->get('chatRooms');
}
return self::$cache;
} }
/** /**

View File

@ -59,6 +59,7 @@ public static function deleteAll(array $objectIDs = array()) {
* Clears the room cache. * Clears the room cache.
*/ */
public static function resetCache() { public static function resetCache() {
\wcf\system\cache\CacheHandler::getInstance()->clear(CHAT_DIR.'cache', 'cache.rooms.php'); \chat\system\cache\builder\RoomCacheBuilder::getInstance()->reset();
\chat\system\cache\builder\PermissionCacheBuilder::getInstance()->reset();
} }
} }

View File

@ -1,7 +1,6 @@
<?php <?php
namespace chat\page; namespace chat\page;
use \chat\data; use \chat\data;
use \wcf\system\cache\CacheHandler;
use \wcf\system\WCF; use \wcf\system\WCF;
/** /**

View File

@ -1,7 +1,6 @@
<?php <?php
namespace chat\page; namespace chat\page;
use \chat\data; use \chat\data;
use \wcf\system\cache\CacheHandler;
use \wcf\system\exception\IllegalLinkException; use \wcf\system\exception\IllegalLinkException;
use \wcf\system\WCF; use \wcf\system\WCF;

View File

@ -11,20 +11,18 @@
* @package be.bastelstu.chat * @package be.bastelstu.chat
* @subpackage system.cache.builder * @subpackage system.cache.builder
*/ */
class PermissionCacheBuilder implements \wcf\system\cache\builder\ICacheBuilder { class PermissionCacheBuilder implements \wcf\system\cache\builder\AbstractCacheBuilder {
/** /**
* @see wcf\system\cache\ICacheBuilder::getData() * @see wcf\system\cache\AbstractCacheBuilder::rebuild()
*/ */
public function getData(array $cacheResource) { public function rebuild(array $parameters) {
$data = array(); $data = array();
list(, $groupIDsStr) = explode('-', $cacheResource['cache']);
$groupIDs = explode(',', $groupIDsStr);
if (count($groupIDs)) { if (!empty($parameters)) {
$conditionBuilder = new \wcf\system\database\util\PreparedStatementConditionBuilder(); $conditionBuilder = new \wcf\system\database\util\PreparedStatementConditionBuilder();
$conditionBuilder->add('acl_option.objectTypeID = ?', array(\wcf\system\acl\ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room'))); $conditionBuilder->add('acl_option.objectTypeID = ?', array(\wcf\system\acl\ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room')));
$conditionBuilder->add('option_to_group.optionID = acl_option.optionID'); $conditionBuilder->add('option_to_group.optionID = acl_option.optionID');
$conditionBuilder->add('option_to_group.groupID IN (?)', array($groupIDs)); $conditionBuilder->add('option_to_group.groupID IN (?)', array($parameters));
$sql = "SELECT option_to_group.groupID, option_to_group.objectID AS roomID, option_to_group.optionValue, $sql = "SELECT option_to_group.groupID, option_to_group.objectID AS roomID, option_to_group.optionValue,
acl_option.optionName AS permission acl_option.optionName AS permission
FROM wcf".WCF_N."_acl_option acl_option, FROM wcf".WCF_N."_acl_option acl_option,

View File

@ -10,11 +10,11 @@
* @package be.bastelstu.chat * @package be.bastelstu.chat
* @subpackage system.cache.builder * @subpackage system.cache.builder
*/ */
class RoomCacheBuilder implements \wcf\system\cache\builder\ICacheBuilder { class RoomCacheBuilder implements \wcf\system\cache\builder\AbstractCacheBuilder {
/** /**
* @see \wcf\system\cache\ICacheBuilder::getData() * @see \wcf\system\cache\AbstractCacheBuilder::rebuild()
*/ */
public function getData(array $cacheResource) { public function rebuild(array $parameters) {
// get all chat rooms // get all chat rooms
$roomList = new \chat\data\room\RoomList(); $roomList = new \chat\data\room\RoomList();
$roomList->sqlOrderBy = "room.position"; $roomList->sqlOrderBy = "room.position";

View File

@ -1,7 +1,6 @@
<?php <?php
namespace chat\system\permission; namespace chat\system\permission;
use \wcf\system\acl\ACLHandler; use \wcf\system\acl\ACLHandler;
use \wcf\system\cache\CacheHandler;
use \wcf\system\package\PackageDependencyHandler; use \wcf\system\package\PackageDependencyHandler;
use \wcf\system\WCF; use \wcf\system\WCF;
@ -35,10 +34,7 @@ public function __construct(\wcf\data\user\User $user = null) {
$ush = \wcf\system\user\storage\UserStorageHandler::getInstance(); $ush = \wcf\system\user\storage\UserStorageHandler::getInstance();
// get groups permissions // get groups permissions
$groups = implode(',', $user->getGroupIDs()); $this->chatPermissions = \chat\system\cache\builder\PermissionCacheBuilder::getInstance()->getData($user->getGroupIDs);
$groupsFileName = \wcf\util\StringUtil::getHash(implode('-', $user->getGroupIDs()));
CacheHandler::getInstance()->addResource('permission-'.$groups, WCF_DIR.'cache/cache.permission-'.$groupsFileName.'.php', '\chat\system\cache\builder\PermissionCacheBuilder');
$this->chatPermissions = CacheHandler::getInstance()->get('permission-'.$groups);
// get user permissions // get user permissions
if ($user->userID) { if ($user->userID) {
@ -106,6 +102,6 @@ public static function clearCache() {
$ush = \wcf\system\user\storage\UserStorageHandler::getInstance(); $ush = \wcf\system\user\storage\UserStorageHandler::getInstance();
$ush->resetAll('chatUserPermissions', $packageID); $ush->resetAll('chatUserPermissions', $packageID);
\wcf\system\cache\CacheHandler::getInstance()->clear(WCF_DIR.'cache', 'cache.permission-[a-f0-9]{40}.php'); \chat\system\cache\builder\PermissionCacheBuilder::getInstance()->reset();
} }
} }