2 namespace wcf\system\package\plugin;
3 use wcf\data\user\notification\event\UserNotificationEventEditor;
4 use wcf\system\exception\SystemException;
8 * Installs, updates and deletes user notification events.
11 * @copyright 2001-2016 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package com.woltlab.wcf
14 * @subpackage system.package.plugin
15 * @category Community Framework
17 class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin {
21 public $className = UserNotificationEventEditor::class;
26 public $tableName = 'user_notification_event';
31 public $tagName = 'event';
37 protected $presetEventIDs = [];
42 protected function handleDelete(array $items) {
43 $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName."
46 $statement = WCF::getDB()->prepareStatement($sql);
47 foreach ($items as $item) {
49 $this->installation->getPackageID(),
50 $item['elements']['name']
58 protected function prepareImport(array $data) {
60 $sql = "SELECT object_type.objectTypeID
61 FROM wcf".WCF_N."_object_type object_type
62 WHERE object_type.objectType = ?
63 AND object_type.definitionID IN (
65 FROM wcf".WCF_N."_object_type_definition
66 WHERE definitionName = 'com.woltlab.wcf.notification.objectType'
68 $statement = WCF::getDB()->prepareStatement($sql, 1);
69 $statement->execute([$data['elements']['objecttype']]);
70 $row = $statement->fetchArray();
71 if (empty($row['objectTypeID'])) throw new SystemException("unknown notification object type '".$data['elements']['objecttype']."' given");
72 $objectTypeID = $row['objectTypeID'];
74 $presetMailNotificationType = 'none';
75 if (isset($data['elements']['presetmailnotificationtype']) && ($data['elements']['presetmailnotificationtype'] == 'instant' || $data['elements']['presetmailnotificationtype'] == 'daily')) {
76 $presetMailNotificationType = $data['elements']['presetmailnotificationtype'];
80 'eventName' => $data['elements']['name'],
81 'className' => $data['elements']['classname'],
82 'objectTypeID' => $objectTypeID,
83 'permissions' => (isset($data['elements']['permissions']) ? $data['elements']['permissions'] : ''),
84 'options' => (isset($data['elements']['options']) ? $data['elements']['options'] : ''),
85 'preset' => (!empty($data['elements']['preset']) ? 1 : 0),
86 'presetMailNotificationType' => $presetMailNotificationType
93 protected function import(array $row, array $data) {
94 $result = parent::import($row, $data);
96 if (empty($row) && $data['preset']) {
97 $this->presetEventIDs[$result->eventID] = $data['presetMailNotificationType'];
106 protected function cleanup() {
107 if (empty($this->presetEventIDs)) return;
109 $sql = "INSERT IGNORE INTO wcf".WCF_N."_user_notification_event_to_user
110 (userID, eventID, mailNotificationType)
112 FROM wcf".WCF_N."_user";
113 $statement = WCF::getDB()->prepareStatement($sql);
114 WCF::getDB()->beginTransaction();
115 foreach ($this->presetEventIDs as $eventID => $mailNotificationType) {
116 $statement->execute([$eventID, $mailNotificationType]);
118 WCF::getDB()->commitTransaction();
124 protected function findExistingItem(array $data) {
126 FROM wcf".WCF_N."_".$this->tableName."
127 WHERE objectTypeID = ?
130 $data['objectTypeID'],
136 'parameters' => $parameters