]> git.mjollnir.org Git - moodle.git/commitdiff
Fixed recoding of parent field for random questions
authorgustav_delius <gustav_delius>
Tue, 11 Apr 2006 21:40:28 +0000 (21:40 +0000)
committergustav_delius <gustav_delius>
Tue, 11 Apr 2006 21:40:28 +0000 (21:40 +0000)
question/restorelib.php

index da1e5b9a49249212a90fe9c1701a0eddf17213bd..cb279106f1eaa532761bd9b4bed77bd50d709736 100644 (file)
                 $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.'<br />';
-                }
-            }
-
             //Check if the question exists
             //by category, stamp, and version
             $question_exists = get_record ("question","category",$question->category,
             $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;
         }
 
             $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.'<br />';
+                    }
+                }
+    
                 //Now, restore every question_answers in this question
                 $status = question_restore_answers($oldid,$newid,$que_info,$restore);
                 // Restore questiontype specific data