Commit | Line | Data |
---|---|---|
11ade432 AE |
1 | <?php |
2 | namespace wcf\system\package\plugin; | |
3 | use wcf\system\cache\CacheHandler; | |
4 | use wcf\system\WCF; | |
5 | ||
6 | /** | |
7 | * This PIP installs, updates or deletes event listeners. | |
8 | * | |
9 | * @author Marcel Werk | |
10 | * @copyright 2001-2011 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 EventListenerPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin { | |
17 | /** | |
18 | * @see AbstractXMLPackageInstallationPlugin::$className | |
19 | */ | |
20 | public $className = 'wcf\data\event\listener\EventListenerEditor'; | |
21 | ||
22 | /** | |
23 | * @see AbstractXMLPackageInstallationPlugin::$tableName | |
24 | */ | |
25 | public $tableName = 'event_listener'; | |
26 | ||
27 | /** | |
28 | * @see AbstractXMLPackageInstallationPlugin::$tagName | |
29 | */ | |
30 | public $tagName = 'eventlistener'; | |
31 | ||
32 | /** | |
33 | * @see AbstractXMLPackageInstallationPlugin::handleDelete() | |
34 | */ | |
35 | protected function handleDelete(array $items) { | |
36 | $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName." | |
37 | WHERE packageID = ? | |
38 | AND eventClassName = ? | |
39 | AND eventName = ?, | |
40 | AND inherit = ? | |
41 | AND listenerClassName = ?"; | |
42 | $statement = WCF::getDB()->prepareStatement($sql); | |
43 | foreach ($items as $item) { | |
44 | $statement->execute(array( | |
45 | $this->installation->getPackageID(), | |
46 | $item['elements']['eventclassname'], | |
47 | $item['elements']['eventname'], | |
48 | $item['elements']['inherit'], | |
49 | $item['elements']['listenerclassname'] | |
50 | )); | |
51 | } | |
52 | } | |
53 | ||
54 | /** | |
55 | * @see AbstractXMLPackageInstallationPlugin::prepareImport() | |
56 | */ | |
57 | protected function prepareImport(array $data) { | |
58 | $nice = (isset($data['elements']['nice'])) ? intval($data['elements']['nice']) : 0; | |
59 | if ($nice < -128) $nice = -128; | |
60 | else if ($nice > 127) $nice = 127; | |
61 | ||
62 | return array( | |
63 | 'eventClassName' => $data['elements']['eventclassname'], | |
64 | 'eventName' => $data['elements']['eventname'], | |
65 | 'inherit' => (isset($data['elements']['inherit'])) ? intval($data['elements']['inherit']) : 0, | |
66 | 'listenerClassName' => $data['elements']['listenerclassname'], | |
67 | 'niceValue' => $nice | |
68 | ); | |
69 | } | |
70 | ||
71 | /** | |
72 | * @see AbstractXMLPackageInstallationPlugin::findExistingItem() | |
73 | */ | |
74 | protected function findExistingItem(array $data) { | |
75 | $sql = "SELECT * | |
76 | FROM wcf".WCF_N."_".$this->tableName." | |
77 | WHERE eventClassName = ? | |
78 | AND eventName = ? | |
79 | AND listenerClassName = ? | |
80 | AND packageID = ?"; | |
81 | $parameters = array( | |
82 | $data['eventClassName'], | |
83 | $data['eventName'], | |
84 | $data['listenerClassName'], | |
85 | $this->installation->getPackageID() | |
86 | ); | |
87 | ||
88 | return array( | |
89 | 'sql' => $sql, | |
90 | 'parameters' => $parameters | |
91 | ); | |
92 | } | |
93 | ||
94 | /** | |
95 | * @see PackageInstallationPlugin::uninstall() | |
96 | */ | |
97 | public function uninstall() { | |
98 | parent::uninstall(); | |
99 | ||
100 | // clear cache immediately | |
101 | CacheHandler::getInstance()->clear(WCF_DIR.'cache', 'cache.eventListener-*.php'); | |
102 | } | |
103 | } | |
104 | ?> |