Clipboard API
authorAlexander Ebert <ebert@woltlab.com>
Wed, 7 Sep 2011 13:35:20 +0000 (15:35 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 7 Sep 2011 13:35:20 +0000 (15:35 +0200)
Renamed column according to PIP, added missing (foreign) keys and cache builders.

wcfsetup/install/files/lib/system/cache/builder/ClipboardActionCacheBuilder.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/cache/builder/ClipboardItemTypeCacheBuilder.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/cache/builder/ClipboardPageCacheBuilder.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php
wcfsetup/setup/db/install.sql

diff --git a/wcfsetup/install/files/lib/system/cache/builder/ClipboardActionCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/ClipboardActionCacheBuilder.class.php
new file mode 100644 (file)
index 0000000..e86c1ed
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+namespace wcf\system\cache\builder;
+use wcf\data\clipboard\action\ClipboardActionList;
+use wcf\system\package\PackageDependencyHandler;
+
+/**
+ * Caches 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 system.cache.builder
+ * @category   Community Framework
+ */
+class ClipboardActionCacheBuilder implements ICacheBuilder {
+       /**
+        * @see wcf\system\cache\ICacheBuilder::getData()
+        */
+       public function getData(array $cacheResource) {
+               $actionList = new ClipboardActionList();
+               $actionList->getConditionBuilder()->add("packageID IN (?)", array(PackageDependencyHandler::getDependencies()));
+               $actionList->sqlLimit = 0;
+               $actionList->readObjects();
+               
+               return $actionList->getObjects();
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/cache/builder/ClipboardItemTypeCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/ClipboardItemTypeCacheBuilder.class.php
new file mode 100644 (file)
index 0000000..a7bc8d5
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+namespace wcf\system\cache\builder;
+use wcf\data\clipboard\item\type\ClipboardItemTypeList;
+use wcf\system\package\PackageDependencyHandler;
+
+/**
+ * Caches 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 system.cache.builder
+ * @category   Community Framework
+ */
+class ClipboardItemTypeCacheBuilder implements ICacheBuilder {
+       /**
+        * @see wcf\system\cache\ICacheBuilder::getData()
+        */
+       public function getData(array $cacheResource) {
+               $typeList = new ClipboardItemTypeList();
+               $typeList->getConditionBuilder()->add("clipboard_item_type.packageID IN (?)", array(PackageDependencyHandler::getDependencies()));
+               $typeList->sqlLimit = 0;
+               $typeList->readObjects();
+               
+               $data = array(
+                       'typeNames' => array(),
+                       'types' => array()
+               );
+               foreach ($typeList->getObjects() as $typeID => $type) {
+                       $data['typeNames'][$type->typeName] = $typeID;
+                       $data['types'][$typeID] = $type;
+               }
+               
+               return $data;
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/cache/builder/ClipboardPageCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/ClipboardPageCacheBuilder.class.php
new file mode 100644 (file)
index 0000000..1d752fa
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+namespace wcf\system\cache\builder;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\package\PackageDependencyHandler;
+use wcf\system\WCF;
+
+/**
+ * Caches clipboard pages.
+ * 
+ * @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 system.cache.builder
+ * @category   Community Framework
+ */
+class ClipboardPageCacheBuilder implements ICacheBuilder {
+       /**
+        * @see wcf\system\cache\ICacheBuilder::getData()
+        */
+       public function getData(array $cacheResource) {
+               $conditions = new PreparedStatementConditionBuilder();
+               $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getDependencies()));
+               
+               $sql = "SELECT  pageClassName, actionID
+                       FROM    wcf".WCF_N."_clipboard_page
+                       ".$conditions;
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute($conditions->getParameters());
+               
+               $data = array();
+               while ($row = $statement->fetchArray()) {
+                       if (!isset($data[$row['pageClassName']])) {
+                               $data[$row['pageClassName']] = array();
+                       }
+                       
+                       $data[$row['pageClassName']][] = $row['actionID'];
+               }
+               
+               return $data;
+       }
+}
index 0cfa703ce0ad7733c51d6618945c31201470ce81..21779bdc114181edf368a1de761a88059af12c72 100644 (file)
@@ -166,7 +166,7 @@ class ClipboardHandler extends SingletonFactory {
                        
                        if (!isset($data[$type->typeName])) {
                                $data[$type->typeName] = array(
-                                       'className' => $type->className,
+                                       'className' => $type->listClassName,
                                        'objectIDs' => array()
                                );
                        }
@@ -196,8 +196,7 @@ class ClipboardHandler extends SingletonFactory {
         */
        public function getEditorItems($page) {
                // ignore unknown pages
-               if (!isset($this->pageCache[$page])) die('page '.$page.' is unknown');
-                       #return null;
+               if (!isset($this->pageCache[$page])) return null;
                
                // get objects
                $objects = $this->getMarkedItems();
index 70378768409505e3e1db5fc71a0353240bbfe9cf..10e2458e54434fe19ba948ae8c6e92b9aefdc52f 100644 (file)
@@ -102,7 +102,8 @@ CREATE TABLE wcf1_clipboard_action (
        packageID INT(10) NOT NULL DEFAULT 0,
        actionName VARCHAR(50) NOT NULL DEFAULT '',
        actionClassName VARCHAR(200) NOT NULL DEFAULT '',
-       sortOrder INT(10) NOT NULL DEFAULT 0
+       sortOrder INT(10) NOT NULL DEFAULT 0,
+       UNIQUE KEY actionName (packageID, actionName)
 );
 
 DROP TABLE IF EXISTS wcf1_clipboard_item;
@@ -117,7 +118,8 @@ CREATE TABLE wcf1_clipboard_item_type (
        typeID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
        packageID INT(10) NOT NULL DEFAULT 0,
        typeName VARCHAR(80) NOT NULL DEFAULT '',
-       className VARCHAR(200) NOT NULL DEFAULT ''
+       listClassName VARCHAR(200) NOT NULL DEFAULT '',
+       UNIQUE KEY typeName (typeName)
 );
 
 DROP TABLE IF EXISTS wcf1_clipboard_page;
@@ -729,6 +731,15 @@ ALTER TABLE wcf1_cleanup_listener ADD FOREIGN KEY (packageID) REFERENCES wcf1_pa
 
 ALTER TABLE wcf1_cleanup_log ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
 
+ALTER TABLE wcf1_clipboard_action ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
+
+ALTER TABLE wcf1_clipboard_item ADD FOREIGN KEY (typeID) REFERENCES wcf1_clipboard_item_type (typeID) ON DELETE CASCADE;
+
+ALTER TABLE wcf1_clipboard_item_type ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
+
+ALTER TABLE wcf1_clipboard_page ADD FOREIGN KEY (actionID) REFERENCES wcf1_clipboard_action (actionID) ON DELETE CASCADE;
+ALTER TABLE wcf1_clipboard_page ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
+
 ALTER TABLE wcf1_core_object ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
 
 ALTER TABLE wcf1_cronjob ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;