MDL-72720 qbehaviour: Implement enable_plugin() method
This commit is contained in:
@@ -88,10 +88,9 @@ if (($disable = optional_param('disable', '', PARAM_PLUGIN)) && confirm_sesskey(
|
||||
}
|
||||
|
||||
if (array_search($disable, $disabledbehaviours) === false) {
|
||||
$disabledbehaviours[] = $disable;
|
||||
set_config('disabledbehaviours', implode(',', $disabledbehaviours), 'question');
|
||||
$class = \core_plugin_manager::resolve_plugininfo_class('qbehaviour');
|
||||
$class::enable_plugin($disable, false);
|
||||
}
|
||||
core_plugin_manager::reset_caches();
|
||||
redirect($thispageurl);
|
||||
}
|
||||
|
||||
@@ -106,10 +105,9 @@ if (($enable = optional_param('enable', '', PARAM_PLUGIN)) && confirm_sesskey())
|
||||
}
|
||||
|
||||
if (($key = array_search($enable, $disabledbehaviours)) !== false) {
|
||||
unset($disabledbehaviours[$key]);
|
||||
set_config('disabledbehaviours', implode(',', $disabledbehaviours), 'question');
|
||||
$class = \core_plugin_manager::resolve_plugininfo_class('qbehaviour');
|
||||
$class::enable_plugin($enable, true);
|
||||
}
|
||||
core_plugin_manager::reset_caches();
|
||||
redirect($thispageurl);
|
||||
}
|
||||
|
||||
@@ -238,4 +236,3 @@ function question_behaviour_icon_html($action, $behaviour, $icon, $alt, $tip) {
|
||||
new pix_icon($icon, $alt, 'moodle', array('title' => '', 'class' => 'iconsmall')),
|
||||
null, array('title' => $tip));
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,33 @@ class qbehaviour extends base {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
public static function enable_plugin(string $pluginname, int $enabled): bool {
|
||||
$haschanged = false;
|
||||
$plugins = [];
|
||||
$oldvalue = get_config('question', 'disabledbehaviours');
|
||||
if (!empty($oldvalue)) {
|
||||
$plugins = array_flip(explode(',', $oldvalue));
|
||||
}
|
||||
// Only set visibility if it's different from the current value.
|
||||
if ($enabled && array_key_exists($pluginname, $plugins)) {
|
||||
unset($plugins[$pluginname]);
|
||||
$haschanged = true;
|
||||
} else if (!$enabled && !array_key_exists($pluginname, $plugins)) {
|
||||
$plugins[$pluginname] = $pluginname;
|
||||
$haschanged = true;
|
||||
}
|
||||
|
||||
if ($haschanged) {
|
||||
$new = implode(',', array_flip($plugins));
|
||||
add_to_config_log('disabledbehaviours', $oldvalue, $new, 'question');
|
||||
set_config('disabledbehaviours', $new, 'question');
|
||||
// Reset caches.
|
||||
\core_plugin_manager::reset_caches();
|
||||
}
|
||||
|
||||
return $haschanged;
|
||||
}
|
||||
|
||||
public function is_uninstall_allowed() {
|
||||
global $DB;
|
||||
|
||||
@@ -110,4 +137,3 @@ class qbehaviour extends base {
|
||||
return new moodle_url('/admin/qbehaviours.php');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user