Skip to content

Commit

Permalink
MDL-68981 tool_recyclebin: Force necessary settings when restoring
Browse files Browse the repository at this point in the history
Created code to force the necessary settings for restore_item in:
  + course_bin class
  + category_bin class
  • Loading branch information
HuongNV13 committed Nov 30, 2022
1 parent e4fde5a commit 45e3d81
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions admin/tool/recyclebin/classes/category_bin.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ public function restore_item($item) {
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,
Expand Down Expand Up @@ -277,6 +287,10 @@ public function restore_item($item) {
// 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();

Expand Down
14 changes: 14 additions & 0 deletions admin/tool/recyclebin/classes/course_bin.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ public function restore_item($item) {
$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,
Expand Down Expand Up @@ -264,6 +274,10 @@ public function restore_item($item) {
// 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();

Expand Down

0 comments on commit 45e3d81

Please sign in to comment.