}
$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);
+ }
}
}