From 0278441b80949f8adc940f3864cc8fc2623a0c27 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 16 May 2013 23:01:51 +0200 Subject: [PATCH] Attempt to fix show order for page menu items on create/update Fixes #1120 Fixes #1193 --- ...actMenuPackageInstallationPlugin.class.php | 2 +- ...ractXMLPackageInstallationPlugin.class.php | 4 +- ...ageMenuPackageInstallationPlugin.class.php | 66 +++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php index 99dbf0a7e0..d1777f3b74 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/AbstractMenuPackageInstallationPlugin.class.php @@ -7,7 +7,7 @@ use wcf\system\WCF; * Abstract implementation of a package installation plugin for menu items. * * @author Alexander Ebert - * @copyright 2001-2012 WoltLab GmbH + * @copyright 2001-2013 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.package.plugin diff --git a/wcfsetup/install/files/lib/system/package/plugin/AbstractXMLPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/AbstractXMLPackageInstallationPlugin.class.php index 6862f462b7..b0af1d24c3 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/AbstractXMLPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/AbstractXMLPackageInstallationPlugin.class.php @@ -10,8 +10,8 @@ use wcf\util\XML; /** * Abstract implementation of a package installation plugin using a XML file. * - * @author Marcel Werk - * @copyright 2001-2012 WoltLab GmbH + * @author Alexander Ebert + * @copyright 2001-2013 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.package.plugin 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 cd1037e858..dab7b2f055 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/PageMenuPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/PageMenuPackageInstallationPlugin.class.php @@ -1,7 +1,9 @@ getMenuItemPosition($data); + } + } + else { + $data['showOrder'] = $this->getMenuItemPosition($data); + } + + parent::import($row, $data); + } + /** * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::getShowOrder() */ protected function getShowOrder($showOrder, $parentName = null, $columnName = null, $tableNameExtension = '') { + // will be recalculated anyway return $showOrder; } + + /** + * Returns menu item position. + * + * @param array $data + * @return integer + */ + protected function getMenuItemPosition(array $data) { + if ($data['showOrder'] === null) { + // get greatest showOrder value + $conditions = new PreparedStatementConditionBuilder(); + $conditions->add("menuPosition = ?", array($data['menuPosition'])); + if ($data['parentMenuItem']) $conditions->add("parentMenuItem = ?", array($data['parentMenuItem'])); + + $sql = "SELECT MAX(showOrder) AS showOrder + FROM wcf".WCF_N."_".$this->tableName." + ".$conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditions->getParameters()); + $maxShowOrder = $statement->fetchArray(); + return (!$maxShowOrder) ? 1 : ($maxShowOrder['showOrder'] + 1); + } + else { + // increase all showOrder values which are >= $showOrder + $sql = "UPDATE wcf".WCF_N."_".$this->tableName." + SET showOrder = showOrder + 1 + WHERE showOrder >= ? + AND menuPosition = ? + ".($data['parentMenuItem'] ? "AND parentMenuItem = ?" : ""); + $statement = WCF::getDB()->prepareStatement($sql); + + $data = array( + $data['showOrder'], + $data['menuPosition'] + ); + if ($data['parentMenuItem']) $data[] = $data['parentMenuItem']; + + $statement->execute($data); + + // return the wanted showOrder level + return $data['showOrder']; + } + } } -- 2.20.1