Quantcast
Channel: Backup and restore
Viewing all articles
Browse latest Browse all 6815

Re: Automated restore creating duplicate assignments etc.

$
0
0

by Pete Frost.  

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




Viewing all articles
Browse latest Browse all 6815

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>