942cba1cca4c1a4fe59d058da3a42bb8fbaa5950
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\package\plugin;
3 use wcf\system\exception\SystemException;
4 use wcf\system\WCF;
5
6 /**
7 * This PIP installs, updates or deletes user notification events.
8 *
9 * @author Marcel Werk
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
15 */
16 class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin {
17 /**
18 * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$className
19 */
20 public $className = 'wcf\data\user\notification\event\UserNotificationEventEditor';
21
22 /**
23 * @see wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName
24 */
25 public $tableName = 'user_notification_event';
26
27 /**
28 * @see wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$tagName
29 */
30 public $tagName = 'event';
31
32 /**
33 * @see AbstractXMLPackageInstallationPlugin::handleDelete()
34 */
35 protected function handleDelete(array $items) {
36 $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName."
37 WHERE packageID = ?
38 AND eventName = ?";
39 $statement = WCF::getDB()->prepareStatement($sql);
40 foreach ($items as $item) {
41 $statement->execute(array(
42 $this->installation->getPackageID(),
43 $item['elements']['name']
44 ));
45 }
46 }
47
48 /**
49 * @see AbstractXMLPackageInstallationPlugin::prepareImport()
50 */
51 protected function prepareImport(array $data) {
52 // get object type id
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'];
65
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'];
81 }
82
83 return array(
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'] : '')
94 );
95 }
96
97 /**
98 * @see AbstractXMLPackageInstallationPlugin::findExistingItem()
99 */
100 protected function findExistingItem(array $data) {
101 $sql = "SELECT *
102 FROM wcf".WCF_N."_".$this->tableName."
103 WHERE packageID = ?
104 AND eventName = ?";
105 $parameters = array(
106 $this->installation->getPackageID(),
107 $data['eventName']
108 );
109
110 return array(
111 'sql' => $sql,
112 'parameters' => $parameters
113 );
114 }
115 }