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 WoltLabSuite\Core\System\Package\Plugin
16 class UserNotificationEventPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin {
20 public $className = UserNotificationEventEditor::class;
25 public $tableName = 'user_notification_event';
30 public $tagName = 'event';
36 protected $presetEventIDs = [];
41 protected function handleDelete(array $items) {
42 $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName."
45 $statement = WCF::getDB()->prepareStatement($sql);
46 foreach ($items as $item) {
48 $this->installation->getPackageID(),
49 $item['elements']['name']
57 protected function prepareImport(array $data) {
59 $sql = "SELECT object_type.objectTypeID
60 FROM wcf".WCF_N."_object_type object_type
61 WHERE object_type.objectType = ?
62 AND object_type.definitionID IN (
64 FROM wcf".WCF_N."_object_type_definition
65 WHERE definitionName = 'com.woltlab.wcf.notification.objectType'
67 $statement = WCF::getDB()->prepareStatement($sql, 1);
68 $statement->execute([$data['elements']['objecttype']]);
69 $row = $statement->fetchArray();
70 if (empty($row['objectTypeID'])) throw new SystemException("unknown notification object type '".$data['elements']['objecttype']."' given");
71 $objectTypeID = $row['objectTypeID'];
73 $presetMailNotificationType = 'none';
74 if (isset($data['elements']['presetmailnotificationtype']) && ($data['elements']['presetmailnotificationtype'] == 'instant' || $data['elements']['presetmailnotificationtype'] == 'daily')) {
75 $presetMailNotificationType = $data['elements']['presetmailnotificationtype'];
79 'eventName' => $data['elements']['name'],
80 'className' => $data['elements']['classname'],
81 'objectTypeID' => $objectTypeID,
82 'permissions' => (isset($data['elements']['permissions']) ? $data['elements']['permissions'] : ''),
83 'options' => (isset($data['elements']['options']) ? $data['elements']['options'] : ''),
84 'preset' => (!empty($data['elements']['preset']) ? 1 : 0),
85 'presetMailNotificationType' => $presetMailNotificationType
92 protected function import(array $row, array $data) {
93 /** @var UserNotificationEvent $event */
94 $event = parent::import($row, $data);
96 if (empty($row) && $data['preset']) {
97 $this->presetEventIDs[$event->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