06551cdf2c78c5ed4add0b818435bb85562ffd9b
[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 * Installs, updates and deletes user notification events.
8 *
9 * @author Marcel Werk
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
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 \wcf\system\package\plugin\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 \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::prepareImport()
50 */
51 protected function prepareImport(array $data) {
52 // get object type id
53 $sql = "SELECT object_type.objectTypeID
54 FROM wcf".WCF_N."_object_type object_type
55 WHERE object_type.objectType = ?
56 AND object_type.definitionID IN (
57 SELECT definitionID
58 FROM wcf".WCF_N."_object_type_definition
59 WHERE definitionName = 'com.woltlab.wcf.notification.objectType'
60 )";
61 $statement = WCF::getDB()->prepareStatement($sql, 1);
62 $statement->execute(array($data['elements']['objecttype']));
63 $row = $statement->fetchArray();
64 if (empty($row['objectTypeID'])) throw new SystemException("unknown notification object type '".$data['elements']['objecttype']."' given");
65 $objectTypeID = $row['objectTypeID'];
66
67 return array(
68 'eventName' => $data['elements']['name'],
69 'className' => $data['elements']['classname'],
70 'objectTypeID' => $objectTypeID,
71 'permissions' => (isset($data['elements']['permissions']) ? $data['elements']['permissions'] : ''),
72 'options' => (isset($data['elements']['options']) ? $data['elements']['options'] : ''),
73 'preset' => (!empty($data['elements']['preset']) ? 1 : 0)
74 );
75 }
76
77 /**
78 * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::findExistingItem()
79 */
80 protected function findExistingItem(array $data) {
81 $sql = "SELECT *
82 FROM wcf".WCF_N."_".$this->tableName."
83 WHERE objectTypeID = ?
84 AND eventName = ?";
85 $parameters = array(
86 $data['objectTypeID'],
87 $data['eventName']
88 );
89
90 return array(
91 'sql' => $sql,
92 'parameters' => $parameters
93 );
94 }
95 }