Adding $skipCache to User::getGroupIDs()
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 8 Aug 2012 16:39:22 +0000 (18:39 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 8 Aug 2012 16:39:22 +0000 (18:39 +0200)
Closes #752

wcfsetup/install/files/lib/acp/form/UserEditForm.class.php
wcfsetup/install/files/lib/data/user/User.class.php

index eb9f95f8fdd5297ba9a08badc413c5fdb2c19378..50311f40cffd3f63faba60b868cf4d8f2492d8f3 100755 (executable)
@@ -119,7 +119,7 @@ class UserEditForm extends UserAddForm {
        protected function readDefaultValues() {
                $this->username = $this->user->username;
                $this->email = $this->confirmEmail = $this->user->email;
-               $this->groupIDs = $this->user->getGroupIDs();
+               $this->groupIDs = $this->user->getGroupIDs(true);
                $this->languageID = $this->user->languageID;
        }
        
index ffcaa962aafc07e878993c000c19867ac692ecbf..b46ea2aa5ba3f0606328e167ef0cc3a72a1c600d 100644 (file)
@@ -103,11 +103,12 @@ final class User extends DatabaseObject implements IRouteController {
        
        /**
         * Returns an array with all the groups in which the actual user is a member.
-        *
+        * 
+        * @param       boolean         $skipCache
         * @return      array           $groupIDs
         */
-       public function getGroupIDs() {
-               if ($this->groupIDs === null) {
+       public function getGroupIDs($skipCache = false) {
+               if ($this->groupIDs === null || $skipCache) {
                        if (!$this->userID) {
                                // user is a guest, use default guest group
                                $this->groupIDs = UserGroup::getGroupIDsByType(array(UserGroup::GUESTS, UserGroup::EVERYONE));
@@ -120,7 +121,7 @@ final class User extends DatabaseObject implements IRouteController {
                                $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'groupIDs');
                                
                                // cache does not exist or is outdated
-                               if ($data[$this->userID] === null) {
+                               if ($data[$this->userID] === null || $skipCache) {
                                        $this->groupIDs = array();
                                        $sql = "SELECT  groupID
                                                FROM    wcf".WCF_N."_user_to_group
@@ -132,7 +133,9 @@ final class User extends DatabaseObject implements IRouteController {
                                        }
                                        
                                        // update storage data
-                                       UserStorageHandler::getInstance()->update($this->userID, 'groupIDs', serialize($this->groupIDs), 1);
+                                       if (!$skipCache) {
+                                               UserStorageHandler::getInstance()->update($this->userID, 'groupIDs', serialize($this->groupIDs), 1);
+                                       }
                                }
                                else {
                                        $this->groupIDs = unserialize($data[$this->userID]);
@@ -312,7 +315,7 @@ final class User extends DatabaseObject implements IRouteController {
         * 
         * @param       array           $userIDs
         * @return      array<User>
-        */     
+        */
        public static function getUsers(array $userIDs) {
                $userList = new UserList();
                $userList->getConditionBuilder()->add("user_table.userID IN (?)", array($userIDs));
@@ -325,7 +328,7 @@ final class User extends DatabaseObject implements IRouteController {
         * Returns username.
         * 
         * @return      string
-        */     
+        */
        public function __toString() {
                return $this->username;
        }