151f2cde94ee1ee5761208e409865a65c1c237e5
[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\devtools\pip\IIdempotentPackageInstallationPlugin;
6 use wcf\system\WCF;
7 use wcf\util\StringUtil;
8
9 /**
10 * Installs, updates and deletes template listeners.
11 *
12 * @author Alexander Ebert
13 * @copyright 2001-2017 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\System\Package\Plugin
16 */
17 class TemplateListenerPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin implements IIdempotentPackageInstallationPlugin {
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']) ? StringUtil::normalizeCsv($data['elements']['options']) : '',
63 'permissions' => isset($data['elements']['permissions']) ? StringUtil::normalizeCsv($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
102 /**
103 * @inheritDoc
104 */
105 public static function getSyncDependencies() {
106 return [];
107 }
108 }