mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 20:50:21 +01:00
MDL-72720 enrol: Implement enable_plugin() method
This commit is contained in:
parent
e8c60cff1f
commit
518b981350
@ -43,25 +43,18 @@ $all = enrol_get_plugins(false);
|
||||
|
||||
$return = new moodle_url('/admin/settings.php', array('section'=>'manageenrols'));
|
||||
|
||||
$syscontext = context_system::instance();
|
||||
|
||||
switch ($action) {
|
||||
case 'disable':
|
||||
unset($enabled[$enrol]);
|
||||
set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
|
||||
core_plugin_manager::reset_caches();
|
||||
$syscontext->mark_dirty(); // resets all enrol caches
|
||||
$class = \core_plugin_manager::resolve_plugininfo_class('enrol');
|
||||
$class::enable_plugin($enrol, false);
|
||||
break;
|
||||
|
||||
case 'enable':
|
||||
if (!isset($all[$enrol])) {
|
||||
break;
|
||||
}
|
||||
$enabled = array_keys($enabled);
|
||||
$enabled[] = $enrol;
|
||||
set_config('enrol_plugins_enabled', implode(',', $enabled));
|
||||
core_plugin_manager::reset_caches();
|
||||
$syscontext->mark_dirty(); // resets all enrol caches
|
||||
$class = \core_plugin_manager::resolve_plugininfo_class('enrol');
|
||||
$class::enable_plugin($enrol, true);
|
||||
break;
|
||||
|
||||
case 'up':
|
||||
@ -129,4 +122,4 @@ switch ($action) {
|
||||
}
|
||||
|
||||
|
||||
redirect($return);
|
||||
redirect($return);
|
||||
|
@ -46,6 +46,37 @@ class enrol extends base {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
public static function enable_plugin(string $pluginname, int $enabled): bool {
|
||||
global $CFG;
|
||||
|
||||
$haschanged = false;
|
||||
$plugins = [];
|
||||
if (!empty($CFG->enrol_plugins_enabled)) {
|
||||
$plugins = array_flip(explode(',', $CFG->enrol_plugins_enabled));
|
||||
}
|
||||
// Only set visibility if it's different from the current value.
|
||||
if ($enabled && !array_key_exists($pluginname, $plugins)) {
|
||||
$plugins[$pluginname] = $pluginname;
|
||||
$haschanged = true;
|
||||
} else if (!$enabled && array_key_exists($pluginname, $plugins)) {
|
||||
unset($plugins[$pluginname]);
|
||||
$haschanged = true;
|
||||
}
|
||||
|
||||
if ($haschanged) {
|
||||
$new = implode(',', array_flip($plugins));
|
||||
add_to_config_log('enrol_plugins_enabled', !$enabled, $enabled, $pluginname);
|
||||
set_config('enrol_plugins_enabled', $new);
|
||||
// Reset caches.
|
||||
\core_plugin_manager::reset_caches();
|
||||
// Resets all enrol caches.
|
||||
$syscontext = \context_system::instance();
|
||||
$syscontext->mark_dirty();
|
||||
}
|
||||
|
||||
return $haschanged;
|
||||
}
|
||||
|
||||
public function get_settings_section_name() {
|
||||
if (file_exists($this->full_path('settings.php'))) {
|
||||
return 'enrolsettings' . $this->name;
|
||||
|
Loading…
x
Reference in New Issue
Block a user