Add permissions and options support for event listeners
authorMatthias Schmidt <gravatronics@live.com>
Fri, 22 May 2015 06:09:33 +0000 (08:09 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 22 May 2015 06:09:33 +0000 (08:09 +0200)
CHANGELOG.md
wcfsetup/install/files/lib/data/event/listener/EventListener.class.php
wcfsetup/install/files/lib/system/event/EventHandler.class.php
wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php
wcfsetup/setup/db/install.sql

index 3a7bfd2442306dbab7394e259f9de99c53b15280..f0224e10ac7f081e45bd7cafbf6eb4e369a12fa8 100644 (file)
@@ -4,6 +4,7 @@
 
 ### 2.2.0 Alpha 1 (XXXX-YY-ZZ)
 
-* Add `wcf\data\TDatabaseObjectOptions` and `wcf\data\TDatabaseObjectPermissions` for database object-bound options and permissions validation.
+* `permissions` and `options` support for event listeners.
+* `wcf\data\TDatabaseObjectOptions` and `wcf\data\TDatabaseObjectPermissions` for database object-bound options and permissions validation.
 * `wcf\system\cache\builder\EventListenerCacheBuilder` returns `wcf\data\event\listener\EventListener` objects instead of data arrays.
 
index f12c8e9f7916918397e4d2197d172df098e81519..bb64640b4d3aa1ebcd95abfaed2814a1f4cab95b 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 namespace wcf\data\event\listener;
 use wcf\data\DatabaseObject;
+use wcf\data\TDatabaseObjectOptions;
+use wcf\data\TDatabaseObjectPermissions;
 
 /**
  * Represents an event listener.
@@ -13,6 +15,9 @@ use wcf\data\DatabaseObject;
  * @category   Community Framework
  */
 class EventListener extends DatabaseObject {
+       use TDatabaseObjectOptions;
+       use TDatabaseObjectPermissions;
+       
        /**
         * @see \wcf\data\DatabaseObject::$databaseTableName
         */
index 03e6be53d889377acb39d9c586e76729c3d2e7d5..c66fcbd53f8396dd4474c1d015d0a086f3d4d0c1 100644 (file)
@@ -98,30 +98,32 @@ class EventHandler extends SingletonFactory {
                                        $actions = $this->inheritedActions[$member];
                                        if (isset($actions[$eventName]) && !empty($actions[$eventName])) {
                                                foreach ($actions[$eventName] as $eventListener) {
-                                                       if (isset($this->inheritedActionsObjects[$name][$eventListener->listenerClassName])) continue;
-                                                       
-                                                       // get class object
-                                                       if (isset($this->listenerObjects[$eventListener->listenerClassName])) {
-                                                               $object = $this->listenerObjects[$eventListener->listenerClassName];
-                                                       }
-                                                       else {
-                                                               $object = null;
-                                                               // instance action object
-                                                               if (!class_exists($eventListener->listenerClassName)) {
-                                                                       throw new SystemException("Unable to find class '".$eventListener->listenerClassName."'");
+                                                       if ($eventListener->validateOptions() && $eventListener->validatePermissions()) {
+                                                               if (isset($this->inheritedActionsObjects[$name][$eventListener->listenerClassName])) continue;
+                                                               
+                                                               // get class object
+                                                               if (isset($this->listenerObjects[$eventListener->listenerClassName])) {
+                                                                       $object = $this->listenerObjects[$eventListener->listenerClassName];
                                                                }
-                                                               if (!ClassUtil::isInstanceOf($eventListener->listenerClassName, 'wcf\system\event\listener\IParameterizedEventListener')) {
-                                                                       // legacy event listeners
-                                                                       if (!ClassUtil::isInstanceOf($eventListener->listenerClassName, 'wcf\system\event\IEventListener')) {
-                                                                               throw new SystemException("'".$eventListener->listenerClassName."' does not implement 'wcf\system\event\listener\IParameterizedEventListener'");
+                                                               else {
+                                                                       $object = null;
+                                                                       // instance action object
+                                                                       if (!class_exists($eventListener->listenerClassName)) {
+                                                                               throw new SystemException("Unable to find class '".$eventListener->listenerClassName."'");
+                                                                       }
+                                                                       if (!ClassUtil::isInstanceOf($eventListener->listenerClassName, 'wcf\system\event\listener\IParameterizedEventListener')) {
+                                                                               // legacy event listeners
+                                                                               if (!ClassUtil::isInstanceOf($eventListener->listenerClassName, 'wcf\system\event\IEventListener')) {
+                                                                                       throw new SystemException("'".$eventListener->listenerClassName."' does not implement 'wcf\system\event\listener\IParameterizedEventListener'");
+                                                                               }
                                                                        }
+                                                                       
+                                                                       $object = new $eventListener->listenerClassName;
+                                                                       $this->listenerObjects[$eventListener->listenerClassName] = $object;
                                                                }
                                                                
-                                                               $object = new $eventListener->listenerClassName;
-                                                               $this->listenerObjects[$eventListener->listenerClassName] = $object;
+                                                               if ($object !== null) $this->inheritedActionsObjects[$name][$eventListener->listenerClassName] = $object;
                                                        }
-                                                       
-                                                       if ($object !== null) $this->inheritedActionsObjects[$name][$eventListener->listenerClassName] = $object;
                                                }
                                        }
                                }
@@ -182,29 +184,31 @@ class EventHandler extends SingletonFactory {
                        
                        $this->actionsObjects[$name] = array();
                        foreach ($this->actions[$name] as $eventListener) {
-                               if (isset($this->actionsObjects[$name][$eventListener->listenerClassName])) continue;
-                               
-                               // get class object
-                               if (isset($this->listenerObjects[$eventListener->listenerClassName])) {
-                                       $object = $this->listenerObjects[$eventListener->listenerClassName];
-                               }
-                               else {
-                                       // instance action object
-                                       if (!class_exists($eventListener->listenerClassName)) {
-                                               throw new SystemException("Unable to find class '".$eventListener->listenerClassName."'");
+                               if ($eventListener->validateOptions() && $eventListener->validatePermissions()) {
+                                       if (isset($this->actionsObjects[$name][$eventListener->listenerClassName])) continue;
+                                       
+                                       // get class object
+                                       if (isset($this->listenerObjects[$eventListener->listenerClassName])) {
+                                               $object = $this->listenerObjects[$eventListener->listenerClassName];
                                        }
-                                       if (!ClassUtil::isInstanceOf($eventListener->listenerClassName, 'wcf\system\event\listener\IParameterizedEventListener')) {
-                                               // legacy event listeners
-                                               if (!ClassUtil::isInstanceOf($eventListener->listenerClassName, 'wcf\system\event\IEventListener')) {
-                                                       throw new SystemException("'".$eventListener->listenerClassName."' does not implement 'wcf\system\event\listener\IParameterizedEventListener'");
+                                       else {
+                                               // instance action object
+                                               if (!class_exists($eventListener->listenerClassName)) {
+                                                       throw new SystemException("Unable to find class '".$eventListener->listenerClassName."'");
+                                               }
+                                               if (!ClassUtil::isInstanceOf($eventListener->listenerClassName, 'wcf\system\event\listener\IParameterizedEventListener')) {
+                                                       // legacy event listeners
+                                                       if (!ClassUtil::isInstanceOf($eventListener->listenerClassName, 'wcf\system\event\IEventListener')) {
+                                                               throw new SystemException("'".$eventListener->listenerClassName."' does not implement 'wcf\system\event\listener\IParameterizedEventListener'");
+                                                       }
                                                }
+                                               
+                                               $object = new $eventListener->listenerClassName;
+                                               $this->listenerObjects[$eventListener->listenerClassName] = $object;
                                        }
                                        
-                                       $object = new $eventListener->listenerClassName;
-                                       $this->listenerObjects[$eventListener->listenerClassName] = $object;
+                                       $this->actionsObjects[$name][$eventListener->listenerClassName] = $object;
                                }
-                               
-                               $this->actionsObjects[$name][$eventListener->listenerClassName] = $object;
                        }
                }
                
index 226bde24ffc9b6fe5334aeadd4e476d0d3fa106f..e2fb08e86057807b0a851e63208691d63ef4a98e 100644 (file)
@@ -62,7 +62,9 @@ class EventListenerPackageInstallationPlugin extends AbstractXMLPackageInstallat
                        'eventName' => $data['elements']['eventname'],
                        'inherit' => (isset($data['elements']['inherit'])) ? intval($data['elements']['inherit']) : 0,
                        'listenerClassName' => $data['elements']['listenerclassname'],
-                       'niceValue' => $nice
+                       'niceValue' => $nice,
+                       'options' => (isset($data['elements']['options']) ? $data['elements']['options'] : ''),
+                       'permissions' => (isset($data['elements']['permissions']) ? $data['elements']['permissions'] : '')
                );
        }
        
index 848cdd055694f9963d58db0ee6611b955419c6ac..25464ad0788a22e723d6336f790a23489d70c946 100644 (file)
@@ -377,6 +377,9 @@ CREATE TABLE wcf1_event_listener (
        listenerClassName VARCHAR(200) NOT NULL DEFAULT '',
        inherit TINYINT(1) NOT NULL DEFAULT 0,
        niceValue TINYINT(3) NOT NULL DEFAULT 0,
+       permissions TEXT,
+       options TEXT,
+       
        UNIQUE KEY packageID (packageID, environment, eventClassName, eventName, listenerClassName)
 );