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