MDL-63795 Administration: CLI upgrade apply all settings

This patch fixes a regression caused by MDL-62777.  MDL-62777 added output to inform
administrators of new default settings.  However, the recursion in the code did not
handle new settings made available as the result of the defaults of other settings
being set.
This patch fixes the issue, now all defaults are correctly set, even those exposed
after other defaults are set.
This commit is contained in:
Matt Porritt 2019-02-14 22:28:10 +00:00 committed by Matt Porritt
parent 6aacd8d6d1
commit 4be93382eb
2 changed files with 6 additions and 4 deletions

View File

@ -8404,10 +8404,12 @@ function admin_get_root($reload=false, $requirefulltree=true) {
* @return array $settingsoutput The names and values of the changed settings
*/
function admin_apply_default_settings($node=null, $unconditional=true, $admindefaultsettings=array(), $settingsoutput=array()) {
$counter = 0;
if (is_null($node)) {
core_plugin_manager::reset_caches();
$node = admin_get_root(true, true);
$counter = count($settingsoutput);
}
if ($node instanceof admin_category) {
@ -8420,7 +8422,7 @@ function admin_apply_default_settings($node=null, $unconditional=true, $admindef
} else if ($node instanceof admin_settingpage) {
foreach ($node->settings as $setting) {
if (!$unconditional and !is_null($setting->get_setting())) {
if (!$unconditional && !is_null($setting->get_setting())) {
// Do not override existing defaults.
continue;
}
@ -8446,7 +8448,7 @@ function admin_apply_default_settings($node=null, $unconditional=true, $admindef
}
// Call this function recursively until all settings are processed.
if (($node instanceof admin_root) && (!empty($admindefaultsettings))) {
if (($node instanceof admin_root) && ($counter != count($settingsoutput))) {
$settingsoutput = admin_apply_default_settings(null, $unconditional, $admindefaultsettings, $settingsoutput);
}
// Just in case somebody modifies the list of active plugins directly.

View File

@ -1092,7 +1092,7 @@ class mod_forum_mail_testcase extends advanced_testcase {
$htmlbase['user']['mailformat'] = 1;
$htmlbase['expectations'][0]['contents'] = array(
'~{\$a',
'~&(amp|lt|gt|quot|\#039);(?!course)',
'~&(amp|lt|gt|quot|\#039);(?!course|lang|version|iosappid|androidappid)',
'<div class="attachments">( *\n *)?<a href',
'<div class="subject">\n.*Hello Moodle', '>Moodle Forum', '>Welcome.*Moodle', '>Love Moodle', '>1\d1');
$htmlcases['HTML mail without ampersands, quotes or lt/gt'] = array('data' => $htmlbase);
@ -1121,7 +1121,7 @@ class mod_forum_mail_testcase extends advanced_testcase {
$newcase['expectations'][0]['subject'] = '.*101.*HTML text and image';
$newcase['expectations'][0]['contents'] = array(
'~{\$a',
'~&(amp|lt|gt|quot|\#039);(?!course)',
'~&(amp|lt|gt|quot|\#039);(?!course|lang|version|iosappid|androidappid)',
'<div class="attachments">( *\n *)?<a href',
'<div class="subject">\n.*HTML text and image', '>Moodle Forum',
'<p>Welcome to Moodle, '