a3d512dbfbe9c6180f3ae374703f8e09c2951443
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\package\plugin;
3 use wcf\system\cache\CacheHandler;
4 use wcf\system\WCF;
5
6 /**
7 * This PIP installs, updates or deletes template listeners.
8 *
9 * @author Alexander Ebert
10 * @copyright 2001-2011 WoltLab GmbH
11 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
12 * @package com.woltlab.wcf
13 * @subpackage system.package.plugin
14 * @category Community Framework
15 */
16 class TemplateListenerPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin {
17 /**
18 * @see AbstractXMLPackageInstallationPlugin::$className
19 */
20 public $className = 'wcf\data\template\listener\TemplateListenerEditor';
21
22 /**
23 * @see AbstractXMLPackageInstallationPlugin::$tableName
24 */
25 public $tableName = 'template_listener';
26
27 /**
28 * @see AbstractXMLPackageInstallationPlugin::$tagName
29 */
30 public $tagName = 'templatelistener';
31
32 /**
33 * @see AbstractXMLPackageInstallationPlugin::handleDelete()
34 */
35 protected function handleDelete(array $items) {
36 $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName."
37 WHERE packageID = ?
38 AND environment = ?
39 AND eventName = ?
40 AND name = ?
41 AND templateName = ?";
42 $statement = WCF::getDB()->prepareStatement($sql);
43 foreach ($items as $item) {
44 $statement->execute(array(
45 $this->installation->getPackageID(),
46 $item['elements']['environment'],
47 $item['elements']['eventname'],
48 $item['attributes']['name'],
49 $item['elements']['templatename']
50 ));
51 }
52 }
53
54 /**
55 * @see AbstractXMLPackageInstallationPlugin::prepareImport()
56 */
57 protected function prepareImport(array $data) {
58 return array(
59 'environment' => $data['elements']['environment'],
60 'eventName' => $data['elements']['eventname'],
61 'name' => $data['attributes']['name'],
62 'templateCode' => $data['elements']['templatecode'],
63 'templateName' => $data['elements']['templatename']
64 );
65 }
66
67 /**
68 * @see AbstractXMLPackageInstallationPlugin::findExistingItem()
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 = array(
79 $this->installation->getPackageID(),
80 $data['name'],
81 $data['templateName'],
82 $data['eventName'],
83 $data['environment']
84 );
85
86 return array(
87 'sql' => $sql,
88 'parameters' => $parameters
89 );
90 }
91
92 /**
93 * @see PackageInstallationPlugin::uninstall()
94 */
95 public function uninstall() {
96 parent::uninstall();
97
98 $this->cleanup();
99 }
100
101 /**
102 * @see AbstractXMLPackageInstallationPlugin::cleanup()
103 */
104 protected function cleanup() {
105 // clear cache immediately
106 CacheHandler::getInstance()->clear(WCF_DIR.'cache', 'cache.templateListener-*.php');
107 CacheHandler::getInstance()->clear(WCF_DIR.'cache/templateListener', '*.php');
108 }
109 }