Skip to content

Commit

Permalink
MDL-33019: Check that message providers' plugins are enabled and exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruslan Kabalin committed May 23, 2012
1 parent 71d7bc3 commit 7fcd3c3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/messagelib.php
Expand Up @@ -389,7 +389,7 @@ function message_get_providers_for_user($userid) {

$systemcontext = get_context_instance(CONTEXT_SYSTEM);

$providers = $DB->get_records('message_providers', null, 'name');
$providers = get_message_providers();

// Remove all the providers we aren't allowed to see now
foreach ($providers as $providerid => $provider) {
Expand Down
2 changes: 1 addition & 1 deletion message/defaultoutputs.php
Expand Up @@ -34,7 +34,7 @@
// Fetch processors
$processors = get_message_processors(true);
// Fetch message providers
$providers = $DB->get_records('message_providers', null, 'name');
$providers = get_message_providers();

if (($form = data_submitted()) && confirm_sesskey()) {
$preferences = array();
Expand Down
30 changes: 30 additions & 0 deletions message/lib.php
Expand Up @@ -2297,6 +2297,36 @@ function get_message_processors($ready = false) {
return $processors;
}

/**
* Get all message providers, validate their plugin existance and
* system configuration
*
* @return mixed $processors array of objects containing information on message processors
*/
function get_message_providers() {
global $CFG, $DB;
require_once($CFG->libdir . '/pluginlib.php');
$pluginman = plugin_manager::instance();

$providers = $DB->get_records('message_providers', null, 'name');

// Remove all the providers whose plugins are disabled or don't exist
foreach ($providers as $providerid => $provider) {
$plugin = $pluginman->get_plugin_info($provider->component);
if ($plugin) {
if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
unset($providers[$providerid]); // Plugins does not exist
continue;
}
if ($plugin->is_enabled() === false) {
unset($providers[$providerid]); // Plugin disabled
continue;
}
}
}
return $providers;
}

/**
* Get an instance of the message_output class for one of the output plugins.
* @param string $type the message output type. E.g. 'email' or 'jabber'.
Expand Down

0 comments on commit 7fcd3c3

Please sign in to comment.