From: Alexander Ebert Date: Wed, 7 Sep 2011 13:20:40 +0000 (+0200) Subject: Added PIPs for clipboard API X-Git-Tag: 2.0.0_Beta_1~1765^2~54 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0bb412010d108f882a5da4fc0da625e96fe488ee;p=GitHub%2FWoltLab%2FWCF.git Added PIPs for clipboard API Modified AbstractXMLPackageInstallationPlugin to support nested elements with own handlers as required by ClipboardActionPackageInstallationPlugin. --- 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 6b1a445ad2..bd63e7c1fd 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/AbstractXMLPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/AbstractXMLPackageInstallationPlugin.class.php @@ -103,7 +103,7 @@ abstract class AbstractXMLPackageInstallationPlugin extends AbstractPackageInsta // fetch child elements $items = $xpath->query('child::*', $element); foreach ($items as $item) { - $data['elements'][$item->tagName] = $item->nodeValue; + $this->getElement($xpath, $data['elements'], $item); } // include node value if item does not contain any child elements (eg. pip) @@ -139,18 +139,30 @@ abstract class AbstractXMLPackageInstallationPlugin extends AbstractPackageInsta $this->postImport(); } + /** + * Sets element value from XPath. + * + * @param \DOMXPath $xpath + * @param array $elements + * @param \DOMElement $element + */ + protected function getElement(\DOMXpath $xpath, array &$elements, \DOMElement $element) { + $elements[$element->tagName] = $element->nodeValue; + } + /** * Inserts or updates new items. * * @param array $row * @param array $data + * @return wcf\data\IStorableObject */ protected function import(array $row, array $data) { if (empty($row)) { // create new item $this->prepareCreate($data); - call_user_func(array($this->className, 'create'), $data); + return call_user_func(array($this->className, 'create'), $data); } else { // update existing item @@ -158,6 +170,8 @@ abstract class AbstractXMLPackageInstallationPlugin extends AbstractPackageInsta $itemEditor = new $this->className(new $baseClass(null, $row)); $itemEditor->update($data); + + return $itemEditor; } } @@ -276,12 +290,7 @@ abstract class AbstractXMLPackageInstallationPlugin extends AbstractPackageInsta $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); $maxShowOrder = $statement->fetchArray(); - if (is_array($maxShowOrder) && isset($maxShowOrder['showOrder'])) { - return $maxShowOrder['showOrder'] + 1; - } - else { - return 1; - } + return (!$maxShowOrder) ? 1 : ($maxShowOrder + 1); } else { // increase all showOrder values which are >= $showOrder diff --git a/wcfsetup/install/files/lib/system/package/plugin/ClipboardActionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/ClipboardActionPackageInstallationPlugin.class.php new file mode 100644 index 0000000000..340fdd76e2 --- /dev/null +++ b/wcfsetup/install/files/lib/system/package/plugin/ClipboardActionPackageInstallationPlugin.class.php @@ -0,0 +1,124 @@ + + * @package com.woltlab.wcf + * @subpackage acp.package.plugin + * @category Community Framework + */ +class ClipboardActionInstallationPlugin extends AbstractXMLPackageInstallationPlugin { + /** + * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$className + */ + public $className = 'wcf\data\clipboard\action\ClipboardActionEditor'; + + /** + * @see wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName + */ + public $tableName = 'clipboard_action'; + + /** + * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$tagName + */ + public $tagName = 'action'; + + /** + * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::handleDelete() + */ + protected function handleDelete(array $items) { + $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName." + WHERE actionName = ? + AND packageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + foreach ($items as $item) { + $statement->execute(array( + $item['attributes']['name'], + $this->installation->getPackageID() + )); + } + } + + /** + * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::getElement() + */ + protected function getElement(\DOMXPath $xpath, array &$elements, \DOMElement $element) { + $nodeValue = $element->nodeValue; + + // read pages + if ($element->tagName == 'pages') { + $nodeValue = array(); + + $pages = $xpath->query('child::ns:page', $element); + foreach ($pages as $page) { + $nodeValue[] = $page->nodeValue; + } + } + + $elements[$element->tagName] = $nodeValue; + } + + /** + * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::prepareImport() + */ + protected function prepareImport(array $data) { + $showOrder = (isset($data['elements']['showorder'])) ? intval($data['elements']['showorder']) : null; + $showOrder = $this->getShowOrder($showOrder); + + return array( + 'actionClassName' => $data['elements']['actionClassName'], + 'actionName' => $data['attributes']['name'], + 'showOrder' => $showOrder + ); + } + + /** + * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::findExistingItem() + */ + protected function findExistingItem(array $data) { + $sql = "SELECT * + FROM wcf".WCF_N."_".$this->tableName." + WHERE actionName = ? + AND packageID = ?"; + $parameters = array( + $data['actionName'], + $this->installation->getPackageID() + ); + + return array( + 'sql' => $sql, + 'parameters' => $parameters + ); + } + + /** + * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::import() + */ + protected function import(array $row, array $data) { + $object = parent::import($row, $data); + + // clear pages + $sql = "DELETE FROM wcf".WCF_N."_clipboard_page + WHERE packageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($this->installation->getPackageID())); + + // insert pages + $sql = "INSERT INTO wcf".WCF_N."_clipboard_page + (pageClassName, packageID, actionID) + VALUES (?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + foreach ($data['pages'] as $pageClassName) { + $statement->execute(array( + $pageClassName, + $this->installation->getPackageID(), + $object->actionID + )); + } + } +} diff --git a/wcfsetup/install/files/lib/system/package/plugin/ClipboardItemTypePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/ClipboardItemTypePackageInstallationPlugin.class.php new file mode 100644 index 0000000000..b383f973dc --- /dev/null +++ b/wcfsetup/install/files/lib/system/package/plugin/ClipboardItemTypePackageInstallationPlugin.class.php @@ -0,0 +1,75 @@ + + * @package com.woltlab.wcf + * @subpackage acp.package.plugin + * @category Community Framework + */ +class ClipboardItemTypeInstallationPlugin extends AbstractXMLPackageInstallationPlugin { + /** + * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$className + */ + public $className = 'wcf\data\clipboard\item\type\ClipboardItemTypeEditor'; + + /** + * @see wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName + */ + public $tableName = 'clipboard_item_type'; + + /** + * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$tagName + */ + public $tagName = 'type'; + + /** + * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::handleDelete() + */ + protected function handleDelete(array $items) { + $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName." + WHERE typeName = ? + AND packageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + foreach ($items as $item) { + $statement->execute(array( + $item['attributes']['name'], + $this->installation->getPackageID() + )); + } + } + + /** + * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::prepareImport() + */ + protected function prepareImport(array $data) { + return array( + 'listClassName' => $data['elements']['listclassname'], + 'typeName' => $data['attributes']['name'] + ); + } + + /** + * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::findExistingItem() + */ + protected function findExistingItem(array $data) { + $sql = "SELECT * + FROM wcf".WCF_N."_".$this->tableName." + WHERE typeName = ? + AND packageID = ?"; + $parameters = array( + $data['typeName'], + $this->installation->getPackageID() + ); + + return array( + 'sql' => $sql, + 'parameters' => $parameters + ); + } +}