diff --git a/mod/quiz/backuplib.php b/mod/quiz/backuplib.php index 88a2b13a522..fe1d97dd6f0 100644 --- a/mod/quiz/backuplib.php +++ b/mod/quiz/backuplib.php @@ -247,8 +247,11 @@ $status = true; - $questions = get_records("quiz_questions","category",$category,"id"); - //If there is questions + // We'll fetch the questions sorted by parent so that questions with no parents + // (these are the ones which could be parents themselves) are backed up first. This + // is important for the recoding of the parent field during the restore process + $questions = get_records("quiz_questions","category",$category,"parent ASC, id"); + //If there are questions if ($questions) { //Write start tag $status =fwrite ($bf,start_tag("QUESTIONS",4,true)); diff --git a/mod/quiz/restorelib.php b/mod/quiz/restorelib.php index 4c388eaa14c..1a9c2c8ce4c 100644 --- a/mod/quiz/restorelib.php +++ b/mod/quiz/restorelib.php @@ -203,6 +203,8 @@ $question->hidden = backup_todb($que_info['#']['HIDDEN']['0']['#']); ////We have to recode the parent field + // This should work alright because we ordered the questions appropriately during backup so that + // questions that can be parents are restored first if ($question->parent and $parent = backup_getid($restore->backup_unique_code,"quiz_questions",$question->parent)) { $question->parent = $parent->new_id; }