Skip to content

Commit

Permalink
MDL-24177 backup - fix page next/prev ids to be propely mapped
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Sep 14, 2010
1 parent 8eabc1d commit 3643aad
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions mod/lesson/backup/moodle2/restore_lesson_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3643aad

Please sign in to comment.