Use transaction for updates to avoid problems with a race condition
authorTim Düsterhus <timwolla@arcor.de>
Sat, 21 Jan 2012 18:37:37 +0000 (19:37 +0100)
committerTim Düsterhus <timwolla@arcor.de>
Sat, 21 Jan 2012 18:37:37 +0000 (19:37 +0100)
wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php

index 469f2bb2ec0b7e3064d156506af13ffe073a4bd7..388821558fa13f4c6f0fbc87e1f891fc52f24c07 100644 (file)
@@ -155,6 +155,7 @@ class UserStorageHandler extends SingletonFactory {
         * Removes and inserts data records on shutdown.
         */
        public function shutdown() {
+               WCF::getDB()->beginTransaction();
                // remove outdated entries
                if (count($this->resetFields)) {
                        $sql = "DELETE FROM     wcf".WCF_N."_user_storage
@@ -166,7 +167,7 @@ class UserStorageHandler extends SingletonFactory {
                        foreach ($this->resetFields as $userID => $data) {
                                foreach ($data as $packageID => $fields) {
                                        foreach ($fields as $field) {
-                                               $statement->execute(array(
+                                               $statement->executeUnbuffered(array(
                                                        $userID,
                                                        $field,
                                                        $packageID
@@ -186,7 +187,7 @@ class UserStorageHandler extends SingletonFactory {
                        foreach ($this->updateFields as $userID => $data) {
                                foreach ($data as $packageID => $fieldValues) {
                                        foreach ($fieldValues as $field => $fieldValue) {
-                                               $statement->execute(array(
+                                               $statement->executeUnbuffered(array(
                                                        $userID,
                                                        $field,
                                                        $fieldValue,
@@ -196,6 +197,7 @@ class UserStorageHandler extends SingletonFactory {
                                }
                        }
                }
+               WCF::getDB()->commitTransaction();
                
                $this->resetFields = $this->updateFields = array();
        }