Skip to content

Commit

Permalink
MDL-72720 message: Implement enable_plugin() method
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Oct 15, 2021
1 parent 105be1e commit a7570bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
6 changes: 2 additions & 4 deletions admin/message.php
Expand Up @@ -119,10 +119,8 @@
// Save processors enabled/disabled status.
foreach ($allprocessors as $processor) {
$enabled = isset($form->{$processor->name});
if ($enabled != $processor->enabled) {
add_to_config_log($processor->name, $processor->enabled, $enabled, 'core');
}
\core_message\api::update_processor_status($processor, $enabled);
$class = \core_plugin_manager::resolve_plugininfo_class('message');
$class::enable_plugin($processor->name, $enabled);
}

foreach ($newpreferences as $name => $value) {
Expand Down
24 changes: 24 additions & 0 deletions lib/classes/plugininfo/message.php
Expand Up @@ -40,6 +40,30 @@ public static function get_enabled_plugins() {
return $DB->get_records_menu('message_processors', array('enabled'=>1), 'name ASC', 'name, name AS val');
}

public static function enable_plugin(string $pluginname, int $enabled): bool {
global $DB;

if (!$plugin = $DB->get_record('message_processors', ['name' => $pluginname])) {
throw new \moodle_exception('invalidplugin', 'message', '', $pluginname);
}

$haschanged = false;

// Only set visibility if it's different from the current value.
if ($plugin->enabled != $enabled) {
$haschanged = true;
$processor = \core_message\api::get_processed_processor_object($plugin);

// Include this information into config changes table.
add_to_config_log($processor->name, $processor->enabled, $enabled, 'core');

// Save processor enabled/disabled status.
\core_message\api::update_processor_status($processor, $enabled);
}

return $haschanged;
}

public function get_settings_section_name() {
return 'messagesetting' . $this->name;
}
Expand Down

0 comments on commit a7570bf

Please sign in to comment.