Modified AbstractXMLPackageInstallationPlugin to support nested elements with own handlers as required by ClipboardActionPackageInstallationPlugin.
// 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)
$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
$itemEditor = new $this->className(new $baseClass(null, $row));
$itemEditor->update($data);
+
+ return $itemEditor;
}
}
$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
--- /dev/null
+<?php
+namespace wcf\system\package\plugin;
+use wcf\system\WCF;
+
+/**
+ * This PIP installs, updates or deletes clipboard actions.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2011 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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
+ ));
+ }
+ }
+}
--- /dev/null
+<?php
+namespace wcf\system\package\plugin;
+use wcf\system\WCF;
+
+/**
+ * This PIP installs, updates or deletes clipboard item types.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2011 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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
+ );
+ }
+}