Added environment setting for event listener
authorMarcel Werk <burntime@woltlab.com>
Wed, 23 Nov 2011 20:53:50 +0000 (21:53 +0100)
committerMarcel Werk <burntime@woltlab.com>
Wed, 23 Nov 2011 20:53:50 +0000 (21:53 +0100)
com.woltlab.wcf/eventListener.xml
wcfsetup/install/files/lib/system/cache/builder/EventListenerCacheBuilder.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 bfae4e17db4f38c6ec85c6925618af93bf4bb441..ded5c04dcf0e4c3bc8ca702a0c7f9f31cff039f9 100644 (file)
@@ -4,18 +4,21 @@
                <eventlistener>
                        <eventclassname>wcf\page\AbstractPage</eventclassname>
                        <eventname>readParameters</eventname>
+                       <environment>admin</environment>
                        <inherit>1</inherit>
                        <listenerclassname>wcf\system\event\listener\SessionAccessLogListener</listenerclassname>
                </eventlistener>
                <eventlistener>
                        <eventclassname>wcf\form\AbstractForm</eventclassname>
                        <eventname>readParameters</eventname>
+                       <environment>admin</environment>
                        <inherit>1</inherit>
                        <listenerclassname>wcf\system\event\listener\SessionAccessLogListener</listenerclassname>
                </eventlistener>
                <eventlistener>
                        <eventclassname>wcf\action\AbstractAction</eventclassname>
                        <eventname>readParameters</eventname>
+                       <environment>admin</environment>
                        <inherit>1</inherit>
                        <listenerclassname>wcf\system\event\listener\SessionAccessLogListener</listenerclassname>
                </eventlistener>
index 4e44b80c1def6affe8c43b3fbd587cb74a6a77ee..b7d5bef0136986ddbd52ead425f6051c1b24975b 100644 (file)
@@ -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'));
+                               }
                        }
                }
                
index cf802104a71eb15a14e83630ed2dcd814a30010e..f4e2d02929e4b21ad483ecf7fb24cf5cebd18393 100644 (file)
@@ -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);
                
index 6c9256cdc637bc07d21d5d3e1cd1c997c3273d2f..ba6c77ae90b20ed5ebec12d3fc74e7f0dd177b93 100644 (file)
@@ -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(
index 010c0d24a09faa0e92558938e7d2555fad5004f3..7221f33b4d5781ae958edb67e7573e73766593a0 100644 (file)
@@ -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;