mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 04:33:13 +01:00
MDL-72720 qbank: Implement enable_plugin() method
This commit is contained in:
parent
14e492bebb
commit
5009021daf
@ -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);
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user