From: Matthias Schmidt Date: Fri, 22 May 2015 06:09:33 +0000 (+0200) Subject: Add permissions and options support for event listeners X-Git-Tag: 3.0.0_Beta_1~2356 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ffdebe9c5b61573ef2350372e4250a1b7910fe43;p=GitHub%2FWoltLab%2FWCF.git Add permissions and options support for event listeners --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a7bfd2442..f0224e10ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. 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 f12c8e9f79..bb64640b4d 100644 --- a/wcfsetup/install/files/lib/data/event/listener/EventListener.class.php +++ b/wcfsetup/install/files/lib/data/event/listener/EventListener.class.php @@ -1,6 +1,8 @@ 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; } } 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 226bde24ff..e2fb08e860 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php @@ -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'] : '') ); } diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 848cdd0556..25464ad078 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -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) );