Added PIPs for clipboard API
authorAlexander Ebert <ebert@woltlab.com>
Wed, 7 Sep 2011 13:20:40 +0000 (15:20 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 7 Sep 2011 13:20:40 +0000 (15:20 +0200)
Modified AbstractXMLPackageInstallationPlugin to support nested elements with own handlers as required by ClipboardActionPackageInstallationPlugin.

wcfsetup/install/files/lib/system/package/plugin/AbstractXMLPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/ClipboardActionPackageInstallationPlugin.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/package/plugin/ClipboardItemTypePackageInstallationPlugin.class.php [new file with mode: 0644]

index 6b1a445ad2f0035837dea172eb4a9da494a55b19..bd63e7c1fd8e236587bc45200b9a3b3e5d47a9b1 100644 (file)
@@ -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 (file)
index 0000000..340fdd7
--- /dev/null
@@ -0,0 +1,124 @@
+<?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
+                       ));
+               }
+       }
+}
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 (file)
index 0000000..b383f97
--- /dev/null
@@ -0,0 +1,75 @@
+<?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
+               );
+       }
+}