Automated restore creating duplicate assignments etc.

Re: Automated restore creating duplicate assignments etc.

by Pete Frost -
Number of replies: 0

I've managed to fix this. It turns out that the restore_controller class doesn't actually do any deleting for you (as far as I can tell), despite accepting a target parameter (TARGET_CURRENT_DELETING) which seem to imply that it will.

The Moodle web interface calls the following static method before it triggers the restore controller:

restore_dbops::delete_course_content($courseid);

Once I added that to my code, it started working as expected. I ended up with:

$transaction = $DB->start_delegated_transaction();
try {
restore_dbops::delete_course_content($this->courseid);

// Define the import.
$controller = new \restore_controller(
$tempdir,
$this->courseid,
\backup::INTERACTIVE_NO,
\backup::MODE_GENERAL,
get_admin()->id,
\backup::TARGET_CURRENT_DELETING
);
// check whether restore might work
$controller->execute_precheck();
// Run the import.
$controller->execute_plan();
// commit changes to database
$transaction->allow_commit();
} catch(\moodle_exception $e) {
$transaction->rollback($e);
} f



Average of ratings: Useful (1)