Skip to content
Browse files

Now, when a category exists, if we are restoring to a different course,

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.
  • Loading branch information...
1 parent 51de923 commit 13d0fb4bbf6f2575fc24382cce6a0930ad34ac63 stronk7 committed Aug 3, 2003
Showing with 27 additions and 6 deletions.
  1. +27 −6 mod/quiz/restorelib.php
View
33 mod/quiz/restorelib.php
@@ -139,6 +139,12 @@ function quiz_restore_question_categories($category,$restore) {
} 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
@@ -190,8 +196,23 @@ function quiz_restore_questions ($old_category_id,$new_category_id,$info,$restor
$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) {
@@ -201,11 +222,14 @@ function quiz_restore_questions ($old_category_id,$new_category_id,$info,$restor
}
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
@@ -226,11 +250,8 @@ function quiz_restore_questions ($old_category_id,$new_category_id,$info,$restor
} else if ($question->qtype == "8") {
$status = quiz_restore_numerical($oldid,$newid,$que_info,$restore);
}
- } else {
- $status = false;
}
}
-
return $status;
}

0 comments on commit 13d0fb4

Please sign in to comment.
Something went wrong with that request. Please try again.