From bb51f707e7782d363678fdc3c709b8a3d956c1b7 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 2 Jan 2014 20:14:11 +0100 Subject: [PATCH] Fixes double (and thus erroneous) update of category position --- .../data/category/CategoryAction.class.php | 23 +++++++++++++------ .../data/category/CategoryEditor.class.php | 20 ---------------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/wcfsetup/install/files/lib/data/category/CategoryAction.class.php b/wcfsetup/install/files/lib/data/category/CategoryAction.class.php index c9df30d317..5e37fab0f6 100644 --- a/wcfsetup/install/files/lib/data/category/CategoryAction.class.php +++ b/wcfsetup/install/files/lib/data/category/CategoryAction.class.php @@ -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++ )); } } diff --git a/wcfsetup/install/files/lib/data/category/CategoryEditor.class.php b/wcfsetup/install/files/lib/data/category/CategoryEditor.class.php index 7c5ee417b8..fe98d0e048 100644 --- a/wcfsetup/install/files/lib/data/category/CategoryEditor.class.php +++ b/wcfsetup/install/files/lib/data/category/CategoryEditor.class.php @@ -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. -- 2.20.1