d424c53da5a9295c95c547b958814e7d3e6cb5ae
[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 use wcf\util\StringUtil;
7
8 /**
9 * Installs, updates and deletes template listeners.
10 *
11 * @author Alexander Ebert
12 * @copyright 2001-2017 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package WoltLabSuite\Core\System\Package\Plugin
15 */
16 class TemplateListenerPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin {
17 /**
18 * @inheritDoc
19 */
20 public $className = TemplateListenerEditor::class;
21
22 /**
23 * @inheritDoc
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([
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 /**
45 * @inheritDoc
46 */
47 protected function prepareImport(array $data) {
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
56 return [
57 'environment' => $data['elements']['environment'],
58 'eventName' => $data['elements']['eventname'],
59 'niceValue' => $niceValue,
60 'name' => $data['attributes']['name'],
61 'options' => isset($data['elements']['options']) ? StringUtil::normalizeCsv($data['elements']['options']) : '',
62 'permissions' => isset($data['elements']['permissions']) ? StringUtil::normalizeCsv($data['elements']['permissions']) : '',
63 'templateCode' => $data['elements']['templatecode'],
64 'templateName' => $data['elements']['templatename']
65 ];
66 }
67
68 /**
69 * @inheritDoc
70 */
71 protected function findExistingItem(array $data) {
72 $sql = "SELECT *
73 FROM wcf".WCF_N."_".$this->tableName."
74 WHERE packageID = ?
75 AND name = ?
76 AND templateName = ?
77 AND eventName = ?
78 AND environment = ?";
79 $parameters = [
80 $this->installation->getPackageID(),
81 $data['name'],
82 $data['templateName'],
83 $data['eventName'],
84 $data['environment']
85 ];
86
87 return [
88 'sql' => $sql,
89 'parameters' => $parameters
90 ];
91 }
92
93 /**
94 * @inheritDoc
95 */
96 protected function cleanup() {
97 // clear cache immediately
98 TemplateListenerCodeCacheBuilder::getInstance()->reset();
99 }
100 }