Skip to content

Commit

Permalink
MDL-19421 Correct lesson dependency mapping on restore
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Robert Nicols authored and stronk7 committed Feb 20, 2012
1 parent 9b228af commit e546d72
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions mod/lesson/backup/moodle2/restore_lesson_stepslib.php
Expand Up @@ -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);
}
}
}

0 comments on commit e546d72

Please sign in to comment.