Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-30466 Backup: Fixed duplicate completion record check error

  • Loading branch information...
commit d98fbf51080fc82dc67d9968d54d926ada3e9016 1 parent 779085b
Rajesh Taneja authored
Showing with 14 additions and 1 deletion.
  1. +14 −1 backup/moodle2/restore_stepslib.php
View
15 backup/moodle2/restore_stepslib.php
@@ -2271,7 +2271,20 @@ protected function process_completion($data) {
$data->userid = $this->get_mappingid('user', $data->userid);
$data->timemodified = $this->apply_date_offset($data->timemodified);
- $DB->insert_record('course_modules_completion', $data);
+ // Check we didn't already insert one for this cmid and userid
+ $existing = $DB->get_record('course_modules_completion', array(
+ 'coursemoduleid' => $data->coursemoduleid,
+ 'userid' => $data->userid), 'id, timemodified');
+ if ($existing) {
+ // Update it to these new values, but only if the time is newer
+ if ($existing->timemodified < $data->timemodified) {
+ $data->id = $existing->id;
+ $DB->update_record('course_modules_completion', $data);
+ }
+ } else {
+ // Normal entry where it doesn't exist already
+ $DB->insert_record('course_modules_completion', $data);
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.