Merge branch 'MDL-72720-master' of git://github.com/sarjona/moodle

This commit is contained in:
Shamim Rezaie
2021-10-18 15:43:31 +11:00
52 changed files with 889 additions and 324 deletions
+14 -8
View File
@@ -54,18 +54,19 @@ if (!confirm_sesskey()) {
redirect($returnurl);
}
$needsupdate = false;
switch ($action) {
case 'disable':
// Remove from enabled list.
$key = array_search($antivirus, $activeantiviruses);
unset($activeantiviruses[$key]);
$class = \core_plugin_manager::resolve_plugininfo_class('antivirus');
$class::enable_plugin($antivirus, false);
break;
case 'enable':
// Add to enabled list.
if (!in_array($antivirus, $activeantiviruses)) {
$activeantiviruses[] = $antivirus;
$activeantiviruses = array_unique($activeantiviruses);
$class = \core_plugin_manager::resolve_plugininfo_class('antivirus');
$class::enable_plugin($antivirus, true);
}
break;
@@ -78,6 +79,7 @@ switch ($action) {
$fsave = $activeantiviruses[$key];
$activeantiviruses[$key] = $activeantiviruses[$key + 1];
$activeantiviruses[$key + 1] = $fsave;
$needsupdate = true;
}
}
break;
@@ -91,6 +93,7 @@ switch ($action) {
$fsave = $activeantiviruses[$key];
$activeantiviruses[$key] = $activeantiviruses[$key - 1];
$activeantiviruses[$key - 1] = $fsave;
$needsupdate = true;
}
}
break;
@@ -98,10 +101,13 @@ switch ($action) {
default:
break;
}
$new = implode(',', $activeantiviruses);
add_to_config_log('antiviruses', $CFG->antiviruses, $new, 'core');
set_config('antiviruses', $new);
core_plugin_manager::reset_caches();
if ($needsupdate) {
$new = implode(',', $activeantiviruses);
add_to_config_log('antiviruses', $CFG->antiviruses, $new, 'core');
set_config('antiviruses', $new);
core_plugin_manager::reset_caches();
}
redirect ($returnurl);
+6 -27
View File
@@ -40,34 +40,15 @@ if (!confirm_sesskey()) {
switch ($action) {
case 'disable':
// remove from enabled list
$key = array_search($auth, $authsenabled);
if ($key !== false) {
unset($authsenabled[$key]);
$value = implode(',', $authsenabled);
add_to_config_log('auth', $CFG->auth, $value, 'core');
set_config('auth', $value);
}
if ($auth == $CFG->registerauth) {
set_config('registerauth', '');
}
\core\session\manager::gc(); // Remove stale sessions.
core_plugin_manager::reset_caches();
// Remove from enabled list.
$class = \core_plugin_manager::resolve_plugininfo_class('auth');
$class::enable_plugin($auth, false);
break;
case 'enable':
// add to enabled list
if (!in_array($auth, $authsenabled)) {
$authsenabled[] = $auth;
$authsenabled = array_unique($authsenabled);
$value = implode(',', $authsenabled);
add_to_config_log('auth', $CFG->auth, $value, 'core');
set_config('auth', $value);
}
\core\session\manager::gc(); // Remove stale sessions.
core_plugin_manager::reset_caches();
// Add to enabled list.
$class = \core_plugin_manager::resolve_plugininfo_class('auth');
$class::enable_plugin($auth, true);
break;
case 'down':
@@ -109,5 +90,3 @@ switch ($action) {
}
redirect($returnurl);
+15 -15
View File
@@ -30,26 +30,28 @@
$strprotect = get_string('blockprotect', 'admin');
$strunprotect = get_string('blockunprotect', 'admin');
/// If data submitted, then process and store.
// If data submitted, then process and store.
if (!empty($hide) && confirm_sesskey()) {
if (!$block = $DB->get_record('block', array('id'=>$hide))) {
print_error('blockdoesnotexist', 'error');
if (!$block = $DB->get_record('block', ['id' => $hide])) {
throw new \moodle_exception('blockdoesnotexist', 'error');
}
$DB->set_field('block', 'visible', '0', array('id'=>$block->id)); // Hide block
add_to_config_log('block_visibility', $block->visible, '0', $block->name);
core_plugin_manager::reset_caches();
admin_get_root(true, false); // settings not required - only pages
$class = \core_plugin_manager::resolve_plugininfo_class('block');
$class::enable_plugin($block->name, false);
// Settings not required - only pages.
admin_get_root(true, false);
}
if (!empty($show) && confirm_sesskey() ) {
if (!$block = $DB->get_record('block', array('id'=>$show))) {
print_error('blockdoesnotexist', 'error');
if (!$block = $DB->get_record('block', ['id' => $show])) {
throw new \moodle_exception('blockdoesnotexist', 'error');
}
$DB->set_field('block', 'visible', '1', array('id'=>$block->id)); // Show block
add_to_config_log('block_visibility', $block->visible, '1', $block->name);
core_plugin_manager::reset_caches();
admin_get_root(true, false); // settings not required - only pages
$class = \core_plugin_manager::resolve_plugininfo_class('block');
$class::enable_plugin($block->name, true);
// Settings not required - only pages.
admin_get_root(true, false);
}
if (!empty($protect) && confirm_sesskey()) {
@@ -234,5 +236,3 @@
}
echo $OUTPUT->footer();
+6 -3
View File
@@ -48,12 +48,14 @@ if (!isset($plugins[$name])) {
switch ($action) {
case 'disable':
if ($plugins[$name]->is_enabled()) {
set_config('disabled', 1, 'contentbank_'. $name);
$class = \core_plugin_manager::resolve_plugininfo_class('contenttype');
$class::enable_plugin($name, false);
}
break;
case 'enable':
if (!$plugins[$name]->is_enabled()) {
unset_config('disabled', 'contentbank_'. $name);
$class = \core_plugin_manager::resolve_plugininfo_class('contenttype');
$class::enable_plugin($name, true);
}
break;
case 'up':
@@ -63,6 +65,7 @@ switch ($action) {
$seq[$currentindex] = $seq[$currentindex - 1];
$seq[$currentindex - 1] = $name;
set_config('contentbank_plugins_sortorder', implode(',', $seq));
core_plugin_manager::reset_caches();
}
break;
case 'down':
@@ -72,10 +75,10 @@ switch ($action) {
$seq[$currentindex] = $seq[$currentindex + 1];
$seq[$currentindex + 1] = $name;
set_config('contentbank_plugins_sortorder', implode(',', $seq));
core_plugin_manager::reset_caches();
}
break;
}
core_plugin_manager::reset_caches();
$cache = cache::make('core', 'contentbank_enabled_extensions');
$cache->purge();
$cache = cache::make('core', 'contentbank_context_extensions');
+4 -7
View File
@@ -47,17 +47,14 @@ if (!isset($formatplugins[$formatname])) {
switch ($action) {
case 'disable':
if ($formatplugins[$formatname]->is_enabled()) {
if (get_config('moodlecourse', 'format') === $formatname) {
print_error('cannotdisableformat', 'error', $return);
}
set_config('disabled', 1, 'format_'. $formatname);
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('format');
$class::enable_plugin($formatname, false);
}
break;
case 'enable':
if (!$formatplugins[$formatname]->is_enabled()) {
unset_config('disabled', 'format_'. $formatname);
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('format');
$class::enable_plugin($formatname, true);
}
break;
case 'up':
+4 -4
View File
@@ -47,14 +47,14 @@ if (!isset($customfieldplugins[$customfieldname])) {
switch ($action) {
case 'disable':
if ($customfieldplugins[$customfieldname]->is_enabled()) {
set_config('disabled', 1, 'customfield_'. $customfieldname);
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('customfield');
$class::enable_plugin($customfieldname, false);
}
break;
case 'enable':
if (!$customfieldplugins[$customfieldname]->is_enabled()) {
unset_config('disabled', 'customfield_'. $customfieldname);
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('customfield');
$class::enable_plugin($customfieldname, true);
}
break;
}
+4 -5
View File
@@ -48,14 +48,14 @@ if (!isset($plugins[$name])) {
switch ($action) {
case 'disable':
if ($plugins[$name]->is_enabled()) {
set_config('disabled', 1, 'dataformat_'. $name);
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('dataformat');
$class::enable_plugin($name, false);
}
break;
case 'enable':
if (!$plugins[$name]->is_enabled()) {
unset_config('disabled', 'dataformat_'. $name);
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('dataformat');
$class::enable_plugin($name, true);
}
break;
case 'up':
@@ -78,4 +78,3 @@ switch ($action) {
break;
}
redirect($return);
+10 -17
View File
@@ -39,22 +39,19 @@ if (!confirm_sesskey()) {
redirect($returnurl);
}
$return = true;
switch ($action) {
case 'disable':
// remove from enabled list
$key = array_search($editor, $active_editors);
unset($active_editors[$key]);
add_to_config_log('editor_visibility', '1', '0', $editor);
// Remove from enabled list.
$class = \core_plugin_manager::resolve_plugininfo_class('editor');
$class::enable_plugin($editor, false);
break;
case 'enable':
// add to enabled list
// Add to enabled list.
if (!in_array($editor, $active_editors)) {
$active_editors[] = $editor;
$active_editors = array_unique($active_editors);
add_to_config_log('editor_visibility', '0', '1', $editor);
$class = \core_plugin_manager::resolve_plugininfo_class('editor');
$class::enable_plugin($editor, true);
}
break;
@@ -68,6 +65,8 @@ switch ($action) {
$active_editors[$key] = $active_editors[$key + 1];
$active_editors[$key + 1] = $fsave;
add_to_config_log('editor_position', $key, $key + 1, $editor);
set_config('texteditors', implode(',', $active_editors));
core_plugin_manager::reset_caches();
}
}
break;
@@ -82,6 +81,8 @@ switch ($action) {
$active_editors[$key] = $active_editors[$key - 1];
$active_editors[$key - 1] = $fsave;
add_to_config_log('editor_position', $key, $key - 1, $editor);
set_config('texteditors', implode(',', $active_editors));
core_plugin_manager::reset_caches();
}
}
break;
@@ -90,14 +91,6 @@ switch ($action) {
break;
}
// at least one editor must be active
if (empty($active_editors)) {
$active_editors = array('textarea');
}
set_config('texteditors', implode(',', $active_editors));
core_plugin_manager::reset_caches();
if ($return) {
redirect ($returnurl);
}
+5 -12
View File
@@ -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);
+9 -7
View File
@@ -72,10 +72,8 @@ switch ($action) {
case 'setstate':
if (isset($filters[$filterpath]) and $newstate = optional_param('newstate', '', PARAM_INT)) {
filter_set_global_state($filterpath, $newstate);
if ($newstate == TEXTFILTER_DISABLED) {
filter_set_applies_to_strings($filterpath, false);
}
$class = \core_plugin_manager::resolve_plugininfo_class('filter');
$class::enable_plugin($filterpath, $newstate);
}
break;
@@ -83,12 +81,16 @@ switch ($action) {
if (isset($filters[$filterpath])) {
$applytostrings = optional_param('stringstoo', false, PARAM_BOOL);
filter_set_applies_to_strings($filterpath, $applytostrings);
reset_text_filters_cache();
core_plugin_manager::reset_caches();
}
break;
case 'down':
if (isset($filters[$filterpath])) {
filter_set_global_state($filterpath, $filters[$filterpath]->active, 1);
reset_text_filters_cache();
core_plugin_manager::reset_caches();
}
break;
@@ -96,14 +98,14 @@ switch ($action) {
if (isset($filters[$filterpath])) {
$oldpos = $filters[$filterpath]->sortorder;
filter_set_global_state($filterpath, $filters[$filterpath]->active, -1);
reset_text_filters_cache();
core_plugin_manager::reset_caches();
}
break;
}
// Reset caches and return.
// Return.
if ($action) {
reset_text_filters_cache();
core_plugin_manager::reset_caches();
redirect(new moodle_url('/admin/filters.php'));
}
+4 -2
View File
@@ -49,11 +49,13 @@ if (!array_key_exists($media, $plugins)) {
switch ($action) {
case 'disable':
$plugins[$media]->set_enabled(false);
$class = \core_plugin_manager::resolve_plugininfo_class('media');
$class::enable_plugin($media, false);
break;
case 'enable':
$plugins[$media]->set_enabled(true);
$class = \core_plugin_manager::resolve_plugininfo_class('media');
$class::enable_plugin($media, true);
break;
case 'up':
+2 -4
View File
@@ -119,10 +119,8 @@ if (($form = data_submitted()) && confirm_sesskey()) {
// Save processors enabled/disabled status.
foreach ($allprocessors as $processor) {
$enabled = isset($form->{$processor->name});
if ($enabled != $processor->enabled) {
add_to_config_log($processor->name, $processor->enabled, $enabled, 'core');
}
\core_message\api::update_processor_status($processor, $enabled);
$class = \core_plugin_manager::resolve_plugininfo_class('message');
$class::enable_plugin($processor->name, $enabled);
}
foreach ($newpreferences as $name => $value) {
+6 -33
View File
@@ -30,42 +30,17 @@
/// If data submitted, then process and store.
if (!empty($hide) and confirm_sesskey()) {
if (!$module = $DB->get_record("modules", array("name"=>$hide))) {
print_error('moduledoesnotexist', 'error');
}
$DB->set_field("modules", "visible", "0", array("id"=>$module->id)); // Hide main module
// Remember the visibility status in visibleold
// and hide...
$sql = "UPDATE {course_modules}
SET visibleold=visible, visible=0
WHERE module=?";
$DB->execute($sql, array($module->id));
// Increment course.cacherev for courses where we just made something invisible.
// This will force cache rebuilding on the next request.
increment_revision_number('course', 'cacherev',
"id IN (SELECT DISTINCT course
FROM {course_modules}
WHERE visibleold=1 AND module=?)",
array($module->id));
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('mod');
$class::enable_plugin($hide, false);
admin_get_root(true, false); // settings not required - only pages
redirect(new moodle_url('/admin/modules.php'));
}
if (!empty($show) and confirm_sesskey()) {
if (!$module = $DB->get_record("modules", array("name"=>$show))) {
print_error('moduledoesnotexist', 'error');
}
$DB->set_field("modules", "visible", "1", array("id"=>$module->id)); // Show main module
$DB->set_field('course_modules', 'visible', '1', array('visibleold'=>1, 'module'=>$module->id)); // Get the previous saved visible state for the course module.
// Increment course.cacherev for courses where we just made something visible.
// This will force cache rebuilding on the next request.
increment_revision_number('course', 'cacherev',
"id IN (SELECT DISTINCT course
FROM {course_modules}
WHERE visible=1 AND module=?)",
array($module->id));
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('mod');
$class::enable_plugin($show, true);
admin_get_root(true, false); // settings not required - only pages
redirect(new moodle_url('/admin/modules.php'));
}
@@ -163,5 +138,3 @@
$table->print_html();
echo $OUTPUT->footer();
+3 -9
View File
@@ -102,20 +102,15 @@ if (($action == 'edit') || ($action == 'new')) {
require_sesskey();
$instance = portfolio_instance($portfolio);
$current = $instance->get('visible');
if (empty($current) && $instance->instance_sanity_check()) {
print_error('cannotsetvisible', 'portfolio', $baseurl);
}
$plugin = $instance->get('plugin');
if ($action == 'show') {
$visible = 1;
} else {
$visible = 0;
}
$instance->set('visible', $visible);
$instance->save();
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('portfolio');
$class::enable_plugin($plugin, $visible);
$return = true;
} else if ($action == 'delete') {
$instance = portfolio_instance($portfolio);
@@ -246,4 +241,3 @@ if ($return) {
}
echo $OUTPUT->footer();
+4 -4
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);
+4 -7
View File
@@ -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));
}
+4 -3
View File
@@ -80,7 +80,8 @@ if (($disable = optional_param('disable', '', PARAM_PLUGIN)) && confirm_sesskey(
print_error('unknownquestiontype', 'question', $thispageurl, $disable);
}
set_config($disable . '_disabled', 1, 'question');
$class = \core_plugin_manager::resolve_plugininfo_class('qtype');
$class::enable_plugin($disable, false);
redirect($thispageurl);
}
@@ -94,7 +95,8 @@ if (($enable = optional_param('enable', '', PARAM_PLUGIN)) && confirm_sesskey())
print_error('cannotenable', 'question', $thispageurl, $enable);
}
unset_config($enable . '_disabled', 'question');
$class = \core_plugin_manager::resolve_plugininfo_class('qtype');
$class::enable_plugin($enable, true);
redirect($thispageurl);
}
@@ -251,4 +253,3 @@ function question_type_icon_html($action, $qtypename, $icon, $alt, $tip) {
new pix_icon($icon, $alt, 'moodle', array('title' => '', 'class' => 'iconsmall')),
null, array('title' => $tip));
}
+4 -12
View File
@@ -183,23 +183,15 @@ if (($action == 'edit') || ($action == 'new')) {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
$repositorytype = repository::get_type_by_typename($repository);
if (empty($repositorytype)) {
print_error('invalidplugin', 'repository', '', $repository);
}
$repositorytype->update_visibility(true);
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('repository');
$class::enable_plugin($repository, true);
$return = true;
} else if ($action == 'hide') {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', '', $baseurl);
}
$repositorytype = repository::get_type_by_typename($repository);
if (empty($repositorytype)) {
print_error('invalidplugin', 'repository', '', $repository);
}
$repositorytype->update_visibility(false);
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class('repository');
$class::enable_plugin($repository, false);
$return = true;
} else if ($action == 'delete') {
$repositorytype = repository::get_type_by_typename($repository);
+4 -3
View File
@@ -52,13 +52,14 @@ if (($plugin = optional_param('plugin', '', PARAM_PLUGIN))) {
$action = required_param('action', PARAM_ALPHA);
switch ($action) {
case 'hide' :
set_config('disabled', 1, 'availability_' . $plugin);
$class = \core_plugin_manager::resolve_plugininfo_class('availability');
$class::enable_plugin($plugin, false);
break;
case 'show' :
unset_config('disabled', 'availability_' . $plugin);
$class = \core_plugin_manager::resolve_plugininfo_class('availability');
$class::enable_plugin($plugin, true);
break;
}
core_plugin_manager::reset_caches();
// Always redirect back after an action.
redirect($pageurl);
@@ -42,6 +42,33 @@ class logstore extends base {
return isset($enabled['logstore_' . $this->name]);
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
$haschanged = false;
$plugins = [];
$oldvalue = get_config('tool_log', 'enabled_stores');
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)) {
$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('tool_logstore_visibility', $oldvalue, $new, $pluginname);
set_config('enabled_stores', $new, 'tool_log');
// Reset caches.
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
public function get_settings_section_name() {
return 'logsetting' . $this->name;
}
+11 -17
View File
@@ -26,7 +26,7 @@ require_once('../../../config.php');
require_once($CFG->libdir . '/adminlib.php');
$action = required_param('action', PARAM_ALPHANUMEXT);
$enrol = required_param('store', PARAM_PLUGIN);
$store = required_param('store', PARAM_PLUGIN);
$PAGE->set_url('/admin/tool/log/stores.php');
$PAGE->set_context(context_system::instance());
@@ -48,50 +48,44 @@ $syscontext = context_system::instance();
switch ($action) {
case 'disable':
unset($enabled[$enrol]);
set_config('enabled_stores', implode(',', array_keys($enabled)), 'tool_log');
add_to_config_log('tool_logstore_visibility', '1', '0', $enrol);
$class = \core_plugin_manager::resolve_plugininfo_class('logstore');
$class::enable_plugin($store, false);
break;
case 'enable':
if (!isset($all[$enrol])) {
break;
}
$enabled = array_keys($enabled);
$enabled[] = $enrol;
set_config('enabled_stores', implode(',', $enabled), 'tool_log');
add_to_config_log('tool_logstore_visibility', '0', '1', $enrol);
$class = \core_plugin_manager::resolve_plugininfo_class('logstore');
$class::enable_plugin($store, true);
break;
case 'up':
if (!isset($enabled[$enrol])) {
if (!isset($enabled[$store])) {
break;
}
$enabled = array_keys($enabled);
$enabled = array_flip($enabled);
$current = $enabled[$enrol];
$current = $enabled[$store];
if ($current == 0) {
break; // Already at the top.
}
$enabled = array_flip($enabled);
$enabled[$current] = $enabled[$current - 1];
$enabled[$current - 1] = $enrol;
$enabled[$current - 1] = $store;
set_config('enabled_stores', implode(',', $enabled), 'tool_log');
break;
case 'down':
if (!isset($enabled[$enrol])) {
if (!isset($enabled[$store])) {
break;
}
$enabled = array_keys($enabled);
$enabled = array_flip($enabled);
$current = $enabled[$enrol];
$current = $enabled[$store];
if ($current == count($enabled) - 1) {
break; // Already at the end.
}
$enabled = array_flip($enabled);
$enabled[$current] = $enabled[$current + 1];
$enabled[$current + 1] = $enrol;
$enabled[$current + 1] = $store;
set_config('enabled_stores', implode(',', $enabled), 'tool_log');
break;
}
+4 -2
View File
@@ -50,11 +50,13 @@ if (!array_key_exists($plugin, $plugins)) {
switch ($action) {
case 'disable':
$plugins[$plugin]->set_enabled(false);
$class = \core_plugin_manager::resolve_plugininfo_class($type);
$class::enable_plugin($plugin, false);
break;
case 'enable':
$plugins[$plugin]->set_enabled(true);
$class = \core_plugin_manager::resolve_plugininfo_class($type);
$class::enable_plugin($plugin, true);
break;
case 'up':
+7 -34
View File
@@ -38,46 +38,19 @@ $action = optional_param('action', '', PARAM_ALPHANUMEXT);
$webservice = optional_param('webservice', '', PARAM_SAFEDIR);
$confirm = optional_param('confirm', 0, PARAM_BOOL);
// get currently installed and enabled auth plugins
$available_webservices = core_component::get_plugin_list('webservice');
if (!empty($webservice) and empty($available_webservices[$webservice])) {
// Get currently installed and enabled auth plugins.
$availablewebservices = core_component::get_plugin_list('webservice');
if (!empty($webservice) and empty($availablewebservices[$webservice])) {
redirect($returnurl);
}
$active_webservices = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols);
foreach ($active_webservices as $key=>$active) {
if (empty($available_webservices[$active])) {
unset($active_webservices[$key]);
}
}
////////////////////////////////////////////////////////////////////////////////
// process actions
// Process actions.
if (!confirm_sesskey()) {
redirect($returnurl);
}
switch ($action) {
case 'disable':
// 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));
$enabled = ($action == 'enable');
$class = \core_plugin_manager::resolve_plugininfo_class('webservice');
$class::enable_plugin($webservice, $enabled);
redirect($returnurl);
+28
View File
@@ -55,6 +55,34 @@ class antivirus extends base {
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
global $CFG;
$haschanged = false;
$plugins = [];
if (!empty($CFG->antiviruses)) {
$plugins = array_flip(explode(',', $CFG->antiviruses));
}
// 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('antiviruses', $CFG->antiviruses, $new, 'core');
set_config('antiviruses', $new);
// Reset caches.
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
/**
* Return the node name to use in admin settings menu for this plugin.
*
+34
View File
@@ -57,6 +57,40 @@ class auth extends base {
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
global $CFG;
$haschanged = false;
$plugins = [];
if (!empty($CFG->auth)) {
$plugins = array_flip(explode(',', $CFG->auth));
}
// 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 ($pluginname == $CFG->registerauth) {
set_config('registerauth', '');
}
}
if ($haschanged) {
$new = implode(',', array_flip($plugins));
add_to_config_log('auth', $CFG->auth, $new, 'core');
set_config('auth', $new);
// Remove stale sessions.
\core\session\manager::gc();
// Reset caches.
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
public function get_settings_section_name() {
return 'authsetting' . $this->name;
}
+23
View File
@@ -56,6 +56,29 @@ class availability extends base {
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
$haschanged = false;
$plugin = 'availability_' . $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;
}
/**
* Defines if there should be a way to uninstall the plugin via the administration UI.
*
+14
View File
@@ -79,6 +79,20 @@ abstract class base {
return null;
}
/**
* Enable or disable a plugin.
* When possible, the change will be stored into the config_log table, to let admins check when/who has modified it.
*
* @param string $pluginname The plugin name to enable/disable.
* @param int $enabled Whether the pluginname should be enabled (1) or not (0). This is an integer because some plugins, such
* as filters or repositories, might support more statuses than just enabled/disabled.
*
* @return bool Whether $pluginname has been updated or not.
*/
public static function enable_plugin(string $pluginname, int $enabled): bool {
return false;
}
/**
* Gathers and returns the information about all plugins of the given type,
* either on disk or previously installed.
+23
View File
@@ -41,6 +41,29 @@ class block extends base {
return $DB->get_records_menu('block', array('visible'=>1), 'name ASC', 'name, name AS val');
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
global $DB;
if (!$block = $DB->get_record('block', ['name' => $pluginname])) {
throw new \moodle_exception('blockdoesnotexist', 'error');
}
$haschanged = false;
// Only set visibility if it's different from the current value.
if ($block->visible != $enabled) {
// Set block visibility.
$DB->set_field('block', 'visible', $enabled, ['id' => $block->id]);
$haschanged = true;
// Include this information into config changes table.
add_to_config_log('block_visibility', $block->visible, $enabled, $pluginname);
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
/**
* Magic method getter, redirects to read only values.
*
+23
View File
@@ -156,6 +156,29 @@ class contenttype extends base {
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
$haschanged = false;
$plugin = 'contentbank_' . $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;
}
/**
* Optional extra warning before uninstallation adding number of existing contenttype contents.
*
+23
View File
@@ -78,6 +78,29 @@ class customfield extends base {
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
$haschanged = false;
$plugin = 'customfield_' . $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;
}
/**
* Pre-uninstall hook.
*
+23 -1
View File
@@ -96,6 +96,29 @@ class dataformat extends base {
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
$haschanged = false;
$plugin = 'dataformat_' . $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;
}
/**
* Returns the node name used in admin settings menu for this plugin settings (if applicable)
*
@@ -163,4 +186,3 @@ class dataformat extends base {
}
}
+36
View File
@@ -51,6 +51,42 @@ class editor extends base {
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
global $CFG;
$haschanged = false;
if (!empty($CFG->texteditors)) {
$plugins = array_flip(explode(',', $CFG->texteditors));
} else {
$plugins = [];
}
// 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;
}
// At least one editor must be active.
if (empty($plugins)) {
$plugins['textarea'] = 'textarea';
$haschanged = true;
}
if ($haschanged) {
$new = implode(',', array_flip($plugins));
add_to_config_log('editor_visibility', !$enabled, $enabled, $pluginname);
set_config('texteditors', $new);
// Reset caches.
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
public function get_settings_section_name() {
return 'editorsettings' . $this->name;
}
+31
View File
@@ -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;
+26 -19
View File
@@ -111,31 +111,38 @@ class fileconverter extends base {
return array_combine($order, $order);
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
global $CFG;
$haschanged = false;
$plugins = [];
if (!empty($CFG->converter_plugins_sortorder)) {
$plugins = array_flip(explode(',', $CFG->converter_plugins_sortorder));
}
// 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) {
add_to_config_log('converter_plugins_sortorder', !$enabled, $enabled, $pluginname);
self::set_enabled_plugins(array_flip($plugins));
}
return $haschanged;
}
/**
* Sets the current plugin as enabled or disabled
* When enabling tries to guess the sortorder based on default rank returned by the plugin.
* @param bool $newstate
*/
public function set_enabled($newstate = true) {
$enabled = self::get_enabled_plugins();
if (array_key_exists($this->name, $enabled) == $newstate) {
// Nothing to do.
return;
}
if ($newstate) {
// Enable converter plugin.
$plugins = \core_plugin_manager::instance()->get_plugins_of_type('fileconverter');
if (!array_key_exists($this->name, $plugins)) {
// Can not be enabled.
return;
}
$enabled[$this->name] = $this->name;
self::set_enabled_plugins($enabled);
} else {
// Disable converter plugin.
unset($enabled[$this->name]);
self::set_enabled_plugins($enabled);
}
self::enable_plugin($this->name, $newstate);
}
/**
+26
View File
@@ -58,6 +58,32 @@ class filter extends base {
return $enabled;
}
/**
* Enable or disable a plugin.
* When possible, the change will be stored into the config_log table, to let admins check when/who has modified it.
*
* @param string $pluginname The plugin name to enable/disable.
* @param int $enabled Whether the pluginname should be TEXTFILTER_ON, TEXTFILTER_OFF or TEXTFILTER_DISABLED.
*
* @return bool It always return true because we don't know if the value has changed or not. That way, we guarantee any action
* required if it's changed will be executed.
*/
public static function enable_plugin(string $pluginname, int $enabled): bool {
global $CFG;
require_once("$CFG->libdir/filterlib.php");
require_once("$CFG->libdir/weblib.php");
filter_set_global_state($pluginname, $enabled);
if ($enabled == TEXTFILTER_DISABLED) {
filter_set_applies_to_strings($filterpath, false);
}
reset_text_filters_cache();
\core_plugin_manager::reset_caches();
return true;
}
public function get_settings_section_name() {
return 'filtersetting' . $this->name;
}
+27
View File
@@ -65,6 +65,33 @@ class format extends base {
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
$haschanged = false;
$plugin = 'format_' . $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) {
if (get_config('moodlecourse', 'format') === $pluginname) {
// The default course format can't be disabled.
throw new \moodle_exception('cannotdisableformat', 'error');
}
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;
}
/**
* Gathers and returns the information about all plugins of the given type
*
+45 -28
View File
@@ -99,40 +99,57 @@ class media extends base {
return array_combine($order, $order);
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
global $CFG;
$haschanged = false;
$plugins = [];
if (!empty($CFG->media_plugins_sortorder)) {
$plugins = explode(',', $CFG->media_plugins_sortorder);
}
// Only set visibility if it's different from the current value.
if ($enabled && !in_array($pluginname, $plugins)) {
// Enable media plugin.
$pluginsbytype = \core_plugin_manager::instance()->get_plugins_of_type('media');
if (!array_key_exists($pluginname, $pluginsbytype)) {
// Can not be enabled.
return false;
}
$rank = $pluginsbytype[$pluginname]->get_rank();
$position = 0;
// Insert before the first enabled plugin which default rank is smaller than the default rank of this one.
foreach ($plugins as $playername) {
if (($player = $pluginsbytype[$playername]) && ($rank > $player->get_rank())) {
break;
}
$position++;
}
array_splice($plugins, $position, 0, [$pluginname]);
$haschanged = true;
} else if (!$enabled && in_array($pluginname, $plugins)) {
// Disable media plugin.
$key = array_search($pluginname, $plugins);
unset($plugins[$key]);
$haschanged = true;
}
if ($haschanged) {
add_to_config_log('media_plugins_sortorder', !$enabled, $enabled, $pluginname);
self::set_enabled_plugins($plugins);
}
return $haschanged;
}
/**
* Sets the current plugin as enabled or disabled
* When enabling tries to guess the sortorder based on default rank returned by the plugin.
* @param bool $newstate
*/
public function set_enabled($newstate = true) {
$enabled = self::get_enabled_plugins();
if (array_key_exists($this->name, $enabled) == $newstate) {
// Nothing to do.
return;
}
if ($newstate) {
// Enable media plugin.
$plugins = \core_plugin_manager::instance()->get_plugins_of_type('media');
if (!array_key_exists($this->name, $plugins)) {
// Can not be enabled.
return;
}
$rank = $this->get_rank();
$position = 0;
// Insert before the first enabled plugin which default rank is smaller than the default rank of this one.
foreach ($enabled as $playername) {
if (($player = $plugins[$playername]) && ($rank > $player->get_rank())) {
break;
}
$position++;
}
array_splice($enabled, $position, 0, [$this->name]);
self::set_enabled_plugins($enabled);
} else {
// Disable media plugin.
unset($enabled[$this->name]);
self::set_enabled_plugins($enabled);
}
self::enable_plugin($this->name, $newstate);
}
/**
+24
View File
@@ -40,6 +40,30 @@ class message extends base {
return $DB->get_records_menu('message_processors', array('enabled'=>1), 'name ASC', 'name, name AS val');
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
global $DB;
if (!$plugin = $DB->get_record('message_processors', ['name' => $pluginname])) {
throw new \moodle_exception('invalidplugin', 'message', '', $pluginname);
}
$haschanged = false;
// Only set visibility if it's different from the current value.
if ($plugin->enabled != $enabled) {
$haschanged = true;
$processor = \core_message\api::get_processed_processor_object($plugin);
// Include this information into config changes table.
add_to_config_log($processor->name, $processor->enabled, $enabled, 'core');
// Save processor enabled/disabled status.
\core_message\api::update_processor_status($processor, $enabled);
}
return $haschanged;
}
public function get_settings_section_name() {
return 'messagesetting' . $this->name;
}
+51
View File
@@ -40,6 +40,57 @@ class mod extends base {
return $DB->get_records_menu('modules', array('visible'=>1), 'name ASC', 'name, name AS val');
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
global $DB;
if (!$module = $DB->get_record('modules', ['name' => $pluginname])) {
throw new \moodle_exception('moduledoesnotexist', 'error');
}
$haschanged = false;
// Only set visibility if it's different from the current value.
if ($module->visible != $enabled) {
// Set module visibility.
$DB->set_field('modules', 'visible', $enabled, ['id' => $module->id]);
$haschanged = true;
if ($enabled) {
// Revert the previous saved visible state for the course module.
$DB->set_field('course_modules', 'visible', '1', ['visibleold' => 1, 'module' => $module->id]);
// Increment course.cacherev for courses where we just made something visible.
// This will force cache rebuilding on the next request.
increment_revision_number('course', 'cacherev',
"id IN (SELECT DISTINCT course
FROM {course_modules}
WHERE visible = 1 AND module = ?)",
[$module->id]
);
} else {
// Remember the visibility status in visibleold and hide.
$sql = "UPDATE {course_modules}
SET visibleold = visible, visible = 0
WHERE module = ?";
$DB->execute($sql, [$module->id]);
// Increment course.cacherev for courses where we just made something invisible.
// This will force cache rebuilding on the next request.
increment_revision_number('course', 'cacherev',
'id IN (SELECT DISTINCT course
FROM {course_modules}
WHERE visibleold = 1 AND module = ?)',
[$module->id]
);
}
// Include this information into config changes table.
add_to_config_log('mod_visibility', $module->visible, $enabled, $pluginname);
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
/**
* Magic method getter, redirects to read only values.
*
+26 -19
View File
@@ -82,6 +82,31 @@ class paygw extends base {
return array_combine($order, $order);
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
global $CFG;
$haschanged = false;
$plugins = [];
if (!empty($CFG->paygw_plugins_sortorder)) {
$plugins = array_flip(explode(',', $CFG->paygw_plugins_sortorder));
}
// 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) {
add_to_config_log('paygw_plugins_sortorder', !$enabled, $enabled, $pluginname);
self::set_enabled_plugins(array_flip($plugins));
}
return $haschanged;
}
/**
* Sets the current plugin as enabled or disabled
* When enabling tries to guess the sortorder based on default rank returned by the plugin.
@@ -89,25 +114,7 @@ class paygw extends base {
* @param bool $newstate
*/
public function set_enabled(bool $newstate = true) {
$enabled = self::get_enabled_plugins();
if (array_key_exists($this->name, $enabled) == $newstate) {
// Nothing to do.
return;
}
if ($newstate) {
// Enable gateway plugin.
$plugins = \core_plugin_manager::instance()->get_plugins_of_type('paygw');
if (!array_key_exists($this->name, $plugins)) {
// Can not be enabled.
return;
}
$enabled[$this->name] = $this->name;
self::set_enabled_plugins($enabled);
} else {
// Disable gateway plugin.
unset($enabled[$this->name]);
self::set_enabled_plugins($enabled);
}
self::enable_plugin($this->name, $newstate);
}
/**
+35
View File
@@ -48,6 +48,41 @@ class portfolio extends base {
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
global $DB, $CFG;
require_once($CFG->libdir . '/portfoliolib.php');
$haschanged = false;
$oldvalue = null;
$data = ['visible' => $enabled];
if ($plugin = $DB->get_record('portfolio_instance', ['plugin' => $pluginname])) {
$instance = portfolio_instance($plugin->id);
$oldvalue = $instance->get('visible');
if (empty($oldvalue) && $instance->instance_sanity_check()) {
throw new \moodle_exception('cannotsetvisible', 'portfolio');
}
// Only set visibility if it's different from the current value.
if ($oldvalue != $enabled) {
$haschanged = true;
$instance->set('visible', $enabled);
$instance->save();
}
} else {
$haschanged = true;
portfolio_static_function($pluginname, 'create_instance', $pluginname, $pluginname, $data);
}
if ($haschanged) {
// Include this information into config changes table.
add_to_config_log('portfolio_visibility', $oldvalue, $enabled, $pluginname);
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
/**
* Return URL used for management of plugins of this type.
* @return moodle_url
+23
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.
+27 -1
View File
@@ -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');
}
}
+23
View File
@@ -65,6 +65,29 @@ class qtype extends base {
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
$haschanged = false;
$settingname = $pluginname . '_disabled';
$oldvalue = get_config('question', $settingname);
$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($settingname, $disabled, 'question');
$haschanged = true;
} else if ($oldvalue != false && !$disabled) {
unset_config($settingname, 'question');
$haschanged = true;
}
if ($haschanged) {
add_to_config_log($settingname, $oldvalue, $disabled, 'question');
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
public function is_uninstall_allowed() {
global $DB;
+26
View File
@@ -40,6 +40,32 @@ class repository extends base {
return $DB->get_records_menu('repository', null, 'type ASC', 'type, type AS val');
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
global $DB;
$haschanged = false;
$repositorytype = \repository::get_type_by_typename($pluginname);
if (empty($repositorytype)) {
throw new \moodle_exception('invalidplugin', 'repository', '', $pluginname);
}
// The visibility will be only changed if the repository exists in database. Otherwise, this method won't do anything.
if ($plugin = $DB->get_record('repository', ['type' => $pluginname])) {
$oldvalue = $plugin->visible;
// Only set visibility if it's different from the current value.
if ($oldvalue != $enabled) {
$haschanged = true;
$repositorytype->update_visibility($enabled);
// Include this information into config changes table.
add_to_config_log('repository_visibility', $oldvalue, $enabled, $pluginname);
\core_plugin_manager::reset_caches();
}
}
return $haschanged;
}
public function get_settings_section_name() {
return 'repositorysettings'.$this->name;
}
+37
View File
@@ -50,6 +50,43 @@ class webservice extends base {
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() {
return 'webservicesetting' . $this->name;
}
@@ -58,6 +58,33 @@ class tinymce extends base {
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
$haschanged = false;
$plugins = [];
$oldvalue = get_config('editor_tinymce', 'disabledsubplugins');
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('disabledsubplugins', $oldvalue, $new, 'editor_tinymce');
set_config('disabledsubplugins', $new, 'editor_tinymce');
// Reset caches.
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
public function is_uninstall_allowed() {
return true;
}
+4 -17
View File
@@ -42,25 +42,12 @@ if ($return === 'settings') {
$returnurl = new moodle_url('/admin/plugins.php');
}
$disabled = array();
$disabledsubplugins = get_config('editor_tinymce', 'disabledsubplugins');
if ($disabledsubplugins) {
$disabledsubplugins = explode(',', $disabledsubplugins);
foreach ($disabledsubplugins as $sp) {
$sp = trim($sp);
if ($sp !== '') {
$disabled[$sp] = $sp;
}
}
}
if ($disable) {
$disabled[$disable] = $disable;
$class = \core_plugin_manager::resolve_plugininfo_class('tinymce');
$class::enable_plugin($disable, false);
} else if ($enable) {
unset($disabled[$enable]);
$class = \core_plugin_manager::resolve_plugininfo_class('tinymce');
$class::enable_plugin($enable, true);
}
set_config('disabledsubplugins', implode(',', $disabled), 'editor_tinymce');
core_plugin_manager::reset_caches();
redirect($returnurl);
+3
View File
@@ -106,6 +106,9 @@ completely removed from Moodle core too.
* Require pass grade criteria is now part of core.
Refer to upgrade.php to see transitioning from similar plugin criteria to core
Refer to completion/upgrade.txt for additional information.
* The method enable_plugin() has been added to the core_plugininfo\base class and it has been implemented by all the plugininfo
classes extending it. When possible, the enable_plugin() method will store these changes into the config_log table, to let admins
check when and who has enabled/disabled plugins.
=== 3.11.2 ===
* For security reasons, filelib has been updated so all requests now use emulated redirects.
+4 -4
View File
@@ -274,8 +274,8 @@ class assign_plugin_manager {
* @return string The next page to display
*/
public function hide_plugin($plugin) {
set_config('disabled', 1, $this->subtype . '_' . $plugin);
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class($this->subtype);
$class::enable_plugin($plugin, false);
return 'view';
}
@@ -333,8 +333,8 @@ class assign_plugin_manager {
* @return string The next page to display
*/
public function show_plugin($plugin) {
set_config('disabled', 0, $this->subtype . '_' . $plugin);
core_plugin_manager::reset_caches();
$class = \core_plugin_manager::resolve_plugininfo_class($this->subtype);
$class::enable_plugin($plugin, true);
return 'view';
}
@@ -63,6 +63,24 @@ class assignfeedback extends base {
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
$haschanged = false;
$plugin = 'assignfeedback_' . $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 || ((bool) $oldvalue != $disabled)) {
set_config('disabled', $disabled, $plugin);
$haschanged = true;
add_to_config_log('disabled', $oldvalue, $disabled, $plugin);
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
public function is_uninstall_allowed() {
return true;
}
@@ -63,6 +63,24 @@ class assignsubmission extends base {
return $enabled;
}
public static function enable_plugin(string $pluginname, int $enabled): bool {
$haschanged = false;
$plugin = 'assignsubmission_' . $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 || ((bool) $oldvalue != $disabled)) {
set_config('disabled', $disabled, $plugin);
$haschanged = true;
add_to_config_log('disabled', $oldvalue, $disabled, $plugin);
\core_plugin_manager::reset_caches();
}
return $haschanged;
}
public function is_uninstall_allowed() {
return true;
}