From: Matthias Schmidt Date: Tue, 24 Feb 2015 17:35:19 +0000 (+0100) Subject: Add category API to react to changed parent category X-Git-Tag: 2.1.0~33^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=af55e97203ac29ed8abe87c0169746a3cefceec5;p=GitHub%2FWoltLab%2FWCF.git Add category API to react to changed parent category --- diff --git a/wcfsetup/install/files/lib/data/category/CategoryAction.class.php b/wcfsetup/install/files/lib/data/category/CategoryAction.class.php index 74be682273..547e4cdf2d 100644 --- a/wcfsetup/install/files/lib/data/category/CategoryAction.class.php +++ b/wcfsetup/install/files/lib/data/category/CategoryAction.class.php @@ -15,7 +15,7 @@ use wcf\system\WCF; * Executes category-related actions. * * @author Matthias Schmidt - * @copyright 2001-2014 WoltLab GmbH + * @copyright 2001-2015 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage data.category @@ -91,16 +91,53 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ISortableAc } parent::update(); + + if ($this->parameters['data']['parentCategoryID']) { + $objectType = null; + $parentUpdates = array(); + + foreach ($this->objects as $category) { + if ($objectType === null) { + $objectType = $category->getObjectType(); + } + + if ($category->parentCategoryID != $this->parameters['data']['parentCategoryID']) { + $parentUpdates[$categoryID] = array( + 'oldParentCategoryID' => $category->parentCategoryID, + 'newParentCategoryID' => $this->parameters['data']['parentCategoryID'] + ); + } + } + + if (!empty($parentUpdates)) { + $objectType->getProcessor()->changedParentCategories($parentUpdates); + } + } } /** * @see \wcf\data\ISortableAction::updatePosition() */ public function updatePosition() { + $objectType = null; + $parentUpdates = array(); + WCF::getDB()->beginTransaction(); foreach ($this->parameters['data']['structure'] as $parentCategoryID => $categoryIDs) { $showOrder = 1; foreach ($categoryIDs as $categoryID) { + $category = CategoryHandler::getInstance()->getCategory($categoryID); + if ($objectType === null) { + $objectType = $category->getObjectType(); + } + + if ($category->parentCategoryID != $parentCategoryID) { + $parentUpdates[$categoryID] = array( + 'oldParentCategoryID' => $category->parentCategoryID, + 'newParentCategoryID' => $parentCategoryID + ); + } + $this->objects[$categoryID]->update(array( 'parentCategoryID' => $parentCategoryID ? $this->objects[$parentCategoryID]->categoryID : 0, 'showOrder' => $showOrder++ @@ -108,6 +145,10 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ISortableAc } } WCF::getDB()->commitTransaction(); + + if (!empty($parentUpdates)) { + $objectType->getProcessor()->changedParentCategories($parentUpdates); + } } /** diff --git a/wcfsetup/install/files/lib/system/category/AbstractCategoryType.class.php b/wcfsetup/install/files/lib/system/category/AbstractCategoryType.class.php index b4e17d9c66..0f4d014296 100644 --- a/wcfsetup/install/files/lib/system/category/AbstractCategoryType.class.php +++ b/wcfsetup/install/files/lib/system/category/AbstractCategoryType.class.php @@ -9,7 +9,7 @@ use wcf\system\WCF; * Abstract implementation of a category type. * * @author Matthias Schmidt - * @copyright 2001-2014 WoltLab GmbH + * @copyright 2001-2015 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.category @@ -98,6 +98,13 @@ abstract class AbstractCategoryType extends SingletonFactory implements ICategor return WCF::getSession()->getPermission($this->permissionPrefix.'.canEditCategory'); } + /** + * @see \wcf\system\category\ICategoryType::changedParentCategories() + */ + public function changedParentCategories(array $categoryData) { + // does nothing + } + /** * @see \wcf\system\category\ICategoryType::forceDescription() */ diff --git a/wcfsetup/install/files/lib/system/category/ICategoryType.class.php b/wcfsetup/install/files/lib/system/category/ICategoryType.class.php index 04e9a12fe3..2ca451a5e7 100644 --- a/wcfsetup/install/files/lib/system/category/ICategoryType.class.php +++ b/wcfsetup/install/files/lib/system/category/ICategoryType.class.php @@ -6,7 +6,7 @@ use wcf\data\category\CategoryEditor; * Every category type has to implement this interface. * * @author Matthias Schmidt - * @copyright 2001-2014 WoltLab GmbH + * @copyright 2001-2015 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.category @@ -41,6 +41,23 @@ interface ICategoryType { */ public function canEditCategory(); + /** + * Is called after categories were assigned different parent categories. + * + * Array structure: + * [ + * categoryID => [ + * oldParentCategoryID => 1, + * newParentCategoryID => 2 + * ], + * categoryID => [ + * oldParentCategoryID => null, + * newParentCategoryID => 2 + * ], + * ] + */ + public function changedParentCategories(array $categoryData); + /** * Returns true if a category of this type may have no empty description. *