diff --git a/admin/tool/recyclebin/classes/category_bin.php b/admin/tool/recyclebin/classes/category_bin.php index b5bde99297f..67bd0072d32 100644 --- a/admin/tool/recyclebin/classes/category_bin.php +++ b/admin/tool/recyclebin/classes/category_bin.php @@ -243,6 +243,16 @@ class category_bin extends base_bin { throw new \moodle_exception("Could not create course to restore into."); } + // As far as recycle bin is using MODE_AUTOMATED, it observes the General restore settings. + // For recycle bin we want to ensure that backup files are always restore the users and groups information. + // In order to achieve that, we hack the setting here via $CFG->forced_plugin_settings, + // so it won't interfere other operations. + // See MDL-65218 and MDL-35773 for more information. + // 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]; + // Define the import. $controller = new \restore_controller( $tempdir, @@ -277,6 +287,10 @@ class category_bin extends base_bin { // Run the import. $controller->execute_plan(); + // We don't need the forced setting anymore, hence unsetting it. + // TODO: Remove this as part of MDL-65228. + unset($CFG->forced_plugin_settings['restore']); + // 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 0353c2c49ef..001158156e6 100644 --- a/admin/tool/recyclebin/classes/course_bin.php +++ b/admin/tool/recyclebin/classes/course_bin.php @@ -234,6 +234,16 @@ class course_bin extends base_bin { $fb = get_file_packer('application/vnd.moodle.backup'); $fb->extract_to_pathname($file, $fulltempdir); + // As far as recycle bin is using MODE_AUTOMATED, it observes the General restore settings. + // For recycle bin we want to ensure that backup files are always restore the users and groups information. + // In order to achieve that, we hack the setting here via $CFG->forced_plugin_settings, + // so it won't interfere other operations. + // See MDL-65218 and MDL-35773 for more information. + // 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]; + // Define the import. $controller = new \restore_controller( $tempdir, @@ -264,6 +274,10 @@ class course_bin extends base_bin { // Run the import. $controller->execute_plan(); + // We don't need the forced setting anymore, hence unsetting it. + // TODO: Remove this as part of MDL-65228. + unset($CFG->forced_plugin_settings['restore']); + // Have finished with the controller, let's destroy it, freeing mem and resources. $controller->destroy();