From: Marcel Werk Date: Wed, 23 Nov 2011 20:53:50 +0000 (+0100) Subject: Added environment setting for event listener X-Git-Tag: 2.0.0_Beta_1~1573 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=7e6405f8a2beffbfcb92e244de4c71b57c6a4729;p=GitHub%2FWoltLab%2FWCF.git Added environment setting for event listener --- diff --git a/com.woltlab.wcf/eventListener.xml b/com.woltlab.wcf/eventListener.xml index bfae4e17db..ded5c04dcf 100644 --- a/com.woltlab.wcf/eventListener.xml +++ b/com.woltlab.wcf/eventListener.xml @@ -4,18 +4,21 @@ wcf\page\AbstractPage readParameters + admin 1 wcf\system\event\listener\SessionAccessLogListener wcf\form\AbstractForm readParameters + admin 1 wcf\system\event\listener\SessionAccessLogListener wcf\action\AbstractAction readParameters + admin 1 wcf\system\event\listener\SessionAccessLogListener 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 4e44b80c1d..b7d5bef013 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/EventListenerCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/EventListenerCacheBuilder.class.php @@ -37,22 +37,26 @@ class EventListenerCacheBuilder implements ICacheBuilder { while ($row = $statement->fetchArray()) { // distinguish between inherited actions and non-inherited actions if (!$row['inherit']) { - $data['actions'][EventHandler::generateKey($row['eventClassName'], $row['eventName'])][] = $row; + $data['actions'][$row['environment']][EventHandler::generateKey($row['eventClassName'], $row['eventName'])][] = $row; } else { - if (!isset($data['inheritedActions'][$row['eventClassName']])) $data['inheritedActions'][$row['eventClassName']] = array(); - $data['inheritedActions'][$row['eventClassName']][$row['eventName']][] = $row; + if (!isset($data['inheritedActions'][$row['environment']][$row['eventClassName']])) $data['inheritedActions'][$row['environment']][$row['eventClassName']] = array(); + $data['inheritedActions'][$row['environment']][$row['eventClassName']][$row['eventName']][] = $row; } } // sort data by nice value and class name - foreach ($data['actions'] as $key => $listeners) { - uasort($data['actions'][$key], array(__CLASS__, 'sortListeners')); + foreach ($data['actions'] as &$listenerMap) { + foreach ($listenerMap as &$listeners) { + uasort($listeners, array(__CLASS__, 'sortListeners')); + } } - foreach ($data['inheritedActions'] as $class => $listeners) { - foreach ($listeners as $key => $val) { - uasort($data['inheritedActions'][$class][$key], array(__CLASS__, 'sortListeners')); + foreach ($data['inheritedActions'] as &$listenerMap) { + foreach ($listenerMap as &$listeners) { + foreach ($listeners as &$val) { + uasort($val, array(__CLASS__, 'sortListeners')); + } } } diff --git a/wcfsetup/install/files/lib/system/event/EventHandler.class.php b/wcfsetup/install/files/lib/system/event/EventHandler.class.php index cf802104a7..f4e2d02929 100644 --- a/wcfsetup/install/files/lib/system/event/EventHandler.class.php +++ b/wcfsetup/install/files/lib/system/event/EventHandler.class.php @@ -50,6 +50,7 @@ class EventHandler extends SingletonFactory { * Loads all registered actions of the active package. */ protected function loadActions() { + $environment = (class_exists('wcf\system\WCFACP', false) ? 'admin' : 'user'); $cacheName = 'eventListener-'.PACKAGE_ID; CacheHandler::getInstance()->addResource( $cacheName, @@ -58,11 +59,11 @@ class EventHandler extends SingletonFactory { ); $cache = CacheHandler::getInstance()->get($cacheName); - if (isset($cache['actions'])) { - $this->actions = $cache['actions']; + if (isset($cache['actions'][$environment])) { + $this->actions = $cache['actions'][$environment]; } - if (isset($cache['inheritedActions'])) { - $this->inheritedActions = $cache['inheritedActions']; + if (isset($cache['inheritedActions'][$environment])) { + $this->inheritedActions = $cache['inheritedActions'][$environment]; } unset($cache); 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 6c9256cdc6..ba6c77ae90 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php @@ -35,6 +35,7 @@ class EventListenerPackageInstallationPlugin extends AbstractXMLPackageInstallat protected function handleDelete(array $items) { $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName." WHERE packageID = ? + AND environment = ? AND eventClassName = ? AND eventName = ?, AND inherit = ? @@ -43,6 +44,7 @@ class EventListenerPackageInstallationPlugin extends AbstractXMLPackageInstallat foreach ($items as $item) { $statement->execute(array( $this->installation->getPackageID(), + (isset($item['elements']['environment']) ? $item['elements']['environment'] : 'user'), $item['elements']['eventclassname'], $item['elements']['eventname'], $item['elements']['inherit'], @@ -60,6 +62,7 @@ class EventListenerPackageInstallationPlugin extends AbstractXMLPackageInstallat else if ($nice > 127) $nice = 127; return array( + 'environment' => (isset($data['elements']['environment']) ? $data['elements']['environment'] : 'user'), 'eventClassName' => $data['elements']['eventclassname'], 'eventName' => $data['elements']['eventname'], 'inherit' => (isset($data['elements']['inherit'])) ? intval($data['elements']['inherit']) : 0, @@ -74,15 +77,17 @@ class EventListenerPackageInstallationPlugin extends AbstractXMLPackageInstallat protected function findExistingItem(array $data) { $sql = "SELECT * FROM wcf".WCF_N."_".$this->tableName." - WHERE eventClassName = ? + WHERE packageID = ? + AND environment = ? + AND eventClassName = ? AND eventName = ? - AND listenerClassName = ? - AND packageID = ?"; + AND listenerClassName = ?"; $parameters = array( + $this->installation->getPackageID(), + $data['environment'], $data['eventClassName'], $data['eventName'], - $data['listenerClassName'], - $this->installation->getPackageID() + $data['listenerClassName'] ); return array( diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 010c0d24a0..7221f33b4d 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -167,12 +167,13 @@ DROP TABLE IF EXISTS wcf1_event_listener; CREATE TABLE wcf1_event_listener ( listenerID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, packageID INT(10) NOT NULL, + environment ENUM('user', 'admin') NOT NULL DEFAULT 'user', eventClassName VARCHAR(80) NOT NULL DEFAULT '', eventName VARCHAR(50) NOT NULL DEFAULT '', listenerClassName VARCHAR(200) NOT NULL DEFAULT '', inherit TINYINT(1) NOT NULL DEFAULT 0, niceValue TINYINT(3) NOT NULL DEFAULT 0, - UNIQUE KEY packageID (packageID, eventClassName, eventName, listenerClassName) + UNIQUE KEY packageID (packageID, environment, eventClassName, eventName, listenerClassName) ); DROP TABLE IF EXISTS wcf1_language;