From ab48e73159ab623efc8a2b6c2a6a95ec00ec2a02 Mon Sep 17 00:00:00 2001 From: Andrew Robert Nicols Date: Mon, 30 Jan 2012 15:49:01 +0000 Subject: [PATCH] MDL-19421 Correct lesson dependency mapping on restore --- .../backup/moodle2/restore_lesson_stepslib.php | 29 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/mod/lesson/backup/moodle2/restore_lesson_stepslib.php b/mod/lesson/backup/moodle2/restore_lesson_stepslib.php index 00dc383f09d..6ceb21cc103 100644 --- a/mod/lesson/backup/moodle2/restore_lesson_stepslib.php +++ b/mod/lesson/backup/moodle2/restore_lesson_stepslib.php @@ -199,8 +199,31 @@ class restore_lesson_activity_structure_step extends restore_activity_structure_ } $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); + } } } -- 2.11.4.GIT