Commit | Line | Data |
---|---|---|
11ade432 AE |
1 | <?php |
2 | namespace wcf\system\package\plugin; | |
f1dc282d | 3 | use wcf\system\cache\builder\TemplateListenerCodeCacheBuilder; |
11ade432 AE |
4 | use wcf\system\WCF; |
5 | ||
6 | /** | |
a17de04e | 7 | * Installs, updates and deletes template listeners. |
11ade432 AE |
8 | * |
9 | * @author Alexander Ebert | |
ca4ba303 | 10 | * @copyright 2001-2014 WoltLab GmbH |
11ade432 AE |
11 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
12 | * @package com.woltlab.wcf | |
13 | * @subpackage system.package.plugin | |
9f959ced | 14 | * @category Community Framework |
11ade432 AE |
15 | */ |
16 | class TemplateListenerPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin { | |
17 | /** | |
0ad90fc3 | 18 | * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$className |
11ade432 AE |
19 | */ |
20 | public $className = 'wcf\data\template\listener\TemplateListenerEditor'; | |
21 | ||
11ade432 | 22 | /** |
0ad90fc3 | 23 | * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::handleDelete() |
11ade432 AE |
24 | */ |
25 | protected function handleDelete(array $items) { | |
26 | $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName." | |
27 | WHERE packageID = ? | |
28 | AND environment = ? | |
29 | AND eventName = ? | |
30 | AND name = ? | |
31 | AND templateName = ?"; | |
32 | $statement = WCF::getDB()->prepareStatement($sql); | |
33 | foreach ($items as $item) { | |
34 | $statement->execute(array( | |
35 | $this->installation->getPackageID(), | |
36 | $item['elements']['environment'], | |
37 | $item['elements']['eventname'], | |
38 | $item['attributes']['name'], | |
39 | $item['elements']['templatename'] | |
40 | )); | |
41 | } | |
42 | } | |
43 | ||
44 | /** | |
0ad90fc3 | 45 | * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::prepareImport() |
11ade432 AE |
46 | */ |
47 | protected function prepareImport(array $data) { | |
da84cf75 MS |
48 | $niceValue = isset($data['elements']['nice']) ? intval($data['elements']['nice']) : 0; |
49 | if ($niceValue < -128) { | |
50 | $niceValue = -128; | |
51 | } | |
52 | else if ($niceValue > 127) { | |
53 | $niceValue = 127; | |
54 | } | |
55 | ||
11ade432 AE |
56 | return array( |
57 | 'environment' => $data['elements']['environment'], | |
58 | 'eventName' => $data['elements']['eventname'], | |
da84cf75 | 59 | 'niceValue' => $niceValue, |
11ade432 AE |
60 | 'name' => $data['attributes']['name'], |
61 | 'templateCode' => $data['elements']['templatecode'], | |
62 | 'templateName' => $data['elements']['templatename'] | |
63 | ); | |
64 | } | |
65 | ||
66 | /** | |
0ad90fc3 | 67 | * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::findExistingItem() |
11ade432 AE |
68 | */ |
69 | protected function findExistingItem(array $data) { | |
70 | $sql = "SELECT * | |
71 | FROM wcf".WCF_N."_".$this->tableName." | |
72 | WHERE packageID = ? | |
73 | AND name = ? | |
74 | AND templateName = ? | |
75 | AND eventName = ? | |
76 | AND environment = ?"; | |
77 | $parameters = array( | |
78 | $this->installation->getPackageID(), | |
79 | $data['name'], | |
80 | $data['templateName'], | |
81 | $data['eventName'], | |
82 | $data['environment'] | |
83 | ); | |
84 | ||
85 | return array( | |
86 | 'sql' => $sql, | |
87 | 'parameters' => $parameters | |
88 | ); | |
89 | } | |
90 | ||
11ade432 | 91 | /** |
0ad90fc3 | 92 | * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::cleanup() |
a17de04e | 93 | */ |
11ade432 AE |
94 | protected function cleanup() { |
95 | // clear cache immediately | |
b401cd0d | 96 | TemplateListenerCodeCacheBuilder::getInstance()->reset(); |
11ade432 AE |
97 | } |
98 | } |