From d3db5e744d3f02c4f9cdc00178d89e866bf2503f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 8 Aug 2012 18:39:22 +0200 Subject: [PATCH] Adding $skipCache to User::getGroupIDs() Closes #752 --- .../files/lib/acp/form/UserEditForm.class.php | 2 +- .../install/files/lib/data/user/User.class.php | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php b/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php index eb9f95f8fd..50311f40cf 100755 --- a/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php @@ -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; } diff --git a/wcfsetup/install/files/lib/data/user/User.class.php b/wcfsetup/install/files/lib/data/user/User.class.php index ffcaa962aa..b46ea2aa5b 100644 --- a/wcfsetup/install/files/lib/data/user/User.class.php +++ b/wcfsetup/install/files/lib/data/user/User.class.php @@ -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 - */ + */ 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; } -- 2.20.1