Fixes double (and thus erroneous) update of category position
authorMatthias Schmidt <gravatronics@live.com>
Thu, 2 Jan 2014 19:14:11 +0000 (20:14 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 2 Jan 2014 19:14:11 +0000 (20:14 +0100)
wcfsetup/install/files/lib/data/category/CategoryAction.class.php
wcfsetup/install/files/lib/data/category/CategoryEditor.class.php

index c9df30d3175fae761b94e83003e4e67355f1ca0e..5e37fab0f623f942dd26c212c0e2ab84aa06bd79 100644 (file)
@@ -79,22 +79,31 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ISortableAc
                }
        }
        
+       /**
+        * @see \wcf\data\AbstractDatabaseObjectAction::update()
+        */
+       public function update() {
+               // check if showOrder needs to be recalculated
+               if (count($this->objects) == 1 && isset($this->parameters['data']['parentCategoryID']) && isset($this->parameters['data']['showOrder'])) {
+                       if ($this->objects[0]->parentCategoryID != $this->parameters['data']['parentCategoryID'] || $this->objects[0]->showOrder != $this->parameters['data']['showOrder']) {
+                               $this->parameters['data']['showOrder'] = $this->objects[0]->updateShowOrder($this->parameters['data']['parentCategoryID'], $this->parameters['data']['showOrder']);
+                       }
+               }
+               
+               parent::update();
+       }
+       
        /**
         * @see \wcf\data\ISortableAction::updatePosition()
         */
        public function updatePosition() {
-               $showOrders = array();
-               
                WCF::getDB()->beginTransaction();
                foreach ($this->parameters['data']['structure'] as $parentCategoryID => $categoryIDs) {
-                       if (!isset($showOrders[$parentCategoryID])) {
-                               $showOrders[$parentCategoryID] = 1;
-                       }
-                       
+                       $showOrder = 1;
                        foreach ($categoryIDs as $categoryID) {
                                $this->objects[$categoryID]->update(array(
                                        'parentCategoryID' => $parentCategoryID ? $this->objects[$parentCategoryID]->categoryID : 0,
-                                       'showOrder' => $showOrders[$parentCategoryID]++
+                                       'showOrder' => $showOrder++
                                ));
                        }
                }
index 7c5ee417b8229130416d2f4ce6a261f2a128087e..fe98d0e0487968e2c6fb87c69e0e2994948c4d54 100644 (file)
@@ -22,26 +22,6 @@ class CategoryEditor extends DatabaseObjectEditor implements IEditableCachedObje
         */
        protected static $baseClass = 'wcf\data\category\Category';
        
-       /**
-        * @see \wcf\data\IEditableObject::update()
-        */
-       public function update(array $parameters = array()) {
-               // update show order
-               if (isset($parameters['parentCategoryID']) || isset($parameters['showOrder'])) {
-                       if (!isset($parameters['parentCategoryID'])) {
-                               $parameters['parentCategoryID'] = $this->parentCategoryID;
-                       }
-                       
-                       if (!isset($parameters['showOrder'])) {
-                               $parameters['showOrder'] = $this->showOrder;
-                       }
-                       
-                       $parameters['showOrder'] = $this->updateShowOrder($parameters['parentCategoryID'], $parameters['showOrder']);
-               }
-               
-               parent::update($parameters);
-       }
-       
        /**
         * Prepares the update of the show order of this category and return the
         * correct new show order.