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