/**
* Caches the event listeners.
*
- * @author Marcel Werk
+ * Important: You cannot use \wcf\data\event\listener\EventListenerLister here as
+ * \wcf\data\DatabaseObjectList fires an event.
+ *
+ * @author Matthias Schmidt, Marcel Werk
* @copyright 2001-2015 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @see \wcf\system\cache\builder\AbstractCacheBuilder::rebuild()
*/
public function rebuild(array $parameters) {
- $data = array(
- 'actions' => array('user' => array(), 'admin' => array()),
- 'inheritedActions' => array('user' => array(), 'admin' => array())
+ $actions = array(
+ 'admin' => array(),
+ 'user' => array()
+ );
+
+ $inheritedActions = array(
+ 'admin' => array(),
+ 'user' => array()
);
- // get all listeners and filter options with low priority
- $sql = "SELECT event_listener.*
- FROM wcf".WCF_N."_event_listener event_listener";
+ $sql = "SELECT *
+ FROM wcf".WCF_N."_event_listener
+ ORDER BY niceValue ASC, listenerClassName ASC";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
- while ($row = $statement->fetchArray()) {
- // distinguish between inherited actions and non-inherited actions
- if (!$row['inherit']) {
- $data['actions'][$row['environment']][EventHandler::generateKey($row['eventClassName'], $row['eventName'])][] = $row;
+ while ($eventListener = $statement->fetchObject('wcf\data\event\listener\EventListener')) {
+ if (!$eventListener->inherit) {
+ if (!isset($actions[$eventListener->environment])) {
+ $actions[$eventListener->environment] = array();
+ }
+
+ $key = EventHandler::generateKey($eventListener->eventClassName, $eventListener->eventName);
+ if (!isset($actions[$eventListener->environment][$key])) {
+ $actions[$eventListener->environment][$key] = array();
+ }
+
+ $actions[$eventListener->environment][$key][] = $eventListener;
}
else {
- 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 &$listenerMap) {
- foreach ($listenerMap as &$listeners) {
- uasort($listeners, array(__CLASS__, 'sortListeners'));
- }
- }
-
- foreach ($data['inheritedActions'] as &$listenerMap) {
- foreach ($listenerMap as &$listeners) {
- foreach ($listeners as &$val) {
- uasort($val, array(__CLASS__, 'sortListeners'));
+ if (!isset($inheritedActions[$eventListener->environment])) {
+ $inheritedActions[$eventListener->environment] = array();
+ }
+
+ if (!isset($inheritedActions[$eventListener->environment][$eventListener->eventClassName])) {
+ $inheritedActions[$eventListener->environment][$eventListener->eventClassName] = array();
}
+
+ $inheritedActions[$eventListener->environment][$eventListener->eventClassName][$eventListener->eventName][] = $eventListener;
}
}
- return $data;
- }
-
- /**
- * Sorts the event listeners by nice value.
- */
- public static function sortListeners($listenerA, $listenerB) {
- if ($listenerA['niceValue'] < $listenerB['niceValue']) {
- return -1;
- }
- else if ($listenerA['niceValue'] > $listenerB['niceValue']) {
- return 1;
- }
- else {
- return strcmp($listenerA['listenerClassName'], $listenerB['listenerClassName']);
- }
+ return array(
+ 'actions' => $actions,
+ 'inheritedActions' => $inheritedActions
+ );
}
}
if (isset($this->inheritedActions[$member])) {
$actions = $this->inheritedActions[$member];
if (isset($actions[$eventName]) && !empty($actions[$eventName])) {
- foreach ($actions[$eventName] as $action) {
- if (isset($this->inheritedActionsObjects[$name][$action['listenerClassName']])) continue;
+ foreach ($actions[$eventName] as $eventListener) {
+ if (isset($this->inheritedActionsObjects[$name][$eventListener->listenerClassName])) continue;
// get class object
- if (isset($this->listenerObjects[$action['listenerClassName']])) {
- $object = $this->listenerObjects[$action['listenerClassName']];
+ if (isset($this->listenerObjects[$eventListener->listenerClassName])) {
+ $object = $this->listenerObjects[$eventListener->listenerClassName];
}
else {
$object = null;
// instance action object
- if (!class_exists($action['listenerClassName'])) {
- throw new SystemException("Unable to find class '".$action['listenerClassName']."'");
+ if (!class_exists($eventListener->listenerClassName)) {
+ throw new SystemException("Unable to find class '".$eventListener->listenerClassName."'");
}
- if (!ClassUtil::isInstanceOf($action['listenerClassName'], 'wcf\system\event\listener\IParameterizedEventListener')) {
+ if (!ClassUtil::isInstanceOf($eventListener->listenerClassName, 'wcf\system\event\listener\IParameterizedEventListener')) {
// legacy event listeners
- if (!ClassUtil::isInstanceOf($action['listenerClassName'], 'wcf\system\event\IEventListener')) {
- throw new SystemException("'".$action['listenerClassName']."' does not implement 'wcf\system\event\listener\IParameterizedEventListener'");
+ if (!ClassUtil::isInstanceOf($eventListener->listenerClassName, 'wcf\system\event\IEventListener')) {
+ throw new SystemException("'".$eventListener->listenerClassName."' does not implement 'wcf\system\event\listener\IParameterizedEventListener'");
}
}
- $object = new $action['listenerClassName'];
- $this->listenerObjects[$action['listenerClassName']] = $object;
+ $object = new $eventListener->listenerClassName;
+ $this->listenerObjects[$eventListener->listenerClassName] = $object;
}
- if ($object !== null) $this->inheritedActionsObjects[$name][$action['listenerClassName']] = $object;
+ if ($object !== null) $this->inheritedActionsObjects[$name][$eventListener->listenerClassName] = $object;
}
}
}
}
$this->actionsObjects[$name] = array();
- foreach ($this->actions[$name] as $action) {
- if (isset($this->actionsObjects[$name][$action['listenerClassName']])) continue;
+ foreach ($this->actions[$name] as $eventListener) {
+ if (isset($this->actionsObjects[$name][$eventListener->listenerClassName])) continue;
// get class object
- if (isset($this->listenerObjects[$action['listenerClassName']])) {
- $object = $this->listenerObjects[$action['listenerClassName']];
+ if (isset($this->listenerObjects[$eventListener->listenerClassName])) {
+ $object = $this->listenerObjects[$eventListener->listenerClassName];
}
else {
// instance action object
- if (!class_exists($action['listenerClassName'])) {
- throw new SystemException("Unable to find class '".$action['listenerClassName']."'");
+ if (!class_exists($eventListener->listenerClassName)) {
+ throw new SystemException("Unable to find class '".$eventListener->listenerClassName."'");
}
- if (!ClassUtil::isInstanceOf($action['listenerClassName'], 'wcf\system\event\listener\IParameterizedEventListener')) {
+ if (!ClassUtil::isInstanceOf($eventListener->listenerClassName, 'wcf\system\event\listener\IParameterizedEventListener')) {
// legacy event listeners
- if (!ClassUtil::isInstanceOf($action['listenerClassName'], 'wcf\system\event\IEventListener')) {
- throw new SystemException("'".$action['listenerClassName']."' does not implement 'wcf\system\event\listener\IParameterizedEventListener'");
+ if (!ClassUtil::isInstanceOf($eventListener->listenerClassName, 'wcf\system\event\IEventListener')) {
+ throw new SystemException("'".$eventListener->listenerClassName."' does not implement 'wcf\system\event\listener\IParameterizedEventListener'");
}
}
- $object = new $action['listenerClassName'];
- $this->listenerObjects[$action['listenerClassName']] = $object;
+ $object = new $eventListener->listenerClassName;
+ $this->listenerObjects[$eventListener->listenerClassName] = $object;
}
- $this->actionsObjects[$name][$action['listenerClassName']] = $object;
+ $this->actionsObjects[$name][$eventListener->listenerClassName] = $object;
}
}