From f3a5bde184c26e836473f4617c3887b4b5ce20ae Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 25 Jan 2013 02:29:56 +0100 Subject: [PATCH] Fixed show order calculation --- .../menu/item/PageMenuItemEditor.class.php | 85 +++---------------- ...ageMenuPackageInstallationPlugin.class.php | 7 ++ 2 files changed, 21 insertions(+), 71 deletions(-) diff --git a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemEditor.class.php b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemEditor.class.php index 1603d37425..089a1df49e 100644 --- a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemEditor.class.php +++ b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemEditor.class.php @@ -28,7 +28,7 @@ class PageMenuItemEditor extends DatabaseObjectEditor implements IEditableCached */ public static function create(array $parameters = array()) { // calculate show order - $parameters['showOrder'] = self::getShowOrder($parameters['showOrder'], $parameters['menuPosition']); + $parameters['showOrder'] = self::getShowOrder($parameters['showOrder'], $parameters['menuPosition'], $parameters['parentMenuItem']); return parent::create($parameters); } @@ -39,9 +39,6 @@ class PageMenuItemEditor extends DatabaseObjectEditor implements IEditableCached * @todo Handle language id and update related language item */ public function update(array $parameters = array()) { - if (isset($parameters['menuPosition']) && isset($parameters['showOrder'])) { - $this->updateShowOrder($parameters['showOrder'], $parameters['menuPosition']); - } parent::update($parameters); } @@ -111,66 +108,6 @@ class PageMenuItemEditor extends DatabaseObjectEditor implements IEditableCached )); } - /** - * Updates show order for current menu item. - * - * @param integer $showOrder - * @param string $menuPosition - */ - protected function updateShowOrder($showOrder, $menuPosition) { - if ($menuPosition == $this->menuPosition) { - if ($this->showOrder != $showOrder) { - if ($showOrder < $this->showOrder) { - $sql = "UPDATE wcf".WCF_N."_page_menu_item - SET showOrder = showOrder + 1 - WHERE showOrder >= ? - AND showOrder < ? - AND menuPosition = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array( - $showOrder, - $this->showOrder, - $menuPosition - )); - } - else if ($showOrder > $this->showOrder) { - $sql = "UPDATE wcf".WCF_N."_page_menu_item - SET showOrder = showOrder - 1 - WHERE showOrder <= ? - AND showOrder > ? - AND menuPosition = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array( - $showOrder, - $this->showOrder, - $menuPosition - )); - } - } - } - else { - $sql = "UPDATE wcf".WCF_N."_page_menu_item - SET showOrder = showOrder - 1 - WHERE showOrder >= ? - AND menuPosition = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array( - $this->showOrder, - $this->menuPosition - )); - - $sql = "UPDATE wcf".WCF_N."_page_menu_item - SET showOrder = showOrder + 1 - WHERE showOrder >= ? - AND menuPosition = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array( - $showOrder, - $menuPosition - )); - } - } - /** * Returns show order for a new menu item. * @@ -178,14 +115,18 @@ class PageMenuItemEditor extends DatabaseObjectEditor implements IEditableCached * @param string $menuPosition * @return integer */ - protected static function getShowOrder($showOrder, $menuPosition) { + protected static function getShowOrder($showOrder, $menuPosition, $parentMenuItem = '') { if ($showOrder == 0) { // get next number in row $sql = "SELECT MAX(showOrder) AS showOrder FROM wcf".WCF_N."_page_menu_item - WHERE menuPosition = ?"; + WHERE parentMenuItem = ? + AND menuPosition = ?"; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($menuPosition)); + $statement->execute(array( + $parentMenuItem, + $menuPosition + )); $row = $statement->fetchArray(); if (!empty($row)) $showOrder = intval($row['showOrder']) + 1; else $showOrder = 1; @@ -193,12 +134,14 @@ class PageMenuItemEditor extends DatabaseObjectEditor implements IEditableCached else { $sql = "UPDATE wcf".WCF_N."_page_menu_item SET showOrder = showOrder + 1 - WHERE showOrder >= ? - AND menuPosition = ?"; + WHERE parentMenuItem = ? + AND menuPosition = ? + AND showOrder >= ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array( - $showOrder, - $menuPosition + $parentMenuItem, + $menuPosition, + $showOrder )); } diff --git a/wcfsetup/install/files/lib/system/package/plugin/PageMenuPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/PageMenuPackageInstallationPlugin.class.php index f3b9cac00e..cd1037e858 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/PageMenuPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/PageMenuPackageInstallationPlugin.class.php @@ -47,4 +47,11 @@ class PageMenuPackageInstallationPlugin extends AbstractMenuPackageInstallationP protected function cleanup() { PageMenuItemEditor::updateLandingPage(); } + + /** + * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::getShowOrder() + */ + protected function getShowOrder($showOrder, $parentName = null, $columnName = null, $tableNameExtension = '') { + return $showOrder; + } } -- 2.20.1