From 44582764afccf25a0ddb0dc35c3cd7cd5763ba27 Mon Sep 17 00:00:00 2001 From: gustav_delius Date: Tue, 11 Apr 2006 21:40:28 +0000 Subject: [PATCH] Fixed recoding of parent field for random questions --- question/restorelib.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/question/restorelib.php b/question/restorelib.php index da1e5b9a492..cb279106f1e 100644 --- a/question/restorelib.php +++ b/question/restorelib.php @@ -200,17 +200,6 @@ $question->qtype = $qtypenames[$question->qtype]; } - ////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) { - if ($parent = backup_getid($restore->backup_unique_code,"question",$question->parent)) { - $question->parent = $parent->new_id; - } else { - echo 'Could not recode parent '.$question->parent.' for question '.$question->id.'
'; - } - } - //Check if the question exists //by category, stamp, and version $question_exists = get_record ("question","category",$question->category, @@ -238,6 +227,7 @@ $restored_questions[$i]->newid = $newid; $restored_questions[$i]->oldid = $oldid; $restored_questions[$i]->qtype = $question->qtype; + $restored_questions[$i]->parent = $question->parent; $restored_questions[$i]->is_new = $creatingnewquestion; } @@ -249,10 +239,23 @@ $newid = $restored_questions[$i]->newid; $oldid = $restored_questions[$i]->oldid; $question->qtype = $restored_questions[$i]->qtype; + $question->parent = $restored_questions[$i]->parent; //If it's a new question in the DB, restore it if ($restored_questions[$i]->is_new) { + + ////We have to recode the parent field + if ($question->parent) { + if ($parent = backup_getid($restore->backup_unique_code,"question",$question->parent)) { + $question->parent = $parent->new_id; + } elseif ($question->parent = $oldid) { + $question->parent = $newid; + } else { + echo 'Could not recode parent '.$question->parent.' for question '.$question->id.'
'; + } + } + //Now, restore every question_answers in this question $status = question_restore_answers($oldid,$newid,$que_info,$restore); // Restore questiontype specific data