Permalink
Browse files

Merge branch 'wip-mdl-30466-m20' of git://github.com/rajeshtaneja/moo…

…dle into MOODLE_20_STABLE
  • Loading branch information...
2 parents 04b1bdf + d98fbf5 commit 027961fcf446fa38cf89820c03ba16532ff54d36 @stronk7 stronk7 committed Nov 29, 2011
Showing with 14 additions and 1 deletion.
  1. +14 −1 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);
+ }
}
}

0 comments on commit 027961f

Please sign in to comment.