Add all environment to event listener (#3145)
authorOlaf Braun <info@braun-development.de>
Mon, 3 Aug 2020 11:34:00 +0000 (13:34 +0200)
committerGitHub <noreply@github.com>
Mon, 3 Aug 2020 11:34:00 +0000 (13:34 +0200)
XSD/types.xsd
wcfsetup/install/files/lib/data/event/listener/EventListener.class.php
wcfsetup/install/files/lib/system/cache/builder/EventListenerCacheBuilder.class.php

index 497b35cb8029d406f4ca54ec30523fdfb8cf65f5..15dcc772d56ffabad657e6c7a4678b6771b278cf 100644 (file)
@@ -29,6 +29,7 @@
                <xs:restriction base="xs:string">
                        <xs:enumeration value="user" />
                        <xs:enumeration value="admin" />
+                       <xs:enumeration value="all" />
                </xs:restriction>
        </xs:simpleType>
 </xs:schema>
\ No newline at end of file
index c21077b3b916914e7b08958b4555d0f2ad14900a..b5d745b1e342043fd7827c6135052ee242a0d6a5 100644 (file)
@@ -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
index 5ab18451c7aea32c0ab743350573a978fac9ac6c..d7ce616d4c0f16d619b118ecd717d76f05ea65db 100644 (file)
@@ -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;
+                                       }
                                }
                        }
                }