Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-32061 Use old lesson_answer ID and correct when restoring lesson …

…attempts
  • Loading branch information...
commit 38a8779d81576cf792625dde9c6761e8c4b3a2b4 1 parent 668a499
@andrewnicols andrewnicols authored
Showing with 13 additions and 1 deletion.
  1. +13 −1 mod/lesson/backup/moodle2/restore_lesson_stepslib.php
View
14 mod/lesson/backup/moodle2/restore_lesson_stepslib.php
@@ -103,6 +103,10 @@ protected function process_lesson_answer($data) {
$data->timemodified = $this->apply_date_offset($data->timemodified);
$data->timecreated = $this->apply_date_offset($data->timecreated);
+ // Set a dummy mapping to get the old ID so that it can be used by get_old_parentid when
+ // processing attempts. It will be corrected in after_execute
+ $this->set_mapping('lesson_answer', $data->id, 0);
+
// Answers need to be processed in order, so we store them in an
// instance variable and insert them in the after_execute stage
$this->answers[$data->id] = $data;
@@ -115,7 +119,9 @@ protected function process_lesson_attempt($data) {
$oldid = $data->id;
$data->lessonid = $this->get_new_parentid('lesson');
$data->pageid = $this->get_new_parentid('lesson_page');
- $data->answerid = $this->get_new_parentid('lesson_answer');
+
+ // We use the old answerid here as the answer isn't created until after_execute
+ $data->answerid = $this->get_old_parentid('lesson_answer');
$data->userid = $this->get_mappingid('user', $data->userid);
$data->timeseen = $this->apply_date_offset($data->timeseen);
@@ -181,6 +187,12 @@ protected function after_execute() {
foreach ($this->answers as $answer) {
$newitemid = $DB->insert_record('lesson_answers', $answer);
$this->set_mapping('lesson_answer', $answer->id, $newitemid);
+
+ // Update the lesson attempts to use the newly created answerid
+ $DB->set_field('lesson_attempts', 'answerid', $newitemid, array(
+ 'lessonid' => $answer->lessonid,
+ 'pageid' => $answer->pageid,
+ 'answerid' => $answer->id));
}
// Add lesson mediafile, no need to match by itemname (just internally handled context)
Please sign in to comment.
Something went wrong with that request. Please try again.