2 namespace wcf\system\package\plugin;
3 use wcf\data\user\notification\event\UserNotificationEvent;
4 use wcf\data\user\notification\event\UserNotificationEventEditor;
5 use wcf\system\exception\SystemException;
9 * Installs, updates and deletes user notification events.
12 * @copyright 2001-2016 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package com.woltlab.wcf
15 * @subpackage system.package.plugin
16 * @category Community Framework
18 class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin {
22 public $className = UserNotificationEventEditor::class;
27 public $tableName = 'user_notification_event';
32 public $tagName = 'event';
38 protected $presetEventIDs = [];
43 protected function handleDelete(array $items) {
44 $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName."
47 $statement = WCF::getDB()->prepareStatement($sql);
48 foreach ($items as $item) {
50 $this->installation->getPackageID(),
51 $item['elements']['name']
59 protected function prepareImport(array $data) {
61 $sql = "SELECT object_type.objectTypeID
62 FROM wcf".WCF_N."_object_type object_type
63 WHERE object_type.objectType = ?
64 AND object_type.definitionID IN (
66 FROM wcf".WCF_N."_object_type_definition
67 WHERE definitionName = 'com.woltlab.wcf.notification.objectType'
69 $statement = WCF::getDB()->prepareStatement($sql, 1);
70 $statement->execute([$data['elements']['objecttype']]);
71 $row = $statement->fetchArray();
72 if (empty($row['objectTypeID'])) throw new SystemException("unknown notification object type '".$data['elements']['objecttype']."' given");
73 $objectTypeID = $row['objectTypeID'];
75 $presetMailNotificationType = 'none';
76 if (isset($data['elements']['presetmailnotificationtype']) && ($data['elements']['presetmailnotificationtype'] == 'instant' || $data['elements']['presetmailnotificationtype'] == 'daily')) {
77 $presetMailNotificationType = $data['elements']['presetmailnotificationtype'];
81 'eventName' => $data['elements']['name'],
82 'className' => $data['elements']['classname'],
83 'objectTypeID' => $objectTypeID,
84 'permissions' => (isset($data['elements']['permissions']) ? $data['elements']['permissions'] : ''),
85 'options' => (isset($data['elements']['options']) ? $data['elements']['options'] : ''),
86 'preset' => (!empty($data['elements']['preset']) ? 1 : 0),
87 'presetMailNotificationType' => $presetMailNotificationType
94 protected function import(array $row, array $data) {
95 /** @var UserNotificationEvent $event */
96 $event = parent::import($row, $data);
98 if (empty($row) && $data['preset']) {
99 $this->presetEventIDs[$event->eventID] = $data['presetMailNotificationType'];
108 protected function cleanup() {
109 if (empty($this->presetEventIDs)) return;
111 $sql = "INSERT IGNORE INTO wcf".WCF_N."_user_notification_event_to_user
112 (userID, eventID, mailNotificationType)
114 FROM wcf".WCF_N."_user";
115 $statement = WCF::getDB()->prepareStatement($sql);
116 WCF::getDB()->beginTransaction();
117 foreach ($this->presetEventIDs as $eventID => $mailNotificationType) {
118 $statement->execute([$eventID, $mailNotificationType]);
120 WCF::getDB()->commitTransaction();
126 protected function findExistingItem(array $data) {
128 FROM wcf".WCF_N."_".$this->tableName."
129 WHERE objectTypeID = ?
132 $data['objectTypeID'],
138 'parameters' => $parameters