2 namespace wcf\system\package\plugin;
3 use wcf\system\exception\SystemException;
7 * Installs, updates and deletes user notification events.
10 * @copyright 2001-2014 WoltLab GmbH
11 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
12 * @package com.woltlab.wcf
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';
36 protected $presetEventIDs = array();
39 * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::handleDelete()
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) {
47 $statement->execute(array(
48 $this->installation->getPackageID(),
49 $item['elements']['name']
55 * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::prepareImport()
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(array($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
90 * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::import()
92 protected function import(array $row, array $data) {
93 $result = parent::import($row, $data);
95 if (empty($row) && $data['preset']) {
96 $this->presetEventIDs[$result->eventID] = $data['presetMailNotificationType'];
103 * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::cleanup()
105 protected function cleanup() {
106 if (empty($this->presetEventIDs)) return;
108 $sql = "INSERT IGNORE INTO wcf".WCF_N."_user_notification_event_to_user
109 (userID, eventID, mailNotificationType)
111 FROM wcf".WCF_N."_user";
112 $statement = WCF::getDB()->prepareStatement($sql);
113 WCF::getDB()->beginTransaction();
114 foreach ($this->presetEventIDs as $eventID => $mailNotificationType) {
115 $statement->execute(array($eventID, $mailNotificationType));
117 WCF::getDB()->commitTransaction();
121 * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::findExistingItem()
123 protected function findExistingItem(array $data) {
125 FROM wcf".WCF_N."_".$this->tableName."
126 WHERE objectTypeID = ?
129 $data['objectTypeID'],
135 'parameters' => $parameters