From 26ae9f271fe453215b804ca187cb280a403e744f Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 28 Jul 2019 15:17:59 +0200 Subject: [PATCH] Append (instead of prepend) menu item during page creation See #2998 --- .../files/lib/acp/form/PageAddForm.class.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php b/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php index 63d4cc71f4..ce2b54da9d 100644 --- a/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php @@ -17,6 +17,7 @@ use wcf\data\page\PageNodeTree; use wcf\data\smiley\SmileyCache; use wcf\form\AbstractForm; use wcf\system\acl\simple\SimpleAclHandler; +use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\IllegalLinkException; use wcf\system\exception\UserInputException; use wcf\system\html\input\HtmlInputProcessor; @@ -589,12 +590,29 @@ class PageAddForm extends AbstractForm { // add page to main menu if ($this->addPageToMainMenu) { + // select maximum showOrder value so that new menu item will be appened + $conditionBuilder = new PreparedStatementConditionBuilder(); + if ($this->parentMenuItemID) { + $conditionBuilder->add('parentItemID = ?', [$this->parentMenuItemID]); + } + else { + $conditionBuilder->add('parentItemID IS NULL'); + } + + $sql = "SELECT MAX(showOrder) + FROM wcf" . WCF_N . "_menu_item + " . $conditionBuilder; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditionBuilder->getParameters()); + $maxShowOrder = $statement->fetchSingleColumn() ?? 0; + $menuItemAction = new MenuItemAction([], 'create', ['data' => [ 'isDisabled' => $this->isDisabled ? 1 : 0, 'title' => (!$this->isMultilingual ? $this->title[0] : ''), 'pageID' => $page->pageID, 'menuID' => MenuCache::getInstance()->getMainMenuID(), 'parentItemID' => $this->parentMenuItemID, + 'showOrder' => $maxShowOrder + 1, 'identifier' => StringUtil::getRandomID(), 'packageID' => 1 ]]); -- 2.20.1