From b477c338d572187b140bd0a270286c480a320191 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 15 Apr 2016 21:58:26 +0200 Subject: [PATCH] Added missing ISortableAction implementation --- .../data/menu/item/MenuItemAction.class.php | 69 ++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/data/menu/item/MenuItemAction.class.php b/wcfsetup/install/files/lib/data/menu/item/MenuItemAction.class.php index 1e820a031a..265f57aab3 100644 --- a/wcfsetup/install/files/lib/data/menu/item/MenuItemAction.class.php +++ b/wcfsetup/install/files/lib/data/menu/item/MenuItemAction.class.php @@ -1,8 +1,12 @@ update(array('isDisabled' => ($object->isDisabled) ? 0 : 1)); } } + + /** + * @inheritDoc + */ + public function validateUpdatePosition() { + WCF::getSession()->checkPermissions(['admin.content.cms.canManageMenu']); + + // validate menu id + $this->readInteger('menuID'); + $menu = new Menu($this->parameters['menuID']); + if (!$menu->menuID) { + throw new UserInputException('menuID'); + } + + // validate structure + if (!isset($this->parameters['data']) || !isset($this->parameters['data']['structure']) || !is_array($this->parameters['data']['structure'])) { + throw new UserInputException('structure'); + } + + $menuItemIDs = []; + foreach ($this->parameters['data']['structure'] as $menuItems) { + $menuItemIDs = array_merge($menuItemIDs, $menuItems); + } + + $menuItemList = new MenuItemList(); + $menuItemList->getConditionBuilder()->add('menu_item.itemID IN (?)', [$menuItemIDs]); + $menuItemList->getConditionBuilder()->add('menu_item.menuID = ?', [$this->parameters['menuID']]); + $menuItemList->readObjects(); + $menuItems = $menuItemList->getObjects(); + + if (count($menuItems) != count($menuItemIDs)) { + throw new UserInputException('structure'); + } + + foreach ($this->parameters['data']['structure'] as $parentItemID => $children) { + if ($parentItemID && !isset($menuItems[$parentItemID])) { + throw new UserInputException('structure'); + } + } + } + + /** + * @inheritDoc + */ + public function updatePosition() { + $sql = "UPDATE wcf".WCF_N."_menu_item + SET parentItemID = ?, + showOrder = ? + WHERE itemID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + + WCF::getDB()->beginTransaction(); + foreach ($this->parameters['data']['structure'] as $parentItemID => $children) { + foreach ($children as $showOrder => $menuItemID) { + $statement->execute([ + ($parentItemID ?: null), + $showOrder + 1, + $menuItemID + ]); + } + } + WCF::getDB()->commitTransaction(); + } } -- 2.20.1