mirror of
https://github.com/moodle/moodle.git
synced 2025-07-27 09:20:36 +02:00
MDL-72720 webservice: Implement enable_plugin() method
This commit is contained in:
@@ -38,46 +38,19 @@ $action = optional_param('action', '', PARAM_ALPHANUMEXT);
|
|||||||
$webservice = optional_param('webservice', '', PARAM_SAFEDIR);
|
$webservice = optional_param('webservice', '', PARAM_SAFEDIR);
|
||||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||||
|
|
||||||
// get currently installed and enabled auth plugins
|
// Get currently installed and enabled auth plugins.
|
||||||
$available_webservices = core_component::get_plugin_list('webservice');
|
$availablewebservices = core_component::get_plugin_list('webservice');
|
||||||
if (!empty($webservice) and empty($available_webservices[$webservice])) {
|
if (!empty($webservice) and empty($availablewebservices[$webservice])) {
|
||||||
redirect($returnurl);
|
redirect($returnurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
$active_webservices = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols);
|
// Process actions.
|
||||||
foreach ($active_webservices as $key=>$active) {
|
|
||||||
if (empty($available_webservices[$active])) {
|
|
||||||
unset($active_webservices[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// process actions
|
|
||||||
|
|
||||||
if (!confirm_sesskey()) {
|
if (!confirm_sesskey()) {
|
||||||
redirect($returnurl);
|
redirect($returnurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($action) {
|
$enabled = ($action == 'enable');
|
||||||
|
$class = \core_plugin_manager::resolve_plugininfo_class('webservice');
|
||||||
case 'disable':
|
$class::enable_plugin($webservice, $enabled);
|
||||||
// remove from enabled list
|
|
||||||
$key = array_search($webservice, $active_webservices);
|
|
||||||
unset($active_webservices[$key]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'enable':
|
|
||||||
// add to enabled list
|
|
||||||
if (!in_array($webservice, $active_webservices)) {
|
|
||||||
$active_webservices[] = $webservice;
|
|
||||||
$active_webservices = array_unique($active_webservices);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
set_config('webserviceprotocols', implode(',', $active_webservices));
|
|
||||||
|
|
||||||
redirect($returnurl);
|
redirect($returnurl);
|
||||||
|
@@ -50,6 +50,43 @@ class webservice extends base {
|
|||||||
return $enabled;
|
return $enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function enable_plugin(string $pluginname, int $enabled): bool {
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
$haschanged = false;
|
||||||
|
$plugins = [];
|
||||||
|
if (!empty($CFG->webserviceprotocols)) {
|
||||||
|
$plugins = array_flip(explode(',', $CFG->webserviceprotocols));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove plugins that are no longer available.
|
||||||
|
$availablews = \core_component::get_plugin_list('webservice');
|
||||||
|
foreach ($plugins as $key => $notused) {
|
||||||
|
if (empty($availablews[$key])) {
|
||||||
|
unset($plugins[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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('webserviceprotocols', $CFG->webserviceprotocols, $new, 'core');
|
||||||
|
set_config('webserviceprotocols', $new);
|
||||||
|
// Reset caches.
|
||||||
|
\core_plugin_manager::reset_caches();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $haschanged;
|
||||||
|
}
|
||||||
|
|
||||||
public function get_settings_section_name() {
|
public function get_settings_section_name() {
|
||||||
return 'webservicesetting' . $this->name;
|
return 'webservicesetting' . $this->name;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user