MDL-74548 backup: Refactor course copies

This patch modifies the way copy data is shared in order to mitigate potential race conditions
and ensure that the serialised controller stored in the DB is always in a valid state.

The restore controller is now considered the "source of truth" for all information about the
copy operation. Backup controllers can no longer contain information about course copies.

As copy creation is not atomic, it is still possible for copy controllers to become orphaned or
exist in an invalid state. To mitigate this the backup cleanup task has been modified to call
a new helper method copy_helper::cleanup_orphaned_copy_controllers.

Summary of changes in this patch:

    - Copy data must now be passed through the restore controller's constructor
    - base_controller::get_copy has been deprecated in favour of restore_controller::get_copy
    - base_controller::set_copy has been deprecated without replacement
    - core_backup\copy\copy has been deprecated, use copy_helper.class.php's copy_helper instead
    - backup_cleanup_task will now clean up orphaned controllers from copy operations that went awry

Thanks to Peter Burnett for assiting with testing this patch.
This commit is contained in:
Cameron Ball
2022-06-29 09:35:58 +08:00
parent bbff432ffa
commit 53dd76348c
15 changed files with 398 additions and 120 deletions
+3 -2
View File
@@ -65,8 +65,10 @@ class asynchronous_copy_task extends adhoc_task {
delete_course($restorerecord->itemid, false); // Clean up partially created destination course.
return; // Return early as we can't continue.
}
$rc = \restore_controller::load_controller($restoreid); // Get the restore controller by restore id.
$bc->set_progress(new \core\progress\db_updater($backuprecord->id, 'backup_controllers', 'progress'));
$copyinfo = $bc->get_copy();
$copyinfo = $rc->get_copy();
$backupplan = $bc->get_plan();
$keepuserdata = (bool)$copyinfo->userdata;
@@ -110,7 +112,6 @@ class asynchronous_copy_task extends adhoc_task {
$file = $results['backup_destination'];
$file->extract_to_pathname(get_file_packer('application/vnd.moodle.backup'), $backupbasepath);
// Start the restore process.
$rc = \restore_controller::load_controller($restoreid); // Get the restore controller by restore id.
$rc->set_progress(new \core\progress\db_updater($restorerecord->id, 'backup_controllers', 'progress'));
$rc->prepare_copy();