Implemented abstraction of object types
authorMarcel Werk <burntime@woltlab.com>
Wed, 19 Oct 2011 12:43:10 +0000 (14:43 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 19 Oct 2011 12:43:10 +0000 (14:43 +0200)
17 files changed:
com.woltlab.wcf/packageInstallationPlugin.xml
wcfsetup/install/files/acp/templates/header.tpl
wcfsetup/install/files/lib/data/event/listener/EventListenerAction.class.php
wcfsetup/install/files/lib/data/event/listener/EventListenerList.class.php
wcfsetup/install/files/lib/data/object/type/ObjectType.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/object/type/ObjectTypeAction.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/object/type/ObjectTypeCache.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/object/type/ObjectTypeEditor.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/object/type/ObjectTypeList.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/object/type/definition/ObjectTypeDefinition.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/object/type/definition/ObjectTypeDefinitionAction.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/object/type/definition/ObjectTypeDefinitionEditor.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/data/object/type/definition/ObjectTypeDefinitionList.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/cache/builder/ObjectTypeCacheBuilder.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/package/plugin/ObjectTypeDefinitionPackageInstallationPlugin.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/package/plugin/ObjectTypePackageInstallationPlugin.class.php [new file with mode: 0644]
wcfsetup/setup/db/install.sql

index 4f2d429a4a1f3ebbd910b3aa68f0a700796ab483..9deed6ac630723ae4a70f78526345f8a16cf9d24 100644 (file)
@@ -10,6 +10,8 @@
                <pip name="eventListener">wcf\system\package\plugin\EventListenerPackageInstallationPlugin</pip>
                <pip name="file">wcf\system\package\plugin\FilePackageInstallationPlugin</pip>
                <pip name="language">wcf\system\package\plugin\LanguagePackageInstallationPlugin</pip>
+               <pip name="objectType">wcf\system\package\plugin\ObjectTypePackageInstallationPlugin</pip>
+               <pip name="objectTypeDefinition">wcf\system\package\plugin\ObjectTypeDefinitionInstallationPlugin</pip>
                <pip name="option">wcf\system\package\plugin\OptionPackageInstallationPlugin</pip>
                <pip name="pageMenu">wcf\system\package\plugin\PageMenuPackageInstallationPlugin</pip>
                <pip name="script">wcf\system\package\plugin\ScriptPackageInstallationPlugin</pip>
index 881bafa104a45384c0e765a1bb593be77cf6c80b..cc173e6db363297dba95169f7d8c33976fdc6846 100644 (file)
                        <!-- logo -->
                        <div id="logo" class="logo">
                                <!-- clickable area -->
-                               <a href="{@SID_ARG_1ST}">
+                               <a href="{link controller='Index'}{/link}">
                                        <h1>WoltLab Community Framework 2.0 Pre-Alpha 1</h1>
                                        <img src="{@RELATIVE_WCF_DIR}acp/images/wcfLogoWhite.svg" width="300" height="58" alt="Product-logo" title="WoltLab Community Framework 2.0 Pre-Alpha 1" />
                                </a>
index 382f1dfcbb7f138023a02482cc1a01bdcd24627f..f87309f349430756dacd9f6c955a99cd436c8ffd 100644 (file)
@@ -9,7 +9,7 @@ use wcf\data\AbstractDatabaseObjectAction;
  * @copyright  2001-2011 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
- * @subpackage data.event
+ * @subpackage data.event.listener
  * @category   Community Framework
  */
 class EventListenerAction extends AbstractDatabaseObjectAction {
index 45a46dde60d76bbe8c090242d3874db344da5755..8b92bf95f61c5ea07a7f2fc8370c588b8460e132 100644 (file)
@@ -9,7 +9,7 @@ use wcf\data\DatabaseObjectList;
  * @copyright  2001-2011 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf
- * @subpackage data.event
+ * @subpackage data.event.listener
  * @category   Community Framework
  */
 class EventListenerList extends DatabaseObjectList {
diff --git a/wcfsetup/install/files/lib/data/object/type/ObjectType.class.php b/wcfsetup/install/files/lib/data/object/type/ObjectType.class.php
new file mode 100644 (file)
index 0000000..e65d5d7
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+namespace wcf\data\object\type;
+use wcf\data\ProcessibleDatabaseObject;
+use wcf\system\exception\SystemException;
+use wcf\util\ClassUtil;
+
+/**
+ * Represents an object type.
+ * 
+ * @author     Marcel Werk
+ * @copyright  2001-2011 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage data.object.type
+ * @category   Community Framework
+ */
+class ObjectType extends ProcessibleDatabaseObject {
+       /**
+        * @see wcf\data\DatabaseObject::$databaseTableName
+        */
+       protected static $databaseTableName = 'object_type';
+       
+       /**
+        * @see wcf\data\DatabaseObject::$databaseTableIndexName
+        */
+       protected static $databaseTableIndexName = 'objectTypeID';
+       
+       /**
+        * @see wcf\data\ProcessibleDatabaseObject::getProcessor()
+        */
+       public function getProcessor() {
+               if ($this->processor === null) {
+                       if ($this->className) {
+                               if (!class_exists($this->className)) {
+                                       throw new SystemException("Unable to find class '".$this->className."'");
+                               }
+                               if (!ClassUtil::isInstanceOf($this->className, 'wcf\data\IDatabaseObjectProcessor')) {
+                                       throw new SystemException("'".$this->className."' should implement wcf\data\IDatabaseObjectProcessor");
+                               }
+                               if (($definitionInterface = ObjectTypeCache::getInstance()->getDefinition($this->definitionID)->interfaceName) && !ClassUtil::isInstanceOf($this->className, $definitionInterface)) {
+                                       throw new SystemException("'".$this->className."' should implement ".$definitionInterface);
+                               }
+                               
+                               $this->processor = new $this->className($this);
+                       }
+               }
+               
+               return $this->processor;
+       }
+}
diff --git a/wcfsetup/install/files/lib/data/object/type/ObjectTypeAction.class.php b/wcfsetup/install/files/lib/data/object/type/ObjectTypeAction.class.php
new file mode 100644 (file)
index 0000000..a47219f
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace wcf\data\object\type;
+use wcf\data\AbstractDatabaseObjectAction;
+
+/**
+ * Executes object type-related 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 data.object.type
+ * @category   Community Framework
+ */
+class ObjectTypeAction extends AbstractDatabaseObjectAction {
+       /**
+        * @see wcf\data\AbstractDatabaseObjectAction::$className
+        */
+       protected $className = 'wcf\data\object\type\ObjectTypeEditor';
+}
diff --git a/wcfsetup/install/files/lib/data/object/type/ObjectTypeCache.class.php b/wcfsetup/install/files/lib/data/object/type/ObjectTypeCache.class.php
new file mode 100644 (file)
index 0000000..1c63ed3
--- /dev/null
@@ -0,0 +1,134 @@
+<?php
+namespace wcf\data\object\type;
+use wcf\system\cache\CacheHandler;
+use wcf\system\SingletonFactory;
+
+/**
+ * Manages the object type cache.
+ * 
+ * @author     Marcel Werk
+ * @copyright  2001-2011 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage data.object.type
+ * @category   Community Framework
+ */
+class ObjectTypeCache extends SingletonFactory {
+       /**
+        * object type definitions
+        * @var array<wcf\data\object\type\definition\ObjectTypeDefinition>
+        */
+       protected $definitions = array();
+       
+       /**
+        * object type definitions sorted by name
+        * @var array<wcf\data\object\type\definition\ObjectTypeDefinition>
+        */
+       protected $definitionsByName = array();
+       
+       /**
+        * object types
+        * @var array<wcf\data\object\type\ObjectType>
+        */
+       protected $objectTypes = array();
+       
+       /**
+        * object types grouped by definition
+        * @var array
+        */
+       protected $groupedObjectTypes = array();
+       
+       /**
+        * @see wcf\system\SingletonFactory::init()
+        */
+       protected function init() {
+               // get definition cache
+               CacheHandler::getInstance()->addResource('objectType-'.PACKAGE_ID, WBB_DIR.'cache/cache.objectType-'.PACKAGE_ID.'.php', 'wcf\system\cache\builder\ObjectTypeCacheBuilder');
+               $this->definitions = CacheHandler::getInstance()->get('objectType-'.PACKAGE_ID, 'definitions');
+               foreach ($this->definitions as $definition) {
+                       $this->definitionsByName[$definition->definitionName] = $definition;
+               }
+               
+               // get object type cache
+               $this->objectTypes = CacheHandler::getInstance()->get('objectType-'.PACKAGE_ID, 'objectTypes');
+               foreach ($this->objectTypes as $objectType) {
+                       $definition = $this->getDefinition($objectType->definitionID);
+                       if (!isset($this->groupedObjectTypes[$definition->definitionName])) {
+                               $this->groupedObjectTypes[$definition->definitionName] = array();
+                       }
+                       
+                       $this->groupedObjectTypes[$definition->definitionName][$objectType->objectTypeName] = $objectType;
+               }
+       }
+       
+       /**
+        * Gets an object type definition by id
+        * 
+        * @param       integer         $definitionID
+        * @return      wcf\data\object\type\definition\ObjectTypeDefinition
+        */
+       public function getDefinition($definitionID) {
+               if (isset($this->definitions[$definitionID])) {
+                       return $this->definitions[$definitionID];
+               }
+               
+               return null;
+       }
+       
+       /**
+        * Gets an object type definition by name
+        * 
+        * @param       string          $definitionName
+        * @return      wcf\data\object\type\definition\ObjectTypeDefinition
+        */
+       public function getDefinitionByName($definitionName) {
+               if (isset($this->definitionsByName[$definitionName])) {
+                       return $this->definitionsByName[$definitionName];
+               }
+               
+               return null;
+       }
+       
+       /**
+        * Gets an object type by id
+        * 
+        * @param       integer         $objectTypeID
+        * @return      wcf\data\object\type\ObjectType
+        */
+       public function getObjectType($objectTypeID) {
+               if (isset($this->objectTypes[$objectTypeID])) {
+                       return $this->objectTypes[$objectTypeID];
+               }
+               
+               return null;
+       }
+       
+       /**
+        * Returns a list of object types.
+        * 
+        * @param       string          $definitionName
+        * @return      array<wcf\data\object\type\ObjectType>
+        */
+       public function getObjectTypes($definitionName) {
+               if (isset($this->groupedObjectTypes[$definitionName])) {
+                       return $this->groupedObjectTypes[$definitionName];
+               }
+               
+               return array();
+       }
+       
+       /**
+        * Returns an object type.
+        * 
+        * @param       string          $definitionName
+        * @param       string          $objectTypeName
+        * @return      wcf\data\object\type\ObjectType
+        */
+       public function getObjectTypeByName($definitionName, $objectTypeName) {
+               if (isset($this->groupedObjectTypes[$definitionName]) && isset($this->groupedObjectTypes[$definitionName][$typeName])) {
+                       return $this->groupedObjectTypes[$definitionName][$typeName];
+               }
+               
+               return null;
+       }
+}
diff --git a/wcfsetup/install/files/lib/data/object/type/ObjectTypeEditor.class.php b/wcfsetup/install/files/lib/data/object/type/ObjectTypeEditor.class.php
new file mode 100644 (file)
index 0000000..c86506d
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace wcf\data\object\type;
+use wcf\data\DatabaseObjectEditor;
+
+/**
+ * Provides functions to edit object 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 data.object.type
+ * @category   Community Framework
+ */
+class ObjectTypeEditor extends DatabaseObjectEditor {
+       /**
+        * @see wcf\data\DatabaseObjectDecorator::$baseClass
+        */
+       public static $baseClass = 'wcf\data\object\type\ObjectType';
+}
diff --git a/wcfsetup/install/files/lib/data/object/type/ObjectTypeList.class.php b/wcfsetup/install/files/lib/data/object/type/ObjectTypeList.class.php
new file mode 100644 (file)
index 0000000..f78fbbe
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace wcf\data\object\type;
+use wcf\data\DatabaseObjectList;
+
+/**
+ * Represents a list of object 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 data.object.type.definition
+ * @category   Community Framework
+ */
+class ObjectTypeList extends DatabaseObjectList {
+       /**
+        * @see wcf\data\DatabaseObjectList::$className
+        */
+       public $className = 'wcf\data\object\type\ObjectType';
+}
diff --git a/wcfsetup/install/files/lib/data/object/type/definition/ObjectTypeDefinition.class.php b/wcfsetup/install/files/lib/data/object/type/definition/ObjectTypeDefinition.class.php
new file mode 100644 (file)
index 0000000..c5feb33
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+namespace wcf\data\object\type\definition;
+use wcf\data\DatabaseObject;
+
+/**
+ * Represents an object type definition.
+ * 
+ * @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 data.object.type.definition
+ * @category   Community Framework
+ */
+class ObjectTypeDefinition extends DatabaseObject {
+       /**
+        * @see wcf\data\DatabaseObject::$databaseTableName
+        */
+       protected static $databaseTableName = 'object_type_definition';
+       
+       /**
+        * @see wcf\data\DatabaseObject::$databaseTableIndexName
+        */
+       protected static $databaseTableIndexName = 'definitionID';
+}
diff --git a/wcfsetup/install/files/lib/data/object/type/definition/ObjectTypeDefinitionAction.class.php b/wcfsetup/install/files/lib/data/object/type/definition/ObjectTypeDefinitionAction.class.php
new file mode 100644 (file)
index 0000000..ee31b94
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace wcf\data\object\type\definition;
+use wcf\data\AbstractDatabaseObjectAction;
+
+/**
+ * Executes object type definition-related 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 data.object.type.definition
+ * @category   Community Framework
+ */
+class ObjectTypeDefinitionAction extends AbstractDatabaseObjectAction {
+       /**
+        * @see wcf\data\AbstractDatabaseObjectAction::$className
+        */
+       protected $className = 'wcf\data\object\type\definition\ObjectTypeDefinitionEditor';
+}
diff --git a/wcfsetup/install/files/lib/data/object/type/definition/ObjectTypeDefinitionEditor.class.php b/wcfsetup/install/files/lib/data/object/type/definition/ObjectTypeDefinitionEditor.class.php
new file mode 100644 (file)
index 0000000..abef7a7
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace wcf\data\object\type\definition;
+use wcf\data\DatabaseObjectEditor;
+
+/**
+ * Provides functions to edit object type definitions.
+ *
+ * @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 data.object.type.definition
+ * @category   Community Framework
+ */
+class ObjectTypeDefinitionEditor extends DatabaseObjectEditor {
+       /**
+        * @see wcf\data\DatabaseObjectDecorator::$baseClass
+        */
+       public static $baseClass = 'wcf\data\object\type\definition\ObjectTypeDefinition';
+}
diff --git a/wcfsetup/install/files/lib/data/object/type/definition/ObjectTypeDefinitionList.class.php b/wcfsetup/install/files/lib/data/object/type/definition/ObjectTypeDefinitionList.class.php
new file mode 100644 (file)
index 0000000..449f030
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace wcf\data\object\type\definition;
+use wcf\data\DatabaseObjectList;
+
+/**
+ * Represents a list of object type definitions.
+ * 
+ * @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 data.object.type.definition
+ * @category   Community Framework
+ */
+class ObjectTypeDefinitionList extends DatabaseObjectList {
+       /**
+        * @see wcf\data\DatabaseObjectList::$className
+        */
+       public $className = 'wcf\data\object\type\definition\ObjectTypeDefinition';
+}
diff --git a/wcfsetup/install/files/lib/system/cache/builder/ObjectTypeCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/ObjectTypeCacheBuilder.class.php
new file mode 100644 (file)
index 0000000..6310228
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+namespace wcf\system\cache\builder;
+use wcf\data\object\type\definition\ObjectTypeDefinition;
+use wcf\system\WCF;
+
+/**
+ * Caches object types and object type definitions.
+ * 
+ * @author     Marcel Werk
+ * @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 ObjectTypeCacheBuilder implements ICacheBuilder {
+       /**
+        * @see wcf\system\cache\ICacheBuilder::getData()
+        */
+       public function getData(array $cacheResource) {
+               list($cache, $packageID) = explode('-', $cacheResource['cache']);
+               $data = array(
+                       'definitions' => array(),
+                       'objectTypes' => array()
+               );
+       
+               // get definitions
+               $sql = "SELECT          object_type_definition.*
+                       FROM            wcf".WCF_N."_package_dependency package_dependency,
+                                       wcf".WCF_N."_object_type_definition object_type_definition
+                       WHERE           object_type_definition.packageID = package_dependency.dependency
+                                       AND package_dependency.packageID = ?
+                       ORDER BY        package_dependency.priority";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array($packageID));
+               while ($row = $statement->fetchArray()) {
+                       $data['definitions'][$row['definitionID']] = new ObjectTypeDefinition(null, $row);
+               }
+
+               // get object types
+               $sql = "SELECT          object_type.*
+                       FROM            wcf".WCF_N."_package_dependency package_dependency,
+                                       wcf".WCF_N."_object_type object_type
+                       WHERE           object_type.packageID = package_dependency.dependency
+                                       AND package_dependency.packageID = ?
+                       ORDER BY        package_dependency.priority";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array($packageID));
+               while ($row = $statement->fetchArray()) {
+                       $data['objectTypes'][$row['objectTypeID']] = new ObjectType(null, $row);
+               }
+               
+               return $data;
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/package/plugin/ObjectTypeDefinitionPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/ObjectTypeDefinitionPackageInstallationPlugin.class.php
new file mode 100644 (file)
index 0000000..5ae27eb
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+namespace wcf\system\package\plugin;
+use wcf\system\WCF;
+
+/**
+ * This PIP installs, updates or deletes object type definitions.
+ * 
+ * @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 ObjectTypeDefinitionPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin {
+       /**
+        * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$className
+        */
+       public $className = 'wcf\data\object\type\definition\ObjectTypeDefinitionEditor';
+       
+       /**
+        * @see wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName
+        */
+       public $tableName = 'object_type_definition';
+       
+       /**
+        * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$tagName
+        */     
+       public $tagName = 'definition';
+       
+       /**
+        * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::handleDelete()
+        */
+       protected function handleDelete(array $items) {
+               $sql = "DELETE FROM     wcf".WCF_N."_".$this->tableName."
+                       WHERE           definitionName = ?
+                                       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(
+                       'interfaceName' => (isset($data['elements']['interfacename']) ? $data['elements']['interfacename'] : ''),
+                       'definitionName' => $data['attributes']['name']
+               );
+       }
+       
+       /**
+        * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::findExistingItem()
+        */
+       protected function findExistingItem(array $data) {
+               $sql = "SELECT  *
+                       FROM    wcf".WCF_N."_".$this->tableName."
+                       WHERE   definitionName = ?
+                               AND packageID = ?";
+               $parameters = array(
+                       $data['definitionName'],
+                       $this->installation->getPackageID()
+               );
+               
+               return array(
+                       'sql' => $sql,
+                       'parameters' => $parameters
+               );
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/package/plugin/ObjectTypePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/ObjectTypePackageInstallationPlugin.class.php
new file mode 100644 (file)
index 0000000..f74e728
--- /dev/null
@@ -0,0 +1,104 @@
+<?php
+namespace wcf\system\package\plugin;
+use wcf\system\exception\SystemException;
+use wcf\system\WCF;
+
+/**
+ * This PIP installs, updates or deletes object 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 ObjectTypePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin {
+       /**
+        * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$className
+        */
+       public $className = 'wcf\data\object\type\ObjectTypeEditor';
+       
+       /**
+        * @see wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName
+        */
+       public $tableName = 'object_type';
+       
+       /**
+        * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$tagName
+        */     
+       public $tagName = 'type';
+       
+       /**
+        * Gets the definition id by name
+        * 
+        * @param       string          $definitionName
+        * @return      integer
+        */
+       protected function getDefinitionID($definitionName) {
+               // get object type id
+               $sql = "SELECT          notification_object_type.definitionID
+                       FROM            wcf".WCF_N."_package_dependency package_dependency,
+                                       wcf".WCF_N."_object_type_definition object_type_definition
+                       WHERE           object_type_definition.packageID = package_dependency.dependency
+                                       AND package_dependency.packageID = ?
+                                       AND object_type_definition.definitionName = ?
+                       ORDER BY        package_dependency.priority DESC";
+               $statement = WCF::getDB()->prepareStatement($sql, 1);
+               $statement->execute(array($this->installation->getPackageID(), $definitionName));
+               $row = $statement->fetchArray();
+               if (empty($row['definitionID'])) throw new SystemException("unknown object type definition '".$definitionName."' given");
+               return $row['definitionID'];
+       }
+       
+       /**
+        * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::handleDelete()
+        */
+       protected function handleDelete(array $items) {
+               $sql = "DELETE FROM     wcf".WCF_N."_".$this->tableName."
+                       WHERE           objectType = ?
+                                       definitionID = ?
+                                       AND packageID = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               foreach ($items as $item) {
+                       $statement->execute(array(
+                               $item['attributes']['name'],
+                               $this->getDefinitionID($data['elements']['definitionname']),
+                               $this->installation->getPackageID()
+                       ));
+               }
+       }
+       
+       /**
+        * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::prepareImport()
+        */
+       protected function prepareImport(array $data) {
+               return array(
+                       'definitionID' => $this->getDefinitionID($data['elements']['definitionname']),
+                       'objectType' => $data['attributes']['name'],
+                       'className' => (isset($data['elements']['classname']) ? $data['elements']['classname'] : ''),
+                       'additionalData' => serialize(isset($data['elements']['additionaldata']) ? $data['elements']['additionaldata'] : array())
+               );
+       }
+       
+       /**
+        * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::findExistingItem()
+        */
+       protected function findExistingItem(array $data) {
+               $sql = "SELECT  *
+                       FROM    wcf".WCF_N."_".$this->tableName."
+                       WHERE   objectType = ?
+                               definitionID = ?
+                               AND packageID = ?";
+               $parameters = array(
+                       $data['objectType'],
+                       $data['definitionID'],
+                       $this->installation->getPackageID()
+               );
+               
+               return array(
+                       'sql' => $sql,
+                       'parameters' => $parameters
+               );
+       }
+}
index ee887c1629f4762334544251965a5736e2bdc63c..a0ad1d50581830d7dff45024646dcb5487dbaa23 100644 (file)
@@ -229,6 +229,26 @@ CREATE TABLE wcf1_language_to_package (
        UNIQUE KEY languageID (languageID, packageID)
 );
 
+DROP TABLE IF EXISTS wcf1_object_type;
+CREATE TABLE wcf1_object_type (
+       objectTypeID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
+       definitionID INT(10) NOT NULL,
+       packageID INT(10) NOT NULL,
+       objectType VARCHAR(255) NOT NULL,
+       className VARCHAR(255) NOT NULL DEFAULT '',
+       additionalData MEDIUMTEXT,
+       UNIQUE KEY objectType (objectType, definitionID, packageID)
+);
+
+DROP TABLE IF EXISTS wcf1_object_type_definition;
+CREATE TABLE wcf1_object_type_definition (
+       definitionID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
+       definitionName VARCHAR(255) NOT NULL,
+       packageID INT(10) NOT NULL,
+       interfaceName VARCHAR(255) NOT NULL DEFAULT '',
+       UNIQUE KEY definitionName (definitionName, packageID)
+);
+
 DROP TABLE IF EXISTS wcf1_option;
 CREATE TABLE wcf1_option (
        optionID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -745,6 +765,11 @@ ALTER TABLE wcf1_language_item ADD FOREIGN KEY (packageID) REFERENCES wcf1_packa
 ALTER TABLE wcf1_language_to_package ADD FOREIGN KEY (languageID) REFERENCES wcf1_language (languageID) ON DELETE CASCADE;
 ALTER TABLE wcf1_language_to_package ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
 
+ALTER TABLE wcf1_object_type ADD FOREIGN KEY (definitionID) REFERENCES wcf1_object_type_definition (definitionID) ON DELETE CASCADE;
+ALTER TABLE wcf1_object_type ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
+
+ALTER TABLE wcf1_object_type_definition ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
+
 ALTER TABLE wcf1_option ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
 
 ALTER TABLE wcf1_option_category ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;