From 25cf4d113a37368e350f21b8f0200598d13240e9 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 21 Oct 2011 20:54:19 +0200 Subject: [PATCH] Clipboard now support generic object types --- XSD/clipboardItemType.xsd | 36 --------- com.woltlab.wcf/clipboardItemType.xml | 8 -- com.woltlab.wcf/package.xml | 1 - com.woltlab.wcf/packageInstallationPlugin.xml | 1 - .../lib/action/ClipboardAction.class.php | 12 +-- .../item/type/ClipboardItemType.class.php | 25 ------- .../type/ClipboardItemTypeAction.class.php | 20 ----- .../type/ClipboardItemTypeEditor.class.php | 20 ----- .../item/type/ClipboardItemTypeList.class.php | 20 ----- .../ClipboardItemTypeCacheBuilder.class.php | 37 --------- .../clipboard/ClipboardHandler.class.php | 64 ++++++++-------- ...temTypePackageInstallationPlugin.class.php | 75 ------------------- wcfsetup/setup/db/install.sql | 18 +---- 13 files changed, 44 insertions(+), 293 deletions(-) delete mode 100644 XSD/clipboardItemType.xsd delete mode 100644 com.woltlab.wcf/clipboardItemType.xml delete mode 100644 wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemType.class.php delete mode 100644 wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemTypeAction.class.php delete mode 100644 wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemTypeEditor.class.php delete mode 100644 wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemTypeList.class.php delete mode 100644 wcfsetup/install/files/lib/system/cache/builder/ClipboardItemTypeCacheBuilder.class.php delete mode 100644 wcfsetup/install/files/lib/system/package/plugin/ClipboardItemTypePackageInstallationPlugin.class.php diff --git a/XSD/clipboardItemType.xsd b/XSD/clipboardItemType.xsd deleted file mode 100644 index 043110f108..0000000000 --- a/XSD/clipboardItemType.xsd +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/com.woltlab.wcf/clipboardItemType.xml b/com.woltlab.wcf/clipboardItemType.xml deleted file mode 100644 index 943267037f..0000000000 --- a/com.woltlab.wcf/clipboardItemType.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/com.woltlab.wcf/package.xml b/com.woltlab.wcf/package.xml index 3e1a71a312..3093d61a6a 100644 --- a/com.woltlab.wcf/package.xml +++ b/com.woltlab.wcf/package.xml @@ -26,6 +26,5 @@ cronjob.xml coreObject.xml clipboardAction.xml - clipboardItemType.xml diff --git a/com.woltlab.wcf/packageInstallationPlugin.xml b/com.woltlab.wcf/packageInstallationPlugin.xml index f3cb59da1e..b91601ab9e 100644 --- a/com.woltlab.wcf/packageInstallationPlugin.xml +++ b/com.woltlab.wcf/packageInstallationPlugin.xml @@ -4,7 +4,6 @@ wcf\system\package\plugin\ACPMenuPackageInstallationPlugin wcf\system\package\plugin\ACPTemplatePackageInstallationPlugin wcf\system\package\plugin\ClipboardActionPackageInstallationPlugin - wcf\system\package\plugin\ClipboardItemTypePackageInstallationPlugin wcf\system\package\plugin\CoreObjectPackageInstallationPlugin wcf\system\package\plugin\CronjobPackageInstallationPlugin wcf\system\package\plugin\EventListenerPackageInstallationPlugin diff --git a/wcfsetup/install/files/lib/action/ClipboardAction.class.php b/wcfsetup/install/files/lib/action/ClipboardAction.class.php index 451ea5971f..8fd94be194 100644 --- a/wcfsetup/install/files/lib/action/ClipboardAction.class.php +++ b/wcfsetup/install/files/lib/action/ClipboardAction.class.php @@ -43,10 +43,10 @@ class ClipboardAction extends AbstractSecureAction { protected $type = ''; /** - * clipboard item type id + * object type id * @var integer */ - protected $typeID = 0; + protected $objectTypeID = 0; /** * @see wcf\action\AbstractAction::_construct() @@ -102,7 +102,7 @@ class ClipboardAction extends AbstractSecureAction { $this->validate(); // execute action - ClipboardHandler::getInstance()->{$this->action}($this->objectIDs, $this->typeID); + ClipboardHandler::getInstance()->{$this->action}($this->objectIDs, $this->objectTypeID); } /** @@ -158,9 +158,9 @@ class ClipboardAction extends AbstractSecureAction { throw new AJAXException("Clipboard action '".$this->action."' is invalid."); } - $this->typeID = (!empty($this->type)) ? ClipboardHandler::getInstance()->getTypeID($this->type) : null; - if ($this->typeID === null) { - throw new AJAXException("Clipboard item type '".$this->type."' is invalid."); + $this->objectTypeID = (!empty($this->type)) ? ClipboardHandler::getInstance()->getObjectTypeID($this->type) : null; + if ($this->objectTypeID === null) { + throw new AJAXException("object type '".$this->type."' is invalid."); } } } diff --git a/wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemType.class.php b/wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemType.class.php deleted file mode 100644 index a9fa4af4c4..0000000000 --- a/wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemType.class.php +++ /dev/null @@ -1,25 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage data.clipboard.item.type - * @category Community Framework - */ -class ClipboardItemType extends DatabaseObject { - /** - * @see wcf\data\DatabaseObject::$databaseTableName - */ - protected static $databaseTableName = 'clipboard_item_type'; - - /** - * @see wcf\data\DatabaseObject::$databaseTableIndexName - */ - protected static $databaseTableIndexName = 'typeID'; -} diff --git a/wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemTypeAction.class.php b/wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemTypeAction.class.php deleted file mode 100644 index 088a3bad38..0000000000 --- a/wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemTypeAction.class.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage data.clipboard.item.type - * @category Community Framework - */ -class ClipboardItemTypeAction extends AbstractDatabaseObjectAction { - /** - * @see wcf\data\AbstractDatabaseObjectAction::$className - */ - protected $className = 'wcf\data\clipboard\item\type\ClipboardItemTypeEditor'; -} diff --git a/wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemTypeEditor.class.php b/wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemTypeEditor.class.php deleted file mode 100644 index 498b5437dc..0000000000 --- a/wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemTypeEditor.class.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage data.clipboard.item.type - * @category Community Framework - */ -class ClipboardItemTypeEditor extends DatabaseObjectEditor { - /** - * @see wcf\data\DatabaseObjectDecorator::$baseClass - */ - protected static $baseClass = 'wcf\data\clipboard\item\type\ClipboardItemType'; -} diff --git a/wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemTypeList.class.php b/wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemTypeList.class.php deleted file mode 100644 index 3adc7bd90a..0000000000 --- a/wcfsetup/install/files/lib/data/clipboard/item/type/ClipboardItemTypeList.class.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage data.clipboard.item.type - * @category Community Framework - */ -class ClipboardItemTypeList extends DatabaseObjectList { - /** - * @see wcf\data\DatabaseObjectList::$className - */ - public $className = 'wcf\data\clipboard\item\type\ClipboardItemType'; -} diff --git a/wcfsetup/install/files/lib/system/cache/builder/ClipboardItemTypeCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/ClipboardItemTypeCacheBuilder.class.php deleted file mode 100644 index a7bc8d53f0..0000000000 --- a/wcfsetup/install/files/lib/system/cache/builder/ClipboardItemTypeCacheBuilder.class.php +++ /dev/null @@ -1,37 +0,0 @@ - - * @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/clipboard/ClipboardHandler.class.php b/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php index f3f4afacbd..25abe78625 100644 --- a/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php +++ b/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php @@ -1,5 +1,6 @@ */ - protected $typeCache = null; + protected $cache = null; /** * @see wcf\system\SingletonFactory::init() */ protected function init() { - CacheHandler::getInstance()->addResource( - 'clipboard-itemType-'.PACKAGE_ID, - WCF_DIR.'cache/cache.clipboard-itemType-'.PACKAGE_ID.'.php', - 'wcf\system\cache\builder\ClipboardItemTypeCacheBuilder' + $this->cache = array( + 'objectTypes' => array(), + 'objectTypeNames' => array() ); - $this->typeCache = CacheHandler::getInstance()->get('clipboard-itemType-'.PACKAGE_ID); + $cache = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.clipboardItem'); + foreach ($cache as $objectType) { + $this->cache['objectTypes'][$objectType->objectTypeID] = $objectType; + $this->cache['objectTypeNames'][$objectType->objectType] = $objectType->objectTypeID; + } CacheHandler::getInstance()->addResource( 'clipboard-page-'.PACKAGE_ID, @@ -79,19 +83,19 @@ class ClipboardHandler extends SingletonFactory { * Marks objects as marked. * * @param array $objectIDs - * @param integer $typeID + * @param integer $objectTypeID */ - public function mark(array $objectIDs, $typeID) { + public function mark(array $objectIDs, $objectTypeID) { // remove existing entries first, prevents conflict with INSERT - $this->unmark($objectIDs, $typeID); + $this->unmark($objectIDs, $objectTypeID); $sql = "INSERT INTO wcf".WCF_N."_clipboard_item - (typeID, userID, objectID) + (objectTypeID, userID, objectID) VALUES (?, ?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); foreach ($objectIDs as $objectID) { $statement->execute(array( - $typeID, + $objectTypeID, WCF::getUser()->userID, $objectID )); @@ -102,11 +106,11 @@ class ClipboardHandler extends SingletonFactory { * Removes an object marking. * * @param array $objectIDs - * @param integer $typeID + * @param integer $objectTypeID */ - public function unmark(array $objectIDs, $typeID) { + public function unmark(array $objectIDs, $objectTypeID) { $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("typeID = ?", array($typeID)); + $conditions->add("objectTypeID = ?", array($objectTypeID)); $conditions->add("objectID IN (?)", array($objectIDs)); $conditions->add("userID = ?", array(WCF::getUser()->userID)); @@ -122,9 +126,9 @@ class ClipboardHandler extends SingletonFactory { * @param string $typeName * @return integer */ - public function getTypeID($typeName) { - if (isset($this->typeCache['typeNames'][$typeName])) { - return $this->typeCache['typeNames'][$typeName]; + public function getObjectTypeID($typeName) { + if (isset($this->cache['objectTypeNames'][$typeName])) { + return $this->cache['objectTypeNames'][$typeName]; } return null; @@ -134,11 +138,11 @@ class ClipboardHandler extends SingletonFactory { * Returns a type by type id. * * @param integer $typeID - * @return wcf\data\clipboard\item\type\ClipboardItemType + * @return wcf\data\object\type\ObjectType */ - public function getType($typeID) { - if (isset($this->typeCache['types'][$typeID])) { - return $this->typeCache['types'][$typeID]; + public function getObjectType($typeID) { + if (isset($this->cache['objectTypes'][$typeID])) { + return $this->cache['objectTypes'][$typeID]; } return null; @@ -155,7 +159,7 @@ class ClipboardHandler extends SingletonFactory { if ($typeID !== null) $conditions->add("typeID = ?", array($typeID)); // fetch object ids - $sql = "SELECT typeID, objectID + $sql = "SELECT objectTypeID, objectID FROM wcf".WCF_N."_clipboard_item ".$conditions; $statement = WCF::getDB()->prepareStatement($sql); @@ -164,30 +168,30 @@ class ClipboardHandler extends SingletonFactory { // group object ids by type name $data = array(); while ($row = $statement->fetchArray()) { - $type = $this->getType($row['typeID']); - if ($type === null) { + $objectType = $this->getObjectType($row['objectTypeID']); + if ($objectType === null) { continue; } - if (!isset($data[$type->typeName])) { - $data[$type->typeName] = array( - 'className' => $type->listClassName, + if (!isset($data[$objectType->objectType])) { + $data[$objectType->objectType] = array( + 'className' => $objectType->listClassName, 'objectIDs' => array() ); } - $data[$type->typeName]['objectIDs'][] = $row['objectID']; + $data[$objectType->objectType]['objectIDs'][] = $row['objectID']; } // read objects $this->markedItems = array(); - foreach ($data as $typeName => $objectData) { + foreach ($data as $objectType => $objectData) { $objectList = new $objectData['className'](); $objectList->getConditionBuilder()->add($objectList->getDatabaseTableAlias() . "." . $objectList->getDatabaseTableIndexName() . " IN (?)", array($objectData['objectIDs'])); $objectList->sqlLimit = 0; $objectList->readObjects(); - $this->markedItems[$typeName] = $objectList->getObjects(); + $this->markedItems[$objectType] = $objectList->getObjects(); } } diff --git a/wcfsetup/install/files/lib/system/package/plugin/ClipboardItemTypePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/ClipboardItemTypePackageInstallationPlugin.class.php deleted file mode 100644 index f2f74b9a9b..0000000000 --- a/wcfsetup/install/files/lib/system/package/plugin/ClipboardItemTypePackageInstallationPlugin.class.php +++ /dev/null @@ -1,75 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage acp.package.plugin - * @category Community Framework - */ -class ClipboardItemTypePackageInstallationPlugin 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 - ); - } -} diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 94e0b5c36f..010c0d24a0 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -112,18 +112,10 @@ CREATE TABLE wcf1_clipboard_action ( DROP TABLE IF EXISTS wcf1_clipboard_item; CREATE TABLE wcf1_clipboard_item ( - typeID INT(10) NOT NULL DEFAULT 0, + objectTypeID INT(10) NOT NULL DEFAULT 0, userID INT(10) NOT NULL DEFAULT 0, - objectID INT(10) NOT NULL DEFAULT 0 -); - -DROP TABLE IF EXISTS wcf1_clipboard_item_type; -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 '', - listClassName VARCHAR(200) NOT NULL DEFAULT '', - UNIQUE KEY typeName (typeName) + objectID INT(10) NOT NULL DEFAULT 0, + UNIQUE KEY (objectTypeID, userID, objectID) ); DROP TABLE IF EXISTS wcf1_clipboard_page; @@ -751,9 +743,7 @@ ALTER TABLE wcf1_cleanup_log ADD FOREIGN KEY (packageID) REFERENCES wcf1_package 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_item ADD FOREIGN KEY (objectTypeID) REFERENCES wcf1_object_type (objectTypeID) 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; -- 2.20.1