From: Alexander Ebert Date: Mon, 30 Nov 2015 13:51:04 +0000 (+0100) Subject: Added PIP for menus X-Git-Tag: 3.0.0_Beta_1~2030^2~225 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3fbcee07d551d71777b6d044afb6f9448f9b2451;p=GitHub%2FWoltLab%2FWCF.git Added PIP for menus --- diff --git a/wcfsetup/install/files/lib/data/menu/MenuEditor.class.php b/wcfsetup/install/files/lib/data/menu/MenuEditor.class.php index ec2d8f1c9d..a7d166aa32 100644 --- a/wcfsetup/install/files/lib/data/menu/MenuEditor.class.php +++ b/wcfsetup/install/files/lib/data/menu/MenuEditor.class.php @@ -1,6 +1,8 @@ 1) { + $sql = "SELECT languageCategoryID + FROM wcf".WCF_N."_language_category + WHERE languageCategory = ?"; + $statement = WCF::getDB()->prepareStatement($sql, 1); + $statement->execute(['wcf.menu']); + $languageCategoryID = $statement->fetchSingleColumn(); + + $sql = "INSERT INTO wcf".WCF_N."_language_item + (languageID, languageItem, languageItemValue, languageItemOriginIsSystem, languageCategoryID, packageID) + VALUES (?, ?, ?, ?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + + WCF::getDB()->beginTransaction(); + foreach ($title as $languageCode => $value) { + $statement->execute([ + LanguageFactory::getInstance()->getLanguageByCode($languageCode)->languageID, + 'wcf.menu.menu' . $menu->menuID, + $value, + 1, + $languageCategoryID, + $menu->packageID + ]); + } + WCF::getDB()->commitTransaction(); + + $title = 'wcf.menu.menu' . $menu->menuID; + } + else { + $title = reset($title); + } + + //$menuEditor = new MenuItemEditor($menu); + $menuEditor = new self($menu); + $menuEditor->update(['title' => $title]); + } + + return $menu; + } } diff --git a/wcfsetup/install/files/lib/system/package/plugin/MenuPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/MenuPackageInstallationPlugin.class.php new file mode 100644 index 0000000000..9bb9e0f3dc --- /dev/null +++ b/wcfsetup/install/files/lib/system/package/plugin/MenuPackageInstallationPlugin.class.php @@ -0,0 +1,112 @@ + + * @package com.woltlab.wcf + * @subpackage acp.package.plugin + * @category Community Framework + */ +class MenuPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin { + /** + * @inheritDoc + */ + public $className = MenuEditor::class; + + /** + * @inheritDoc + */ + public $tagName = 'menu'; + + /** + * @inheritDoc + */ + protected function handleDelete(array $items) { + $sql = "DELETE FROM wcf".WCF_N."_menu + WHERE identifier = ? + AND packageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + + WCF::getDB()->beginTransaction(); + foreach ($items as $item) { + $statement->execute([ + $item['attributes']['identifier'], + $this->installation->getPackageID() + ]); + } + WCF::getDB()->commitTransaction(); + } + + /** + * @inheritDoc + * @throws SystemException + */ + protected function getElement(\DOMXPath $xpath, array &$elements, \DOMElement $element) { + $nodeValue = $element->nodeValue; + + if ($element->tagName === 'title') { + if (empty($element->getAttribute('language'))) { + throw new SystemException("Missing required attribute 'language' for menu '" . $element->parentNode->getAttribute('identifier') . "'"); + } + + // can occur multiple times using the `language` attribute + if (!isset($elements['title'])) $elements['title'] = []; + + $elements['title'][$element->getAttribute('language')] = $element->nodeValue; + } + else { + $elements[$element->tagName] = $nodeValue; + } + } + + /** + * @inheritDoc + */ + protected function prepareImport(array $data) { + return [ + 'identifier' => $data['attributes']['identifier'], + 'title' => $this->getI18nValues($data['elements']['title']), + 'originIsSystem' => 1 + ]; + } + + /** + * @inheritDoc + */ + protected function findExistingItem(array $data) { + $sql = "SELECT * + FROM wcf".WCF_N."_menu + WHERE identifier = ? + AND packageID = ?"; + $parameters = array( + $data['identifier'], + $this->installation->getPackageID() + ); + + return array( + 'sql' => $sql, + 'parameters' => $parameters + ); + } + + /** + * @inheritDoc + */ + protected function import(array $row, array $data) { + // updating menus is not supported because the only modifiable data is the + // title and overwriting it could conflict with user changes + if (!empty($row)) { + return new Menu(null, $row); + } + + return parent::import($row, $data); + } +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 910028319c..81dfc25975 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -2380,6 +2380,10 @@ Fehler sind beispielsweise: <item name="wcf.message.error.tooLong"><![CDATA[Ihre Nachricht ist zu lang. Es stehen maximal {#$maxTextLength} Zeichen zur Verfügung.]]></item> </category> + <category name="wcf.menu"> + <!-- category for menus and menu items --> + </category> + <category name="wcf.moderation"> <item name="wcf.moderation.assignedUser"><![CDATA[Zugewiesener Benutzer]]></item> <item name="wcf.moderation.assignedUser.change"><![CDATA[(Ändern)]]></item> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index fdb396d358..8b74c302ea 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -2377,6 +2377,10 @@ Errors are: <item name="wcf.message.error.tooLong"><![CDATA[Message is too long, must be below {#$maxTextLength} characters.]]></item> </category> + <category name="wcf.menu"> + <!-- category for menus and menu items --> + </category> + <category name="wcf.moderation"> <item name="wcf.moderation.assignedUser"><![CDATA[Assigned User]]></item> <item name="wcf.moderation.assignedUser.change"><![CDATA[(Change)]]></item>