Replaced StorageHandler with UserStorageHandler
authorMatthias Schmidt <gravatronics@live.com>
Fri, 12 Aug 2011 12:12:27 +0000 (14:12 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 12 Aug 2011 12:12:27 +0000 (14:12 +0200)
Since the StorageHandler "just" stores user data, shouldn't it be named
UserStorageHandler?

wcfsetup/install/files/lib/data/user/User.class.php
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/session/SessionHandler.class.php
wcfsetup/install/files/lib/system/storage/StorageHandler.class.php [deleted file]
wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php [new file with mode: 0644]

index a30fe884706f2c88a96d510785fdbe103a9bb8a5..c2218ffe9675450bd3cae7e172ab4e5544c9a22f 100644 (file)
@@ -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]);
index de4de0583d5a073ee3701086eef2b6dd25975590..bdf91a8b3bd66448fc22dbb2e6b96d31fde3977d 100644 (file)
@@ -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();
        }
        
        /**
index 69888381e1cfe620404d1adc13b6299b5c24338f..e8416cd6341b3f0c7164e4a7adbdb435ee8b1a22 100644 (file)
@@ -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 (file)
index cc2f631..0000000
+++ /dev/null
@@ -1,198 +0,0 @@
-<?php
-namespace wcf\system\storage;
-use wcf\system\database\util\PreparedStatementConditionBuilder;
-use wcf\system\SingletonFactory;
-use wcf\system\WCF;
-
-/**
- * Handles the persistent data storage.
- * 
- * @author     Alexander Ebert
- * @copyright  2001-2011 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    com.woltlab.wcf
- * @subpackage system.storage
- * @category   Community Framework
- */
-class StorageHandler extends SingletonFactory {
-       /**
-        * data cache
-        * @var array<array>
-        */
-       protected $cache = array();
-       
-       /**
-        * list of outdated data records
-        * @var array<array>
-        */
-       protected $resetFields = array();
-       
-       /**
-        * list of updated or new data records
-        * @var array<array>
-        */
-       protected $updateFields = array();
-       
-       /**
-        * Loads storage for a given set of users.
-        * 
-        * @param       array<integer>  $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<integer>  $userIDs
-        * @param       string          $field
-        * @param       integer         $packageID
-        * @return      array<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<integer>  $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 (file)
index 0000000..e3f03cb
--- /dev/null
@@ -0,0 +1,198 @@
+<?php
+namespace wcf\system\user\storage;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\SingletonFactory;
+use wcf\system\WCF;
+
+/**
+ * Handles the persistent user data storage.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2011 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.storage
+ * @category   Community Framework
+ */
+class UserStorageHandler extends SingletonFactory {
+       /**
+        * data cache
+        * @var array<array>
+        */
+       protected $cache = array();
+       
+       /**
+        * list of outdated data records
+        * @var array<array>
+        */
+       protected $resetFields = array();
+       
+       /**
+        * list of updated or new data records
+        * @var array<array>
+        */
+       protected $updateFields = array();
+       
+       /**
+        * Loads storage for a given set of users.
+        * 
+        * @param       array<integer>  $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<integer>  $userIDs
+        * @param       string          $field
+        * @param       integer         $packageID
+        * @return      array<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<integer>  $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
+                                               ));
+                                       }
+                               }
+                       }
+               }
+       }
+}