MDL-62777 Administration: CLI upgrade new setting notification
During a CLI upgrade when there are new settings in core or in a plugin, the settings are set to the defined defaults automatically. There is no ouput shown on the CLI about which new settings have been introduced or what default values the setting are set to. This patch outputs the name of the new setting and what the default value being is set is to the CLI during an upgrade. Objects and arrays are expanded into a human readable format. This plugin also makes the function that sets the defaults to be more robust so it isno longer required to be called multiple times to ensure all settings are set.
This commit is contained in:
+39
-14
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -8006,12 +8007,16 @@ function admin_get_root($reload=false, $requirefulltree=true) {
|
||||
|
||||
/**
|
||||
* This function applies default settings.
|
||||
* Because setting the defaults of some settings can enable other settings,
|
||||
* this function is called recursively until no more new settings are found.
|
||||
*
|
||||
* @param object $node, NULL means complete tree, null by default
|
||||
* @param bool $unconditional if true overrides all values with defaults, null buy default
|
||||
* @param bool $unconditional if true overrides all values with defaults, true by default
|
||||
* @param array $admindefaultsettings default admin settings to apply. Used recursively
|
||||
* @param array $settingsoutput The names and values of the changed settings. Used recursively
|
||||
* @return array $settingsoutput The names and values of the changed settings
|
||||
*/
|
||||
function admin_apply_default_settings($node=NULL, $unconditional=true) {
|
||||
global $CFG;
|
||||
function admin_apply_default_settings($node=null, $unconditional=true, $admindefaultsettings=array(), $settingsoutput=array()) {
|
||||
|
||||
if (is_null($node)) {
|
||||
core_plugin_manager::reset_caches();
|
||||
@@ -8021,26 +8026,46 @@ function admin_apply_default_settings($node=NULL, $unconditional=true) {
|
||||
if ($node instanceof admin_category) {
|
||||
$entries = array_keys($node->children);
|
||||
foreach ($entries as $entry) {
|
||||
admin_apply_default_settings($node->children[$entry], $unconditional);
|
||||
$settingsoutput = admin_apply_default_settings(
|
||||
$node->children[$entry], $unconditional, $admindefaultsettings, $settingsoutput
|
||||
);
|
||||
}
|
||||
|
||||
} else if ($node instanceof admin_settingpage) {
|
||||
foreach ($node->settings as $setting) {
|
||||
if (!$unconditional and !is_null($setting->get_setting())) {
|
||||
//do not override existing defaults
|
||||
continue;
|
||||
}
|
||||
$defaultsetting = $setting->get_defaultsetting();
|
||||
if (is_null($defaultsetting)) {
|
||||
// no value yet - default maybe applied after admin user creation or in upgradesettings
|
||||
continue;
|
||||
}
|
||||
foreach ($node->settings as $setting) {
|
||||
if (!$unconditional and !is_null($setting->get_setting())) {
|
||||
// Do not override existing defaults.
|
||||
continue;
|
||||
}
|
||||
$defaultsetting = $setting->get_defaultsetting();
|
||||
if (is_null($defaultsetting)) {
|
||||
// No value yet - default maybe applied after admin user creation or in upgradesettings.
|
||||
continue;
|
||||
}
|
||||
|
||||
$settingname = $node->name . '_' . $setting->name; // Get a unique name for the setting.
|
||||
|
||||
if (!array_key_exists($settingname, $admindefaultsettings)) { // Only update a setting if not already processed.
|
||||
$admindefaultsettings[$settingname] = $settingname;
|
||||
$settingsoutput[$settingname] = $defaultsetting;
|
||||
|
||||
// Set the default for this setting.
|
||||
$setting->write_setting($defaultsetting);
|
||||
$setting->write_setting_flags(null);
|
||||
} else {
|
||||
unset($admindefaultsettings[$settingname]); // Remove processed settings.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Call this function recursively until all settings are processed.
|
||||
if (($node instanceof admin_root) && (!empty($admindefaultsettings))) {
|
||||
$settingsoutput = admin_apply_default_settings(null, $unconditional, $admindefaultsettings, $settingsoutput);
|
||||
}
|
||||
// Just in case somebody modifies the list of active plugins directly.
|
||||
core_plugin_manager::reset_caches();
|
||||
|
||||
return $settingsoutput;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user