Skip to content

Commit

Permalink
MDL-45216 events: Update to core/event/manager to return observer inf…
Browse files Browse the repository at this point in the history
…ormation.
  • Loading branch information
abgreeve committed Apr 23, 2014
1 parent e471fc6 commit 1b9fb2e
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions lib/classes/event/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,16 @@ protected static function init_all_observers() {
self::$allobservers = array();

$plugintypes = \core_component::get_plugin_types();
$plugintypes = array_merge(array('core' => 'not used'), $plugintypes);
$systemdone = false;
foreach ($plugintypes as $plugintype => $ignored) {
$plugins = \core_component::get_plugin_list($plugintype);
if (!$systemdone) {
$plugins[] = "$CFG->dirroot/lib";
$systemdone = true;
if ($plugintype === 'core') {
$plugins['core'] = "$CFG->dirroot/lib";
} else {
$plugins = \core_component::get_plugin_list($plugintype);
}

foreach ($plugins as $fulldir) {
foreach ($plugins as $plugin => $fulldir) {
if (!file_exists("$fulldir/db/events.php")) {
continue;
}
Expand All @@ -232,7 +233,7 @@ protected static function init_all_observers() {
if (!is_array($observers)) {
continue;
}
self::add_observers($observers, "$fulldir/db/events.php");
self::add_observers($observers, "$fulldir/db/events.php", $plugintype, $plugin);
}
}

Expand All @@ -248,8 +249,10 @@ protected static function init_all_observers() {
* Add observers.
* @param array $observers
* @param string $file
* @param string $plugintype Plugin type of the observer.
* @param string $plugin Plugin of the observer.
*/
protected static function add_observers(array $observers, $file) {
protected static function add_observers(array $observers, $file, $plugintype = null, $plugin = null) {
global $CFG;

foreach ($observers as $observer) {
Expand Down Expand Up @@ -292,6 +295,8 @@ protected static function add_observers(array $observers, $file) {
}
$o->includefile = $observer['includefile'];
}
$o->plugintype = $plugintype;
$o->plugin = $plugin;
self::$allobservers[$observer['eventname']][] = $o;
}
}
Expand All @@ -306,6 +311,17 @@ protected static function order_all_observers() {
}
}

/**
* Returns all observers in the system. This is only for use for reporting on the list of observers in the system.
*
* @access private
* @return array An array of stdClass with all core observer details.
*/
public static function get_all_observers() {
self::init_all_observers();
return self::$allobservers;
}

/**
* Replace all standard observers.
* @param array $observers
Expand Down

0 comments on commit 1b9fb2e

Please sign in to comment.