MDL-72720 qbank: Implement enable_plugin() method

This commit is contained in:
Sara Arjona 2021-10-05 12:14:52 +02:00
parent 14e492bebb
commit 5009021daf
2 changed files with 27 additions and 4 deletions

View File

@ -49,16 +49,16 @@ if (!isset($plugins[$name])) {
switch ($action) {
case 'disable':
if ($plugins[$name]->is_enabled()) {
set_config('disabled', 1, 'qbank_'. $name);
$class = \core_plugin_manager::resolve_plugininfo_class('qbank');
$class::enable_plugin($name, false);
}
break;
case 'enable':
if (!$plugins[$name]->is_enabled()) {
unset_config('disabled', 'qbank_'. $name);
$class = \core_plugin_manager::resolve_plugininfo_class('qbank');
$class::enable_plugin($name, true);
}
break;
}
core_plugin_manager::reset_caches();
redirect($return);

View File

@ -85,6 +85,29 @@ class qbank extends base {
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
$haschanged = false;
$plugin = 'qbank_' . $pluginname;
$oldvalue = get_config($plugin, 'disabled');
$disabled = !$enabled;
// Only set value if there is no config setting or if the value is different from the previous one.
if ($oldvalue == false && $disabled) {
set_config('disabled', $disabled, $plugin);
$haschanged = true;
} else if ($oldvalue != false && !$disabled) {
unset_config('disabled', $plugin);
$haschanged = true;
}
if ($haschanged) {
add_to_config_log('disabled', $oldvalue, $disabled, $plugin);
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
/**
* Checks if a qbank plugin is ready to be used.
* It checks the plugin status as well as the plugin is missing or not.