From: moodler Date: Mon, 25 Aug 2003 02:52:19 +0000 (+0000) Subject: Sometimes there are no answers, so check existence first X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=eb94392c4babb90ef4bee22bde5cc8033142da9e;p=moodle.git Sometimes there are no answers, so check existence first --- diff --git a/mod/quiz/restorelib.php b/mod/quiz/restorelib.php index ccf230edb1..f2f9b75a54 100644 --- a/mod/quiz/restorelib.php +++ b/mod/quiz/restorelib.php @@ -264,42 +264,44 @@ $status = true; //Get the answers array - $answers = $info['#']['ANSWERS']['0']['#']['ANSWER']; - - //Iterate over answers - for($i = 0; $i < sizeof($answers); $i++) { - $ans_info = $answers[$i]; - //traverse_xmlize($ans_info); //Debug - //print_object ($GLOBALS['traverse_array']); //Debug - //$GLOBALS['traverse_array']=""; //Debug - - //We'll need this later!! - $oldid = backup_todb($ans_info['#']['ID']['0']['#']); - - //Now, build the QUIZ_ANSWERS record structure - $answer->question = $new_question_id; - $answer->answer = backup_todb($ans_info['#']['ANSWER_TEXT']['0']['#']); - $answer->fraction = backup_todb($ans_info['#']['FRACTION']['0']['#']); - $answer->feedback = backup_todb($ans_info['#']['FEEDBACK']['0']['#']); - - //The structure is equal to the db, so insert the quiz_answers - $newid = insert_record ("quiz_answers",$answer); - - //Do some output - if (($i+1) % 50 == 0) { - echo "."; - if (($i+1) % 1000 == 0) { - echo "
"; + if (isset($info['#']['ANSWERS']['0']['#']['ANSWER'])) { + $answers = $info['#']['ANSWERS']['0']['#']['ANSWER']; + + //Iterate over answers + for($i = 0; $i < sizeof($answers); $i++) { + $ans_info = $answers[$i]; + //traverse_xmlize($ans_info); //Debug + //print_object ($GLOBALS['traverse_array']); //Debug + //$GLOBALS['traverse_array']=""; //Debug + + //We'll need this later!! + $oldid = backup_todb($ans_info['#']['ID']['0']['#']); + + //Now, build the QUIZ_ANSWERS record structure + $answer->question = $new_question_id; + $answer->answer = backup_todb($ans_info['#']['ANSWER_TEXT']['0']['#']); + $answer->fraction = backup_todb($ans_info['#']['FRACTION']['0']['#']); + $answer->feedback = backup_todb($ans_info['#']['FEEDBACK']['0']['#']); + + //The structure is equal to the db, so insert the quiz_answers + $newid = insert_record ("quiz_answers",$answer); + + //Do some output + if (($i+1) % 50 == 0) { + echo "."; + if (($i+1) % 1000 == 0) { + echo "
"; + } + backup_flush(300); + } + + if ($newid) { + //We have the newid, update backup_ids + backup_putid($restore->backup_unique_code,"quiz_answers",$oldid, + $newid); + } else { + $status = false; } - backup_flush(300); - } - - if ($newid) { - //We have the newid, update backup_ids - backup_putid($restore->backup_unique_code,"quiz_answers",$oldid, - $newid); - } else { - $status = false; } }