From bc538e1ccb39299f307f432823671f1e2c0b826f Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 7 Jun 2021 14:13:48 +0200 Subject: [PATCH] Make event listeners' `eventname` default to `:default` (#4265) See #4000 --- XSD/eventListener.xsd | 2 +- ...istenerPackageInstallationPlugin.class.php | 21 ++++++++++++++----- wcfsetup/install/lang/de.xml | 2 +- wcfsetup/install/lang/en.xml | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/XSD/eventListener.xsd b/XSD/eventListener.xsd index ccda8530ab..18ac9b15ba 100644 --- a/XSD/eventListener.xsd +++ b/XSD/eventListener.xsd @@ -39,7 +39,7 @@ - + diff --git a/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php index 9fa4c50012..5506fb61cb 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php @@ -9,6 +9,7 @@ use wcf\system\cache\builder\EventListenerCacheBuilder; use wcf\system\devtools\pip\IDevtoolsPipEntryList; use wcf\system\devtools\pip\IGuiPackageInstallationPlugin; use wcf\system\devtools\pip\TXmlGuiPackageInstallationPlugin; +use wcf\system\event\EventHandler; use wcf\system\event\listener\IParameterizedEventListener; use wcf\system\form\builder\container\FormContainer; use wcf\system\form\builder\field\BooleanFormField; @@ -98,10 +99,15 @@ class EventListenerPackageInstallationPlugin extends AbstractXMLPackageInstallat $nice = 127; } + $eventName = EventHandler::DEFAULT_EVENT_NAME; + if (!empty($data['elements']['eventname'])) { + $eventName = StringUtil::normalizeCsv($data['elements']['eventname']); + } + return [ 'environment' => $data['elements']['environment'] ?? 'user', 'eventClassName' => $data['elements']['eventclassname'], - 'eventName' => StringUtil::normalizeCsv($data['elements']['eventname']), + 'eventName' => $eventName, 'inherit' => isset($data['elements']['inherit']) ? \intval($data['elements']['inherit']) : 0, 'listenerClassName' => $data['elements']['listenerclassname'], 'listenerName' => $data['attributes']['name'] ?? '', @@ -252,8 +258,7 @@ class EventListenerPackageInstallationPlugin extends AbstractXMLPackageInstallat ItemListFormField::create('eventName') ->objectProperty('eventname') ->label('wcf.acp.pip.eventListener.eventName') - ->description('wcf.acp.pip.eventListener.eventName.description') - ->required(), + ->description('wcf.acp.pip.eventListener.eventName.description'), ClassNameFormField::create('listenerClassName') ->objectProperty('listenerclassname') @@ -305,9 +310,15 @@ class EventListenerPackageInstallationPlugin extends AbstractXMLPackageInstallat */ protected function fetchElementData(\DOMElement $element, $saveData) { + $eventName = EventHandler::DEFAULT_EVENT_NAME; + $eventNameElements = $element->getElementsByTagName('eventname'); + if ($eventNameElements->length) { + $eventName = StringUtil::normalizeCsv($eventNameElements->item(0)->nodeValue); + } + $data = [ 'eventClassName' => $element->getElementsByTagName('eventclassname')->item(0)->nodeValue, - 'eventName' => StringUtil::normalizeCsv($element->getElementsByTagName('eventname')->item(0)->nodeValue), + 'eventName' => $eventName, 'listenerClassName' => $element->getElementsByTagName('listenerclassname')->item(0)->nodeValue, 'listenerName' => $element->getAttribute('name'), 'packageID' => $this->installation->getPackage()->packageID, @@ -382,7 +393,7 @@ class EventListenerPackageInstallationPlugin extends AbstractXMLPackageInstallat $eventListener, [ 'eventclassname', - 'eventname', + 'eventname' => '', 'listenerclassname', 'environment' => 'user', 'inherit' => 0, diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 5aad336b12..2f96b207b6 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -2387,7 +2387,7 @@ Die Datenbestände werden sorgfältig gepflegt, aber es ist nicht ausgeschlossen - + :default]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 5e9d5c7aac..57a335c617 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -2375,7 +2375,7 @@ If you have already bought the licenses for the listed apps, th - + :default]]> user), the ACP (admin), or in both (all).]]> -- 2.20.1