From 476cf5a282dd772b0c3127471602535a73f1ddab Mon Sep 17 00:00:00 2001 From: Benjamin Walker Date: Tue, 5 Mar 2024 09:49:41 +1000 Subject: [PATCH] MDL-81119 tool_recyclebin: Stop overriding unrelated forced config --- admin/tool/recyclebin/classes/category_bin.php | 16 ++++++++++------ admin/tool/recyclebin/classes/course_bin.php | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/admin/tool/recyclebin/classes/category_bin.php b/admin/tool/recyclebin/classes/category_bin.php index 67bd0072d32..3c18f62d528 100644 --- a/admin/tool/recyclebin/classes/category_bin.php +++ b/admin/tool/recyclebin/classes/category_bin.php @@ -117,7 +117,9 @@ class category_bin extends base_bin { // This hack will be removed once recycle bin switches to use its own backup mode, with // own preferences and 100% separate from MOODLE_AUTOMATED. // TODO: Remove this as part of MDL-65228. - $CFG->forced_plugin_settings['backup'] = ['backup_auto_storage' => 0, 'backup_auto_files' => 1]; + $forcedbackupsettings = $CFG->forced_plugin_settings['backup'] ?? null; + $CFG->forced_plugin_settings['backup']['backup_auto_storage'] = 0; + $CFG->forced_plugin_settings['backup']['backup_auto_files'] = 1; // Backup the course. $user = get_admin(); @@ -131,9 +133,9 @@ class category_bin extends base_bin { ); $controller->execute_plan(); - // We don't need the forced setting anymore, hence unsetting it. + // We don't need the forced setting anymore, hence restore previous settings. // TODO: Remove this as part of MDL-65228. - unset($CFG->forced_plugin_settings['backup']); + $CFG->forced_plugin_settings['backup'] = $forcedbackupsettings; // Grab the result. $result = $controller->get_results(); @@ -251,7 +253,9 @@ class category_bin extends base_bin { // This hack will be removed once recycle bin switches to use its own backup mode, with // own preferences and 100% separate from MOODLE_AUTOMATED. // TODO: Remove this as part of MDL-65228. - $CFG->forced_plugin_settings['restore'] = ['restore_general_users' => 1, 'restore_general_groups' => 1]; + $forcedrestoresettings = $CFG->forced_plugin_settings['restore'] ?? null; + $CFG->forced_plugin_settings['restore']['restore_general_users'] = 1; + $CFG->forced_plugin_settings['restore']['restore_general_groups'] = 1; // Define the import. $controller = new \restore_controller( @@ -287,9 +291,9 @@ class category_bin extends base_bin { // Run the import. $controller->execute_plan(); - // We don't need the forced setting anymore, hence unsetting it. + // We don't need the forced setting anymore, hence restore previous settings. // TODO: Remove this as part of MDL-65228. - unset($CFG->forced_plugin_settings['restore']); + $CFG->forced_plugin_settings['restore'] = $forcedrestoresettings; // Have finished with the controller, let's destroy it, freeing mem and resources. $controller->destroy(); diff --git a/admin/tool/recyclebin/classes/course_bin.php b/admin/tool/recyclebin/classes/course_bin.php index 28329fe196f..bfb19b4790c 100644 --- a/admin/tool/recyclebin/classes/course_bin.php +++ b/admin/tool/recyclebin/classes/course_bin.php @@ -121,7 +121,9 @@ class course_bin extends base_bin { // This hack will be removed once recycle bin switches to use its own backup mode, with // own preferences and 100% separate from MOODLE_AUTOMATED. // TODO: Remove this as part of MDL-65228. - $CFG->forced_plugin_settings['backup'] = ['backup_auto_storage' => 0, 'backup_auto_files' => 1]; + $forcedbackupsettings = $CFG->forced_plugin_settings['backup'] ?? null; + $CFG->forced_plugin_settings['backup']['backup_auto_storage'] = 0; + $CFG->forced_plugin_settings['backup']['backup_auto_files'] = 1; // Backup the activity. $user = get_admin(); @@ -145,9 +147,9 @@ class course_bin extends base_bin { $controller->execute_plan(); - // We don't need the forced setting anymore, hence unsetting it. + // We don't need the forced setting anymore, hence restore previous settings. // TODO: Remove this as part of MDL-65228. - unset($CFG->forced_plugin_settings['backup']); + $CFG->forced_plugin_settings['backup'] = $forcedbackupsettings; // Grab the result. $result = $controller->get_results(); @@ -252,7 +254,9 @@ class course_bin extends base_bin { // This hack will be removed once recycle bin switches to use its own backup mode, with // own preferences and 100% separate from MOODLE_AUTOMATED. // TODO: Remove this as part of MDL-65228. - $CFG->forced_plugin_settings['restore'] = ['restore_general_users' => 1, 'restore_general_groups' => 1]; + $forcedrestoresettings = $CFG->forced_plugin_settings['restore'] ?? null; + $CFG->forced_plugin_settings['restore']['restore_general_users'] = 1; + $CFG->forced_plugin_settings['restore']['restore_general_groups'] = 1; // Define the import. $controller = new \restore_controller( @@ -284,9 +288,9 @@ class course_bin extends base_bin { // Run the import. $controller->execute_plan(); - // We don't need the forced setting anymore, hence unsetting it. + // We don't need the forced setting anymore, hence restore previous settings. // TODO: Remove this as part of MDL-65228. - unset($CFG->forced_plugin_settings['restore']); + $CFG->forced_plugin_settings['restore'] = $forcedrestoresettings; // Have finished with the controller, let's destroy it, freeing mem and resources. $controller->destroy();