From 8ae3d95c4e685eae3913e9f825f0945086dbcc2a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 9 Oct 2013 12:48:49 +0200 Subject: [PATCH] Fixed user storage reset/update race condition --- .../user/storage/UserStorageHandler.class.php | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php b/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php index 272eb74100..6b5f2de5c7 100644 --- a/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php @@ -102,9 +102,6 @@ class UserStorageHandler extends SingletonFactory { } $this->cache[$userID][$field] = $fieldValue; - - // flag key as outdated - self::reset(array($userID), $field); } /** @@ -165,18 +162,35 @@ class UserStorageHandler extends SingletonFactory { // insert data if (!empty($this->updateFields)) { - $sql = "INSERT INTO wcf".WCF_N."_user_storage - (userID, field, fieldValue) - VALUES (?, ?, ?)"; - $statement = WCF::getDB()->prepareStatement($sql); - + // exclude values which should be resetted foreach ($this->updateFields as $userID => $fieldValues) { - foreach ($fieldValues as $field => $fieldValue) { - $statement->execute(array( - $userID, - $field, - $fieldValue - )); + if (isset($this->resetFields[$userID])) { + foreach ($fieldValues as $field => $fieldValue) { + if (in_array($field, $this->resetFields[$userID])) { + unset($this->updateFields[$userID][$field]); + } + } + + if (empty($this->updateFields[$userID])) { + unset($this->updateFields[$userID]); + } + } + } + + if (!empty($this->updateFields)) { + $sql = "REPLACE INTO wcf".WCF_N."_user_storage + (userID, field, fieldValue) + VALUES (?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + + foreach ($this->updateFields as $userID => $fieldValues) { + foreach ($fieldValues as $field => $fieldValue) { + $statement->execute(array( + $userID, + $field, + $fieldValue + )); + } } } } -- 2.20.1