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

Automated restore creating duplicate assignments etc.

$
0
0

by Pete Frost.  

Hi all,

  I've been tasked with creating some PHP code that will automatically restore a course (which still exists) from an earlier backup. The backup is stored in moodle2 format, untar'd. It's then put into a temporary directory before the restore controller is executed. Here's the code that executes the controller:

$transaction = $DB->start_delegated_transaction();
try {
// 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();

The intention is for the restored course contents to completely replace whatever's currently in the course. However, what actually seems to happen is that the restored assignments etc. are appended to the course (so whatever was in the course before the restore was done is still there). Judging by the contents of the Moodle database table (mdl_assign), the restored assignments are being given a new id and the old ones are being left in the table.

I derived the controller parameters by looking at what parameters are passed to the controller when I manually do a restore via the Moodle web interface, so I'd expect them to be correct, but perhaps they're not. My script is being run via CLI rather than via the web but I can't see why that would make any difference.

Can anyone spot what I'm doing wrong? We're running Moodle 3.1. Here's the debug output that appears in my terminal:


instantiating restore controller bccddfa7443a49163c0690de7b1828e2
setting controller status to 100
loading backup info
loading controller plan
setting controller status to 300
checking plan security
setting controller status to 600
saving controller to db
calculating controller checksum dac228e0057a2c01530031990df38738
loading controller from db
setting controller status to 700
saving controller to db
calculating controller checksum adfbb68305e6df83c3df47aef6afb075
loading controller from db
setting controller status to 800
processing file aliases queue
setting controller status to 1000
saving controller to db



Viewing all articles
Browse latest Browse all 6621

Trending Articles



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