From c2e14083712e43bf4f25bb49aeedd3dc93ce278f Mon Sep 17 00:00:00 2001 From: Olaf Braun Date: Mon, 3 Aug 2020 13:34:00 +0200 Subject: [PATCH] Add all environment to event listener (#3145) --- XSD/types.xsd | 1 + .../event/listener/EventListener.class.php | 2 +- .../EventListenerCacheBuilder.class.php | 45 ++++++++++--------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/XSD/types.xsd b/XSD/types.xsd index 497b35cb80..15dcc772d5 100644 --- a/XSD/types.xsd +++ b/XSD/types.xsd @@ -29,6 +29,7 @@ + \ No newline at end of file diff --git a/wcfsetup/install/files/lib/data/event/listener/EventListener.class.php b/wcfsetup/install/files/lib/data/event/listener/EventListener.class.php index c21077b3b9..b5d745b1e3 100644 --- a/wcfsetup/install/files/lib/data/event/listener/EventListener.class.php +++ b/wcfsetup/install/files/lib/data/event/listener/EventListener.class.php @@ -14,7 +14,7 @@ use wcf\data\TDatabaseObjectPermissions; * * @property-read integer $listenerID unique id of the event listener * @property-read integer $packageID id of the package which delivers the event listener - * @property-read string $environment environment in which the event listener is executed, possible values: 'user' or 'admin' + * @property-read string $environment environment in which the event listener is executed, possible values: 'all', 'user' or 'admin' * @property-read string $listenerName name and textual identifier of the event listener * @property-read string $eventClassName name of the class in which the listened event is fired * @property-read string $eventName name of the listened event diff --git a/wcfsetup/install/files/lib/system/cache/builder/EventListenerCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/EventListenerCacheBuilder.class.php index 5ab18451c7..d7ce616d4c 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/EventListenerCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/EventListenerCacheBuilder.class.php @@ -40,32 +40,35 @@ class EventListenerCacheBuilder extends AbstractCacheBuilder { /** @var EventListener $eventListener */ while ($eventListener = $statement->fetchObject(EventListener::class)) { $eventNames = $eventListener->getEventNames(); + $environments = $eventListener->environment == 'all' ? ['admin', 'user'] : [$eventListener->environment]; - if (!$eventListener->inherit) { - if (!isset($actions[$eventListener->environment])) { - $actions[$eventListener->environment] = []; - } - - foreach ($eventNames as $eventName) { - $key = EventHandler::generateKey($eventListener->eventClassName, $eventName); - if (!isset($actions[$eventListener->environment][$key])) { - $actions[$eventListener->environment][$key] = []; + foreach ($environments as $environment) { + if (!$eventListener->inherit) { + if (!isset($actions[$environment])) { + $actions[$environment] = []; } - $actions[$eventListener->environment][$key][] = $eventListener; - } - } - else { - if (!isset($inheritedActions[$eventListener->environment])) { - $inheritedActions[$eventListener->environment] = []; - } - - foreach ($eventNames as $eventName) { - if (!isset($inheritedActions[$eventListener->environment][$eventListener->eventClassName])) { - $inheritedActions[$eventListener->environment][$eventListener->eventClassName] = []; + foreach ($eventNames as $eventName) { + $key = EventHandler::generateKey($eventListener->eventClassName, $eventName); + if (!isset($actions[$environment][$key])) { + $actions[$environment][$key] = []; + } + + $actions[$environment][$key][] = $eventListener; + } + } + else { + if (!isset($inheritedActions[$environment])) { + $inheritedActions[$environment] = []; } - $inheritedActions[$eventListener->environment][$eventListener->eventClassName][$eventName][] = $eventListener; + foreach ($eventNames as $eventName) { + if (!isset($inheritedActions[$environment][$eventListener->eventClassName])) { + $inheritedActions[$environment][$eventListener->eventClassName] = []; + } + + $inheritedActions[$environment][$eventListener->eventClassName][$eventName][] = $eventListener; + } } } } -- 2.20.1