From 3643aadf80ff2a7eb35c8244953221a71367ae88 Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Tue, 14 Sep 2010 08:58:24 +0000 Subject: [PATCH] MDL-24177 backup - fix page next/prev ids to be propely mapped --- .../backup/moodle2/restore_lesson_stepslib.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mod/lesson/backup/moodle2/restore_lesson_stepslib.php b/mod/lesson/backup/moodle2/restore_lesson_stepslib.php index aa426a71356c0..da4da3672bf2e 100644 --- a/mod/lesson/backup/moodle2/restore_lesson_stepslib.php +++ b/mod/lesson/backup/moodle2/restore_lesson_stepslib.php @@ -74,8 +74,8 @@ protected function process_lesson_page($data) { $data = (object)$data; $oldid = $data->id; $data->lessonid = $this->get_new_parentid('lesson'); - $data->prevpageid = (empty($data->prevpageid)) ? 0 : $this->get_mappingid('lesson_page', $data->prevpageid); - $data->nextpageid = 0; //we don't know the id of the next page as it hasn't been created yet. + + // We'll remap all the prevpageid and nextpageid at the end, once all pages have been created $data->timemodified = $this->apply_date_offset($data->timemodified); $data->timecreated = $this->apply_date_offset($data->timecreated); @@ -169,11 +169,23 @@ protected function process_lesson_timer($data) { } protected function after_execute() { + global $DB; + // Add lesson mediafile, no need to match by itemname (just internally handled context) $this->add_related_files('mod_lesson', 'mediafile', null); // Add lesson page files, by lesson_page itemname $this->add_related_files('mod_lesson', 'page_contents', 'lesson_page'); + // Remap all the restored prevpageid and nextpageid now that we have all the pages and their mappings + $rs = $DB->get_recordset('lesson_pages', array('lessonid' => $this->task->get_activityid()), + '', 'id, prevpageid, nextpageid'); + foreach ($rs as $page) { + $page->prevpageid = (empty($page->prevpageid)) ? 0 : $this->get_mappingid('lesson_page', $page->prevpageid); + $page->nextpageid = (empty($page->nextpageid)) ? 0 : $this->get_mappingid('lesson_page', $page->nextpageid); + $DB->update_record('lesson_pages', $page); + } + $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