Fixed calculation of page menu item show order
authorAlexander Ebert <ebert@woltlab.com>
Sun, 26 May 2013 22:54:26 +0000 (00:54 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 26 May 2013 22:54:26 +0000 (00:54 +0200)
wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemAction.class.php
wcfsetup/install/files/lib/data/page/menu/item/PageMenuItemEditor.class.php
wcfsetup/install/files/lib/system/package/plugin/AbstractXMLPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/PageMenuPackageInstallationPlugin.class.php

index 86ee719224603ad0348e76013d884ee41d0463c9..1fb77609f9c8408ad21a3c0626ea87368c59a98a 100644 (file)
@@ -53,6 +53,9 @@ class PageMenuItemAction extends AbstractDatabaseObjectAction implements ISortab
                        $this->parameters['data']['packageID'] = PACKAGE_ID;
                }
                
+               // calculate show order
+               $this->parameters['data']['showOrder'] = PageMenuItemEditor::getShowOrder($this->parameters['data']['showOrder'], $this->parameters['data']['menuPosition'], $this->parameters['data']['parentMenuItem']);
+               
                $menuItem = parent::create();
                
                if ($menuItem->menuPosition == 'header') {
index 5e834d69107e2725628a3c12818cb550c631a5c3..8f946165cbb3919f71f723107383a55623661ecc 100644 (file)
@@ -21,16 +21,6 @@ class PageMenuItemEditor extends DatabaseObjectEditor implements IEditableCached
         */
        protected static $baseClass = 'wcf\data\page\menu\item\PageMenuItem';
        
-       /**
-        * @see wcf\data\IEditableObject::create()
-        */
-       public static function create(array $parameters = array()) {
-               // calculate show order
-               $parameters['showOrder'] = self::getShowOrder($parameters['showOrder'], $parameters['menuPosition'], $parameters['parentMenuItem']);
-               
-               return parent::create($parameters);
-       }
-       
        /**
         * @see wcf\data\IEditableObject::delete()
         */
@@ -105,7 +95,7 @@ class PageMenuItemEditor extends DatabaseObjectEditor implements IEditableCached
         * @param       string          $menuPosition
         * @return      integer
         */
-       protected static function getShowOrder($showOrder, $menuPosition, $parentMenuItem = '') {
+       public static function getShowOrder($showOrder, $menuPosition, $parentMenuItem = '') {
                if ($showOrder == 0) {
                        // get next number in row
                        $sql = "SELECT  MAX(showOrder) AS showOrder
index f262551be3640fc8dc9b3a6f0c55a50e611a4869..b0af1d24c3933740a20721b10b3cc3a0026cd632 100644 (file)
@@ -314,10 +314,6 @@ abstract class AbstractXMLPackageInstallationPlugin extends AbstractPackageInsta
         * @return      integer 
         */
        protected function getShowOrder($showOrder, $parentName = null, $columnName = null, $tableNameExtension = '') {
-               if ($this instanceof PageMenuPackageInstallationPlugin) {
-                       file_put_contents(WCF_DIR.'__pageMenu.log', "\tWARNING: Accessed AbstractXMLPackageInstallationPlugin::getShowOrder() (page menu pip has own method: " . (method_exists('wcf\system\package\plugin\PageMenuPackageInstallationPlugin', 'getShowOrder') ? 'yes' : 'no') . ")\n", FILE_APPEND);
-               }
-               
                if ($showOrder === null) {
                        // get greatest showOrder value
                        $conditions = new PreparedStatementConditionBuilder();
index 71a3c8976ca0cd35fa6c34242759cd158f9b7ca3..fc18abe5f0709124ddb80189e564d92dc4bad948 100644 (file)
@@ -85,10 +85,6 @@ class PageMenuPackageInstallationPlugin extends AbstractMenuPackageInstallationP
         * @return      integer
         */
        protected function getMenuItemPosition(array $data) {
-               file_put_contents(WCF_DIR.'__pageMenu.log', "Resolving menu position for '" . $data['menuItem'] . "' (" . $data['menuPosition'] . ") ...\n", FILE_APPEND);
-               file_put_contents(WCF_DIR.'__pageMenu.log', "  showOrder = ".($data['showOrder'] === null ? 'null' : $data['showOrder']) . "\n", FILE_APPEND);
-               file_put_contents(WCF_DIR.'__pageMenu.log', "  parentMenuItem = ". $data['parentMenuItem'] . "\n", FILE_APPEND);
-               
                if ($data['showOrder'] === null) {
                        // get greatest showOrder value
                        $conditions = new PreparedStatementConditionBuilder();
@@ -101,11 +97,9 @@ class PageMenuPackageInstallationPlugin extends AbstractMenuPackageInstallationP
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute($conditions->getParameters());
                        $maxShowOrder = $statement->fetchArray();
-                       //return (!$maxShowOrder) ? 1 : ($maxShowOrder['showOrder'] + 1);
-                       $showOrder = (!$maxShowOrder) ? 1 : ($maxShowOrder['showOrder'] + 1);
+                       return (!$maxShowOrder) ? 1 : ($maxShowOrder['showOrder'] + 1);
                }
                else {
-                       file_put_contents(WCF_DIR.'__pageMenu.log', "\tINCREASING SHOW ORDER\n", FILE_APPEND);
                        // increase all showOrder values which are >= $showOrder
                        $sql = "UPDATE  wcf".WCF_N."_".$this->tableName."
                                SET     showOrder = showOrder + 1
@@ -123,11 +117,7 @@ class PageMenuPackageInstallationPlugin extends AbstractMenuPackageInstallationP
                        $statement->execute($parameters);
                        
                        // return the wanted showOrder level
-                       //return $data['showOrder'];
-                       $showOrder = $data['showOrder'];
+                       return $data['showOrder'];
                }
-               
-               file_put_contents(WCF_DIR.'__pageMenu.log', "  calculated show order = ". $showOrder . "\n\n", FILE_APPEND);
-               return $showOrder;
        }
 }