Skip to content

Commit

Permalink
MDL-46651 Backup: Handle duplicate course completions during restore
Browse files Browse the repository at this point in the history
Cron can cause duplicate completion records if triggered during a long
running restore process. If this is the case, replace the new record
with the record from the backup file
  • Loading branch information
Joshua Johnston committed Dec 11, 2014
1 parent 8542d18 commit 48d0e75
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion backup/moodle2/restore_stepslib.php
Expand Up @@ -2607,7 +2607,21 @@ public function process_course_completions($data) {
'timecompleted' => $this->apply_date_offset($data->timecompleted),
'reaggregate' => $data->reaggregate
);
$DB->insert_record('course_completions', $params);

$existing = $DB->get_record('course_completions', array(
'userid' => $data->userid,
'course' => $data->course
));

// MDL-46651 - If cron writes out a new record before we get to it
// then we should replace it with the Truth data from the backup.
// This may be obsolete after MDL-48518 is resolved
if ($existing) {
$params['id'] = $existing->id;
$DB->update_record('course_completions', $params);
} else {
$DB->insert_record('course_completions', $params);
}
}
}

Expand Down

0 comments on commit 48d0e75

Please sign in to comment.