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;
7 use wcf\util\StringUtil;
10 * Installs, updates and deletes template listeners.
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
17 class TemplateListenerPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin implements IIdempotentPackageInstallationPlugin {
21 public $className = TemplateListenerEditor::class;
26 protected function handleDelete(array $items) {
27 $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName."
32 AND templateName = ?";
33 $statement = WCF::getDB()->prepareStatement($sql);
34 foreach ($items as $item) {
36 $this->installation->getPackageID(),
37 $item['elements']['environment'],
38 $item['elements']['eventname'],
39 $item['attributes']['name'],
40 $item['elements']['templatename']
48 protected function prepareImport(array $data) {
49 $niceValue = isset($data['elements']['nice']) ? intval($data['elements']['nice']) : 0;
50 if ($niceValue < -128) {
53 else if ($niceValue > 127) {
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']
72 protected function findExistingItem(array $data) {
74 FROM wcf".WCF_N."_".$this->tableName."
81 $this->installation->getPackageID(),
83 $data['templateName'],
90 'parameters' => $parameters
97 protected function cleanup() {
98 // clear cache immediately
99 TemplateListenerCodeCacheBuilder::getInstance()->reset();