d9265bbe49f45c381894cb8c190d61056ae738b9
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\package\plugin;
3 use wcf\system\cache\builder\TemplateListenerCacheBuilder;
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-2014 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 * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::$className
20 */
21 public $className = 'wcf\data\template\listener\TemplateListenerEditor';
22
23 /**
24 * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::handleDelete()
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(array(
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 * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::prepareImport()
47 */
48 protected function prepareImport(array $data) {
49 return array(
50 'environment' => $data['elements']['environment'],
51 'eventName' => $data['elements']['eventname'],
52 'name' => $data['attributes']['name'],
53 'templateCode' => $data['elements']['templatecode'],
54 'templateName' => $data['elements']['templatename']
55 );
56 }
57
58 /**
59 * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::findExistingItem()
60 */
61 protected function findExistingItem(array $data) {
62 $sql = "SELECT *
63 FROM wcf".WCF_N."_".$this->tableName."
64 WHERE packageID = ?
65 AND name = ?
66 AND templateName = ?
67 AND eventName = ?
68 AND environment = ?";
69 $parameters = array(
70 $this->installation->getPackageID(),
71 $data['name'],
72 $data['templateName'],
73 $data['eventName'],
74 $data['environment']
75 );
76
77 return array(
78 'sql' => $sql,
79 'parameters' => $parameters
80 );
81 }
82
83 /**
84 * @see \wcf\system\package\plugin\AbstractXMLPackageInstallationPlugin::cleanup()
85 */
86 protected function cleanup() {
87 // clear cache immediately
88 TemplateListenerCacheBuilder::getInstance()->reset();
89 TemplateListenerCodeCacheBuilder::getInstance()->reset();
90 }
91 }