ea7b2ec6b8d31728b5fa359f97411b370a9c1482
[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 WoltLabSuite\Core\System\Package\Plugin
14 */
15 class TemplateListenerPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin {
16 /**
17 * @inheritDoc
18 */
19 public $className = TemplateListenerEditor::class;
20
21 /**
22 * @inheritDoc
23 */
24 protected function handleDelete(array $items) {
25 $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName."
26 WHERE packageID = ?
27 AND environment = ?
28 AND eventName = ?
29 AND name = ?
30 AND templateName = ?";
31 $statement = WCF::getDB()->prepareStatement($sql);
32 foreach ($items as $item) {
33 $statement->execute([
34 $this->installation->getPackageID(),
35 $item['elements']['environment'],
36 $item['elements']['eventname'],
37 $item['attributes']['name'],
38 $item['elements']['templatename']
39 ]);
40 }
41 }
42
43 /**
44 * @inheritDoc
45 */
46 protected function prepareImport(array $data) {
47 $niceValue = isset($data['elements']['nice']) ? intval($data['elements']['nice']) : 0;
48 if ($niceValue < -128) {
49 $niceValue = -128;
50 }
51 else if ($niceValue > 127) {
52 $niceValue = 127;
53 }
54
55 return [
56 'environment' => $data['elements']['environment'],
57 'eventName' => $data['elements']['eventname'],
58 'niceValue' => $niceValue,
59 'name' => $data['attributes']['name'],
60 'options' => (isset($data['elements']['options']) ? $data['elements']['options'] : ''),
61 'permissions' => (isset($data['elements']['permissions']) ? $data['elements']['permissions'] : ''),
62 'templateCode' => $data['elements']['templatecode'],
63 'templateName' => $data['elements']['templatename']
64 ];
65 }
66
67 /**
68 * @inheritDoc
69 */
70 protected function findExistingItem(array $data) {
71 $sql = "SELECT *
72 FROM wcf".WCF_N."_".$this->tableName."
73 WHERE packageID = ?
74 AND name = ?
75 AND templateName = ?
76 AND eventName = ?
77 AND environment = ?";
78 $parameters = [
79 $this->installation->getPackageID(),
80 $data['name'],
81 $data['templateName'],
82 $data['eventName'],
83 $data['environment']
84 ];
85
86 return [
87 'sql' => $sql,
88 'parameters' => $parameters
89 ];
90 }
91
92 /**
93 * @inheritDoc
94 */
95 protected function cleanup() {
96 // clear cache immediately
97 TemplateListenerCodeCacheBuilder::getInstance()->reset();
98 }
99 }