2 namespace wcf\system\package\plugin;
3 use wcf\system\exception\SystemException;
7 * This PIP installs, updates or deletes user notification events.
10 * @copyright 2001-2011 WoltLab GmbH
11 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
12 * @package com.woltlab.wcf.notification
13 * @subpackage system.package.plugin
14 * @category Community Framework
16 class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin {
18 * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$className
20 public $className = 'wcf\data\user\notification\event\UserNotificationEventEditor';
23 * @see wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName
25 public $tableName = 'user_notification_event';
28 * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$tagName
30 public $tagName = 'event';
33 * @see AbstractXMLPackageInstallationPlugin::handleDelete()
35 protected function handleDelete(array $items) {
36 $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName."
39 $statement = WCF::getDB()->prepareStatement($sql);
40 foreach ($items as $item) {
41 $statement->execute(array(
42 $this->installation->getPackageID(),
43 $item['elements']['name']
49 * @see AbstractXMLPackageInstallationPlugin::prepareImport()
51 protected function prepareImport(array $data) {
53 $sql = "SELECT notification_object_type.objectTypeID
54 FROM wcf".WCF_N."_package_dependency package_dependency,
55 wcf".WCF_N."_user_notification_object_type notification_object_type
56 WHERE notification_object_type.packageID = package_dependency.dependency
57 AND package_dependency.packageID = ?
58 AND notification_object_type.objectType = ?
59 ORDER BY package_dependency.priority DESC";
60 $statement = WCF::getDB()->prepareStatement($sql, 1);
61 $statement->execute(array($this->installation->getPackageID(), $data['elements']['objecttype']));
62 $row = $statement->fetchArray();
63 if (empty($row['objectTypeID'])) throw new SystemException("unknown notification object type '".$data['elements']['objecttype']."' given");
64 $objectTypeID = $row['objectTypeID'];
66 // get notification type id
67 $defaultNotificationTypeID = 0;
68 if (!empty($data['elements']['defaultnotificationtype'])) {
69 $sql = "SELECT notification_type.notificationTypeID
70 FROM wcf".WCF_N."_package_dependency package_dependency,
71 wcf".WCF_N."_user_notification_type notification_type
72 WHERE notification_type.packageID = package_dependency.dependency
73 AND package_dependency.packageID = ?
74 AND notification_type.notificationType = ?
75 ORDER BY package_dependency.priority DESC";
76 $statement = WCF::getDB()->prepareStatement($sql, 1);
77 $statement->execute(array($this->installation->getPackageID(), $data['elements']['defaultnotificationtype']));
78 $row = $statement->fetchArray();
79 if (empty($row['objectTypeID'])) throw new SystemException("unknown notification type '".$data['elements']['defaultnotificationtype']."' given");
80 $defaultNotificationTypeID = $row['notificationTypeID'];
84 'eventName' => $data['elements']['name'],
85 'className' => $data['elements']['classname'],
86 'objectTypeID' => $objectTypeID,
87 'defaultNotificationTypeID' => $defaultNotificationTypeID,
88 'languageCategory' => (isset($data['elements']['languagecategory']) ? $data['elements']['languagecategory'] : ''),
89 'requiresConfirmation' => (isset($data['elements']['requiresconfirmation']) ? intval($data['elements']['requiresconfirmation']) : 0),
90 'acceptURL' => (isset($data['elements']['accepturl']) ? $data['elements']['accepturl'] : ''),
91 'declineURL' => (isset($data['elements']['declineurl']) ? $data['elements']['declineurl'] : ''),
92 'permissions' => (isset($data['elements']['permissions']) ? $data['elements']['permissions'] : ''),
93 'options' => (isset($data['elements']['options']) ? $data['elements']['options'] : '')
98 * @see AbstractXMLPackageInstallationPlugin::findExistingItem()
100 protected function findExistingItem(array $data) {
102 FROM wcf".WCF_N."_".$this->tableName."
106 $this->installation->getPackageID(),
112 'parameters' => $parameters