From: Matthias Schmidt Date: Fri, 12 Aug 2011 12:12:27 +0000 (+0200) Subject: Replaced StorageHandler with UserStorageHandler X-Git-Tag: 2.0.0_Beta_1~1882^2~1^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c96ee721c6ec04615a519f47fa31ae374ef51a3e;p=GitHub%2FWoltLab%2FWCF.git Replaced StorageHandler with UserStorageHandler Since the StorageHandler "just" stores user data, shouldn't it be named UserStorageHandler? --- diff --git a/wcfsetup/install/files/lib/data/user/User.class.php b/wcfsetup/install/files/lib/data/user/User.class.php index a30fe88470..c2218ffe96 100644 --- a/wcfsetup/install/files/lib/data/user/User.class.php +++ b/wcfsetup/install/files/lib/data/user/User.class.php @@ -4,7 +4,7 @@ use wcf\data\DatabaseObject; use wcf\data\user\group\UserGroup; use wcf\data\user\UserList; use wcf\system\cache\CacheHandler; -use wcf\system\storage\StorageHandler; +use wcf\system\user\storage\UserStorageHandler; use wcf\system\WCF; use wcf\util\StringUtil; @@ -89,10 +89,10 @@ class User extends DatabaseObject { } else { // load storage data - StorageHandler::getInstance()->loadStorage(array($this->userID), 1); + UserStorageHandler::getInstance()->loadStorage(array($this->userID), 1); // get group ids - $data = StorageHandler::getInstance()->getStorage(array($this->userID), 'groupIDs', 1); + $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'groupIDs', 1); // cache does not exist or is outdated if ($data[$this->userID] === null) { @@ -107,7 +107,7 @@ class User extends DatabaseObject { } // update storage data - StorageHandler::getInstance()->update($this->userID, 'groupIDs', serialize($this->groupIDs), 1); + UserStorageHandler::getInstance()->update($this->userID, 'groupIDs', serialize($this->groupIDs), 1); } else { $this->groupIDs = unserialize($data[$this->userID]); @@ -128,8 +128,8 @@ class User extends DatabaseObject { // load storage data StorageHandler::getInstance()->loadStorage(array($this->userID), 1); - // get group ids - $data = StorageHandler::getInstance()->getStorage(array($this->userID), 'languageIDs', 1); + // get language ids + $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'languageIDs', 1); // cache does not exist or is outdated if ($data[$this->userID] === null) { @@ -143,7 +143,7 @@ class User extends DatabaseObject { } // update storage data - StorageHandler::getInstance()->update($this->userID, 'languageIDs', serialize($this->languageIDs), 1); + UserStorageHandler::getInstance()->update($this->userID, 'languageIDs', serialize($this->languageIDs), 1); } else { $this->languageIDs = unserialize($data[$this->userID]); diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index de4de0583d..bdf91a8b3b 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -9,8 +9,8 @@ use wcf\system\language\LanguageFactory; use wcf\system\package\PackageInstallationDispatcher; use wcf\system\session\SessionFactory; use wcf\system\session\SessionHandler; -use wcf\system\storage\StorageHandler; use wcf\system\template\TemplateEngine; +use wcf\system\user\storage\UserStorageHandler; use wcf\system\exception; use wcf\util; @@ -142,8 +142,8 @@ class WCF { CacheHandler::getInstance()->getCacheSource()->close(); } - // execute shutdown actions - StorageHandler::getInstance()->shutdown(); + // execute shutdown actions of user storage handler + UserStorageHandler::getInstance()->shutdown(); } /** diff --git a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php index 69888381e1..e8416cd634 100644 --- a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php +++ b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php @@ -5,7 +5,7 @@ use wcf\data\user\User; use wcf\system\auth\UserAuth; use wcf\system\cache\CacheHandler; use wcf\system\exception\PermissionDeniedException; -use wcf\system\storage\StorageHandler; +use wcf\system\user\storage\UserStorageHandler; use wcf\system\SingletonFactory; use wcf\system\WCF; use wcf\util\StringUtil; @@ -602,12 +602,12 @@ class SessionHandler extends SingletonFactory { */ public static function resetSessions(array $userIDs = array()) { if (count($userIDs)) { - StorageHandler::getInstance()->reset($userIDs, 'groupIDs', 1); - StorageHandler::getInstance()->reset($userIDs, 'languageIDs', 1); + UserStorageHandler::getInstance()->reset($userIDs, 'groupIDs', 1); + UserStorageHandler::getInstance()->reset($userIDs, 'languageIDs', 1); } else { - StorageHandler::getInstance()->resetAll('groupIDs', 1); - StorageHandler::getInstance()->resetAll('languageIDs', 1); + UserStorageHandler::getInstance()->resetAll('groupIDs', 1); + UserStorageHandler::getInstance()->resetAll('languageIDs', 1); } } } diff --git a/wcfsetup/install/files/lib/system/storage/StorageHandler.class.php b/wcfsetup/install/files/lib/system/storage/StorageHandler.class.php deleted file mode 100644 index cc2f631a7c..0000000000 --- a/wcfsetup/install/files/lib/system/storage/StorageHandler.class.php +++ /dev/null @@ -1,198 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.storage - * @category Community Framework - */ -class StorageHandler extends SingletonFactory { - /** - * data cache - * @var array - */ - protected $cache = array(); - - /** - * list of outdated data records - * @var array - */ - protected $resetFields = array(); - - /** - * list of updated or new data records - * @var array - */ - protected $updateFields = array(); - - /** - * Loads storage for a given set of users. - * - * @param array $userIDs - * @param integer $packageID - */ - public function loadStorage(array $userIDs, $packageID = PACKAGE_ID) { - $tmp = array(); - foreach ($userIDs as $userID) { - if (!isset($this->cache[$userID])) $tmp[] = $userID; - } - - // ignore users whose storage data is already loaded - if (empty($tmp)) return; - - $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("userID IN (?)", array($tmp)); - $conditions->add("packageID = ?", array(PACKAGE_ID)); - - $sql = "SELECT * - FROM wcf".WCF_N."_storage - ".$conditions; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($conditions->getParameters()); - while ($row = $statement->fetchArray()) { - if (!isset($this->cache[$row['userID']])) { - $this->cache[$row['userID']] = array(); - } - - if (!isset($this->cache[$row['userID']][$row['packageID']])) { - $this->cache[$row['userID']][$row['packageID']] = array(); - } - - $this->cache[$row['userID']][$row['packageID']][$row['field']] = $row['fieldValue']; - } - } - - /** - * Returns stored data for given users. - * - * @param array $userIDs - * @param string $field - * @param integer $packageID - * @return array - */ - public function getStorage(array $userIDs, $field, $packageID = PACKAGE_ID) { - $data = array(); - - foreach ($userIDs as $userID) { - if (isset($this->cache[$userID][$packageID][$field])) { - $data[$userID] = $this->cache[$userID][$packageID][$field]; - } - else { - $data[$userID] = null; - } - } - - return $data; - } - - /** - * Inserts new data records into database. - * - * @param integer $userID - * @param string $field - * @param string $fieldValue - * @param integer $packageID - */ - public function update($userID, $field, $fieldValue, $packageID = PACKAGE_ID) { - $this->updateFields[$userID][$packageID][$field] = $fieldValue; - - // update data cache for given user - if (!isset($this->cache[$userID])) { - $this->cache[$userID] = array(); - } - - if (!isset($this->cache[$userID][$packageID])) { - $this->cache[$userID][$packageID] = array(); - } - - $this->cache[$userID][$packageID][$field] = $fieldValue; - - // flag key as outdated - self::reset(array($userID), $field, $packageID); - } - - /** - * Removes a data record from database. - * - * @param array $userIDs - * @param string $field - * @param integer $packageID - */ - public function reset(array $userIDs, $field, $packageID = PACKAGE_ID) { - foreach ($userIDs as $userID) { - $this->resetFields[$userID][$packageID][] = $field; - } - } - - /** - * Removes a specific data record for all users. - * - * @param string $field - * @param integer $packageID - */ - public function resetAll($field, $packageID = PACKAGE_ID) { - $sql = "DELETE FROM wcf".WCF_N."_storage - WHERE field = ? - AND packageID = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array( - $field, - $packageID - )); - } - - /** - * Removes and inserts data records on shutdown. - */ - public function shutdown() { - // remove outdated entries - if (count($this->resetFields)) { - $sql = "DELETE FROM wcf".WCF_N."_storage - WHERE userID = ? - AND field = ? - AND packageID = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - - foreach ($this->resetFields as $userID => $data) { - foreach ($data as $packageID => $fields) { - foreach ($fields as $field) { - $statement->execute(array( - $userID, - $field, - $packageID - )); - } - } - } - } - - // insert data - if (count($this->updateFields)) { - $sql = "INSERT INTO wcf".WCF_N."_storage - (userID, field, fieldValue, packageID) - VALUES (?, ?, ?, ?)"; - $statement = WCF::getDB()->prepareStatement($sql); - - foreach ($this->updateFields as $userID => $data) { - foreach ($data as $packageID => $fieldValues) { - foreach ($fieldValues as $field => $fieldValue) { - $statement->execute(array( - $userID, - $field, - $fieldValue, - $packageID - )); - } - } - } - } - } -} diff --git a/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php b/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php new file mode 100644 index 0000000000..e3f03cbba7 --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php @@ -0,0 +1,198 @@ + + * @package com.woltlab.wcf + * @subpackage system.storage + * @category Community Framework + */ +class UserStorageHandler extends SingletonFactory { + /** + * data cache + * @var array + */ + protected $cache = array(); + + /** + * list of outdated data records + * @var array + */ + protected $resetFields = array(); + + /** + * list of updated or new data records + * @var array + */ + protected $updateFields = array(); + + /** + * Loads storage for a given set of users. + * + * @param array $userIDs + * @param integer $packageID + */ + public function loadStorage(array $userIDs, $packageID = PACKAGE_ID) { + $tmp = array(); + foreach ($userIDs as $userID) { + if (!isset($this->cache[$userID])) $tmp[] = $userID; + } + + // ignore users whose storage data is already loaded + if (empty($tmp)) return; + + $conditions = new PreparedStatementConditionBuilder(); + $conditions->add("userID IN (?)", array($tmp)); + $conditions->add("packageID = ?", array(PACKAGE_ID)); + + $sql = "SELECT * + FROM wcf".WCF_N."_storage + ".$conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditions->getParameters()); + while ($row = $statement->fetchArray()) { + if (!isset($this->cache[$row['userID']])) { + $this->cache[$row['userID']] = array(); + } + + if (!isset($this->cache[$row['userID']][$row['packageID']])) { + $this->cache[$row['userID']][$row['packageID']] = array(); + } + + $this->cache[$row['userID']][$row['packageID']][$row['field']] = $row['fieldValue']; + } + } + + /** + * Returns stored data for given users. + * + * @param array $userIDs + * @param string $field + * @param integer $packageID + * @return array + */ + public function getStorage(array $userIDs, $field, $packageID = PACKAGE_ID) { + $data = array(); + + foreach ($userIDs as $userID) { + if (isset($this->cache[$userID][$packageID][$field])) { + $data[$userID] = $this->cache[$userID][$packageID][$field]; + } + else { + $data[$userID] = null; + } + } + + return $data; + } + + /** + * Inserts new data records into database. + * + * @param integer $userID + * @param string $field + * @param string $fieldValue + * @param integer $packageID + */ + public function update($userID, $field, $fieldValue, $packageID = PACKAGE_ID) { + $this->updateFields[$userID][$packageID][$field] = $fieldValue; + + // update data cache for given user + if (!isset($this->cache[$userID])) { + $this->cache[$userID] = array(); + } + + if (!isset($this->cache[$userID][$packageID])) { + $this->cache[$userID][$packageID] = array(); + } + + $this->cache[$userID][$packageID][$field] = $fieldValue; + + // flag key as outdated + self::reset(array($userID), $field, $packageID); + } + + /** + * Removes a data record from database. + * + * @param array $userIDs + * @param string $field + * @param integer $packageID + */ + public function reset(array $userIDs, $field, $packageID = PACKAGE_ID) { + foreach ($userIDs as $userID) { + $this->resetFields[$userID][$packageID][] = $field; + } + } + + /** + * Removes a specific data record for all users. + * + * @param string $field + * @param integer $packageID + */ + public function resetAll($field, $packageID = PACKAGE_ID) { + $sql = "DELETE FROM wcf".WCF_N."_storage + WHERE field = ? + AND packageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array( + $field, + $packageID + )); + } + + /** + * Removes and inserts data records on shutdown. + */ + public function shutdown() { + // remove outdated entries + if (count($this->resetFields)) { + $sql = "DELETE FROM wcf".WCF_N."_storage + WHERE userID = ? + AND field = ? + AND packageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + + foreach ($this->resetFields as $userID => $data) { + foreach ($data as $packageID => $fields) { + foreach ($fields as $field) { + $statement->execute(array( + $userID, + $field, + $packageID + )); + } + } + } + } + + // insert data + if (count($this->updateFields)) { + $sql = "INSERT INTO wcf".WCF_N."_storage + (userID, field, fieldValue, packageID) + VALUES (?, ?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + + foreach ($this->updateFields as $userID => $data) { + foreach ($data as $packageID => $fieldValues) { + foreach ($fieldValues as $field => $fieldValue) { + $statement->execute(array( + $userID, + $field, + $fieldValue, + $packageID + )); + } + } + } + } + } +}