]> git.mjollnir.org Git - moodle.git/commitdiff
Now, when a category exists, if we are restoring to a different course,
authorstronk7 <stronk7>
Sun, 3 Aug 2003 16:36:29 +0000 (16:36 +0000)
committerstronk7 <stronk7>
Sun, 3 Aug 2003 16:36:29 +0000 (16:36 +0000)
set utomatically the publish field to 1.
If a question exists in DB (by category, questiontext and qtype) it isn't
duplicated.
This produce some problems restoring answes, but avoid duplicates.

mod/quiz/restorelib.php

index baba737792329f9c20ecefdfc1466deedc53bad0..29e092b02b8fe92e61e71e54f40e81c9b58f2408 100644 (file)
             } else {
                 //Exists, so get its id
                 $newid = $cat->id;
+                //If the existing category course and $restore->course_id are different,
+                //we must publish the existing category
+                if ($cat->course != $restore->course_id and $cat->publish == 0) {
+                    $cat->publish = 1;
+                    update_record("quiz_categories",$cat);
+                }
             }
 
             //Do some output
             $question->defaultgrade = backup_todb($que_info['#']['DEFAULTGRADE']['0']['#']);
             $question->qtype = backup_todb($que_info['#']['QTYPE']['0']['#']);
 
-            //The structure is equal to the db, so insert the quiz_questions
-            $newid = insert_record ("quiz_questions",$question);
+            //Check if the question exists
+            //by category,questiontext and qtype
+            $question_exists = get_record ("quiz_questions","category",$question->category,
+                                                            "questiontext",$question->questiontext,
+                                                            "qtype",$question->qtype);
+            //If the question exists, only record its id
+            if ($question_exists) {
+                $newid = $question_exists->id;
+                echo $question->name." exists";
+                $creatingnewquestion = false;
+            //Else, create a new question
+            } else {
+                //The structure is equal to the db, so insert the quiz_questions
+                $newid = insert_record ("quiz_questions",$question);
+                echo $question->name." not exists";
+                $creatingnewquestion = true;
+            }
 
             //Do some output
             if (($i+1) % 2 == 0) {
                 }
                 backup_flush(300);
             }
-
+            //Save newid to backup tables
             if ($newid) {
                 //We have the newid, update backup_ids
                 backup_putid($restore->backup_unique_code,"quiz_questions",$oldid,
                              $newid);
+            }
+            //If it's a new question in the DB, restore it
+            if ($creatingnewquestion) {
                 //Now, restore every quiz_answers in this question
                 $status = quiz_restore_answers($oldid,$newid,$que_info,$restore);
                 //Now, depending of the type of questions, invoke different functions
                 } else if ($question->qtype == "8") {
                     $status = quiz_restore_numerical($oldid,$newid,$que_info,$restore);
                 }
-            } else {
-                $status = false;
             }
         }
-
         return $status;
     }