From 4be93382eb751f6e76f0503e7bb607fef82785db Mon Sep 17 00:00:00 2001 From: Matt Porritt Date: Thu, 14 Feb 2019 22:28:10 +0000 Subject: [PATCH] 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. --- lib/adminlib.php | 6 ++++-- mod/forum/tests/mail_test.php | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/adminlib.php b/lib/adminlib.php index 1f731a46f6e..902b5f2b720 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -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. diff --git a/mod/forum/tests/mail_test.php b/mod/forum/tests/mail_test.php index 7688acbf1df..c7f4a44d2a1 100644 --- a/mod/forum/tests/mail_test.php +++ b/mod/forum/tests/mail_test.php @@ -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)', '
( *\n *)?\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)', '