Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-19421 Correct lesson dependency mapping on restore

  • Loading branch information...
commit e546d727872f24e15dfdbe9ec5347d5e177ed9ca 1 parent 9b228af
@andrewnicols andrewnicols authored stronk7 committed
Showing with 26 additions and 3 deletions.
  1. +26 −3 mod/lesson/backup/moodle2/restore_lesson_stepslib.php
View
29 mod/lesson/backup/moodle2/restore_lesson_stepslib.php
@@ -209,8 +209,31 @@ protected function after_execute() {
}
$rs->close();
- // TODO: somewhere at the end of the restore... when all the activities have been restored
- // TODO: we need to decode the lesson->activitylink that points to another activity in the course
- // TODO: great functionality that breaks self-contained principles, grrr
+ // Re-map the dependency and activitylink information
+ // If a depency or activitylink has no mapping in the backup data then it could either be a duplication of a
+ // lesson, or a backup/restore of a single lesson. We have no way to determine which and whether this is the
+ // same site and/or course. Therefore we try and retrieve a mapping, but fallback to the original value if one
+ // was not found. We then test to see whether the value found is valid for the course being restored into.
+ $lesson = $DB->get_record('lesson', array('id' => $this->task->get_activityid()), 'id, course, dependency, activitylink');
+ $updaterequired = false;
+ if (!empty($lesson->dependency)) {
+ $updaterequired = true;
+ $lesson->dependency = $this->get_mappingid('lesson', $lesson->dependency, $lesson->dependency);
+ if (!$DB->record_exists('lesson', array('id' => $lesson->dependency, 'course' => $lesson->course))) {
+ $lesson->dependency = 0;
+ }
+ }
+
+ if (!empty($lesson->activitylink)) {
+ $updaterequired = true;
+ $lesson->activitylink = $this->get_mappingid('course_module', $lesson->activitylink, $lesson->activitylink);
+ if (!$DB->record_exists('course_modules', array('id' => $lesson->activitylink, 'course' => $lesson->course))) {
+ $lesson->activitylink = 0;
+ }
+ }
+
+ if ($updaterequired) {
+ $DB->update_record('lesson', $lesson);
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.