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 3c33d77817230b96f6d65ef9c073864a55912114 1 parent 1de9151
Rajesh Taneja authored
Showing with 5 additions and 11 deletions.
  1. +5 −11 backup/moodle2/restore_stepslib.php
16 backup/moodle2/restore_stepslib.php
View
@@ -2425,8 +2425,6 @@ protected function process_availability($data) {
* - Activity includes completion info (file_exists)
*/
class restore_userscompletion_structure_step extends restore_structure_step {
- private $done = array();
-
/**
* To conditionally decide if this step must be executed
* Note the "settings" conditions are evaluated in the
@@ -2470,15 +2468,14 @@ protected function process_completion($data) {
$data->userid = $this->get_mappingid('user', $data->userid);
$data->timemodified = $this->apply_date_offset($data->timemodified);
+ // Find the existing record
+ $existing = $DB->get_record('course_modules_completion', array(
+ 'coursemoduleid' => $data->coursemoduleid,
+ 'userid' => $data->userid), 'id, timemodified');
// Check we didn't already insert one for this cmid and userid
// (there aren't supposed to be duplicates in that field, but
// it was possible until MDL-28021 was fixed).
- $key = $data->coursemoduleid . ',' . $data->userid;
- if (array_key_exists($key, $this->done)) {
- // Find the existing record
- $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;
@@ -2487,8 +2484,6 @@ protected function process_completion($data) {
} else {
// Normal entry where it doesn't exist already
$DB->insert_record('course_modules_completion', $data);
- // Remember this entry
- $this->done[$key] = true;
}
}
@@ -2496,7 +2491,6 @@ protected function after_execute() {
// This gets called once per activity (according to my testing).
// Clearing the array isn't strictly required, but avoids using
// unnecessary memory.
- $this->done = array();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.