- PIPs for the user notification package
authorMarcel Werk <burntime@woltlab.com>
Thu, 14 Jul 2011 20:11:45 +0000 (22:11 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 14 Jul 2011 20:11:45 +0000 (22:11 +0200)
com.woltlab.wcf.notification/files/lib/system/package/plugin/UserNotificationEventPackageInstallationPlugin.class.php
com.woltlab.wcf.notification/files/lib/system/package/plugin/UserNotificationObjectTypePackageInstallationPlugin.class.php [new file with mode: 0644]
com.woltlab.wcf.notification/files/lib/system/package/plugin/UserNotificationTypePackageInstallationPlugin.class.php [new file with mode: 0644]
com.woltlab.wcf.notification/install.sql
wcfsetup/install/files/lib/system/request/Request.class.php

diff --git a/com.woltlab.wcf.notification/files/lib/system/package/plugin/UserNotificationObjectTypePackageInstallationPlugin.class.php b/com.woltlab.wcf.notification/files/lib/system/package/plugin/UserNotificationObjectTypePackageInstallationPlugin.class.php
new file mode 100644 (file)
index 0000000..994e07f
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+namespace wcf\system\package\plugin;
+use wcf\system\WCF;
+
+/**
+ * This PIP installs, updates or deletes user notification object types.
+ * 
+ * @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.notification
+ * @subpackage system.package.plugin
+ * @category   Community Framework
+ */
+class UserNotificationObjectTypePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin {
+       /**
+        * @see AbstractXMLPackageInstallationPlugin::$className
+        */
+       public $className = 'wcf\data\user\notification\object\type\UserNotificationObjectTypeEditor';
+       
+       /**
+        * @see AbstractXMLPackageInstallationPlugin::$tableName
+        */
+       public $tableName = 'user_notification_object_type';
+       
+       /**
+        * @see AbstractXMLPackageInstallationPlugin::$tagName
+        */     
+       public $tagName = 'objecttype';
+       
+       /**
+        * @see AbstractXMLPackageInstallationPlugin::handleDelete()
+        */
+       protected function handleDelete(array $items) {
+               $sql = "DELETE FROM     wcf".WCF_N."_".$this->tableName."
+                       WHERE           packageID = ?
+                                       AND objectType = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               foreach ($items as $item) {
+                       $statement->execute(array(
+                               $this->installation->getPackageID(),
+                               $item['elements']['name']
+                       ));
+               }
+       }
+       
+       /**
+        * @see AbstractXMLPackageInstallationPlugin::prepareImport()
+        */
+       protected function prepareImport(array $data) {
+               return array(
+                       'objectType' => $data['elements']['name'],
+                       'className' => $data['elements']['classname'],
+                       'permissions' => (isset($data['elements']['permissions']) ? $data['elements']['permissions'] : ''),
+                       'options' => (isset($data['elements']['options']) ? $data['elements']['options'] : '')
+               );
+       }
+       
+       /**
+        * @see AbstractXMLPackageInstallationPlugin::findExistingItem()
+        */
+       protected function findExistingItem(array $data) {
+               $sql = "SELECT  *
+                       FROM    wcf".WCF_N."_".$this->tableName."
+                       WHERE   packageID = ?
+                               AND objectType = ?";
+               $parameters = array(
+                       $this->installation->getPackageID(),
+                       $data['objectType']
+               );
+               
+               return array(
+                       'sql' => $sql,
+                       'parameters' => $parameters
+               );
+       }
+}
+?>
diff --git a/com.woltlab.wcf.notification/files/lib/system/package/plugin/UserNotificationTypePackageInstallationPlugin.class.php b/com.woltlab.wcf.notification/files/lib/system/package/plugin/UserNotificationTypePackageInstallationPlugin.class.php
new file mode 100644 (file)
index 0000000..7a7ef08
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+namespace wcf\system\package\plugin;
+use wcf\system\WCF;
+
+/**
+ * This PIP installs, updates or deletes user notification types.
+ * 
+ * @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.notification
+ * @subpackage system.package.plugin
+ * @category   Community Framework
+ */
+class UserNotificationTypePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin {
+       /**
+        * @see AbstractXMLPackageInstallationPlugin::$className
+        */
+       public $className = 'wcf\data\user\notification\type\UserNotificationTypeEditor';
+       
+       /**
+        * @see AbstractXMLPackageInstallationPlugin::$tableName
+        */
+       public $tableName = 'user_notification_type';
+       
+       /**
+        * @see AbstractXMLPackageInstallationPlugin::$tagName
+        */     
+       public $tagName = 'notificationtype';
+       
+       /**
+        * @see AbstractXMLPackageInstallationPlugin::handleDelete()
+        */
+       protected function handleDelete(array $items) {
+               $sql = "DELETE FROM     wcf".WCF_N."_".$this->tableName."
+                       WHERE           packageID = ?
+                                       AND notificationType = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               foreach ($items as $item) {
+                       $statement->execute(array(
+                               $this->installation->getPackageID(),
+                               $item['elements']['name']
+                       ));
+               }
+       }
+       
+       /**
+        * @see AbstractXMLPackageInstallationPlugin::prepareImport()
+        */
+       protected function prepareImport(array $data) {
+               return array(
+                       'notificationType' => $data['elements']['name'],
+                       'className' => $data['elements']['classname'],
+                       'permissions' => (isset($data['elements']['permissions']) ? $data['elements']['permissions'] : ''),
+                       'options' => (isset($data['elements']['options']) ? $data['elements']['options'] : '')
+               );
+       }
+       
+       /**
+        * @see AbstractXMLPackageInstallationPlugin::findExistingItem()
+        */
+       protected function findExistingItem(array $data) {
+               $sql = "SELECT  *
+                       FROM    wcf".WCF_N."_".$this->tableName."
+                       WHERE   packageID = ?
+                               AND notificationType = ?";
+               $parameters = array(
+                       $this->installation->getPackageID(),
+                       $data['notificationType']
+               );
+               
+               return array(
+                       'sql' => $sql,
+                       'parameters' => $parameters
+               );
+       }
+}
+?>
index e0fe14d0cc1aa204707fee75198a1488841ceb5a..5857f676ad740839950e3dabba96e2562865b7e9 100644 (file)
@@ -69,7 +69,8 @@ CREATE TABLE wcf1_user_notification_type (
        notificationType VARCHAR(255) NOT NULL,
        className VARCHAR(255) NOT NULL,
        permissions TEXT,
-       options TEXT  
+       options TEXT,
+       UNIQUE KEY packageID (packageID, notificationType) 
 );
 
 ALTER TABLE wcf1_user_notification ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
index 4d0433d38f3999e7bb428b01b3558e8da36a8112..d5d8a261a7fafbb0659a93390a7e6ccc6f0d8455 100644 (file)
@@ -94,4 +94,5 @@ class Request {
        public function getPageType() {\r
                return $this->pageType;\r
        }\r
-}
\ No newline at end of file
+}\r
+?>
\ No newline at end of file