]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14913 check vars b4 using
authordanmarsden <danmarsden>
Mon, 11 Aug 2008 05:09:44 +0000 (05:09 +0000)
committerdanmarsden <danmarsden>
Mon, 11 Aug 2008 05:09:44 +0000 (05:09 +0000)
mod/choice/restorelib.php

index 4e3ff69ce135ce5237629b143fff3b68b9b20932..474eabf9abdf7df9da61e99611c380b25398f21f 100644 (file)
@@ -195,70 +195,71 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
 
     //This function restores the choice_answers
     function choice_answers_restore_mods($choiceid,$info,$restore) {
-        global $CFG, $DB;
-
-        $status = true;
 
-        $answers = $info['MOD']['#']['ANSWERS']['0']['#']['ANSWER'];
-
-        //Iterate over answers
-        for($i = 0; $i < sizeof($answers); $i++) {
-            $ans_info = $answers[$i];
-            //traverse_xmlize($sub_info);                                                                 //Debug
-            //print_object ($GLOBALS['traverse_array']);                                                  //Debug
-            //$GLOBALS['traverse_array']="";                                                              //Debug
+        global $CFG;
 
-            //We'll need this later!!
-            $oldid = backup_todb($ans_info['#']['ID']['0']['#']);
-            $olduserid = backup_todb($ans_info['#']['USERID']['0']['#']);
-
-            //Now, build the CHOICE_ANSWERS record structure
-            $answer->choiceid = $choiceid;
-            $answer->userid = backup_todb($ans_info['#']['USERID']['0']['#']);
-            $answer->optionid = backup_todb($ans_info['#']['OPTIONID']['0']['#']);
-            $answer->timemodified = backup_todb($ans_info['#']['TIMEMODIFIED']['0']['#']);
-
-            //If the answer contains CHOICE_ANSWER, it's a pre 1.5 backup
-            if (!empty($ans_info['#']['CHOICE_ANSWER']['0']['#'])) {
-                //optionid was, in pre 1.5 backups, choice_answer
-                $answer->optionid = backup_todb($ans_info['#']['CHOICE_ANSWER']['0']['#']);
-            }
+        $status = true;
+        if (isset($info['MOD']['#']['ANSWERS']['0']['#']['ANSWER'])) {
+            $answers = $info['MOD']['#']['ANSWERS']['0']['#']['ANSWER'];
+
+            //Iterate over answers
+            for($i = 0; $i < sizeof($answers); $i++) {
+                $ans_info = $answers[$i];
+                //traverse_xmlize($sub_info);                                                                 //Debug
+                //print_object ($GLOBALS['traverse_array']);                                                  //Debug
+                //$GLOBALS['traverse_array']="";                                                              //Debug
+
+                //We'll need this later!!
+                $oldid = backup_todb($ans_info['#']['ID']['0']['#']);
+                $olduserid = backup_todb($ans_info['#']['USERID']['0']['#']);
+
+                //Now, build the CHOICE_ANSWERS record structure
+                $answer->choiceid = $choiceid;
+                $answer->userid = backup_todb($ans_info['#']['USERID']['0']['#']);
+                $answer->optionid = backup_todb($ans_info['#']['OPTIONID']['0']['#']);
+                $answer->timemodified = backup_todb($ans_info['#']['TIMEMODIFIED']['0']['#']);
+
+                //If the answer contains CHOICE_ANSWER, it's a pre 1.5 backup
+                if (!empty($ans_info['#']['CHOICE_ANSWER']['0']['#'])) {
+                    //optionid was, in pre 1.5 backups, choice_answer
+                    $answer->optionid = backup_todb($ans_info['#']['CHOICE_ANSWER']['0']['#']);
+                }
 
-            //We have to recode the optionid field
-            $option = backup_getid($restore->backup_unique_code,"choice_options",$answer->optionid);
-            if ($option) {
-                $answer->optionid = $option->new_id;
-            }
+                //We have to recode the optionid field
+                $option = backup_getid($restore->backup_unique_code,"choice_options",$answer->optionid);
+                if ($option) {
+                    $answer->optionid = $option->new_id;
+                }
 
-            //We have to recode the userid field
-            $user = backup_getid($restore->backup_unique_code,"user",$answer->userid);
-            if ($user) {
-                $answer->userid = $user->new_id;
-            }
+                //We have to recode the userid field
+                $user = backup_getid($restore->backup_unique_code,"user",$answer->userid);
+                if ($user) {
+                    $answer->userid = $user->new_id;
+                }
 
-            //The structure is equal to the db, so insert the choice_answers
-            $newid = $DB->insert_record ("choice_answers",$answer);
+                //The structure is equal to the db, so insert the choice_answers
+                $newid = insert_record ("choice_answers",$answer);
 
-            //Do some output
-            if (($i+1) % 50 == 0) {
-                if (!defined('RESTORE_SILENTLY')) {
-                    echo ".";
-                    if (($i+1) % 1000 == 0) {
-                        echo "<br />";
+                //Do some output
+                if (($i+1) % 50 == 0) {
+                    if (!defined('RESTORE_SILENTLY')) {
+                        echo ".";
+                        if (($i+1) % 1000 == 0) {
+                            echo "<br />";
+                        }
                     }
+                    backup_flush(300);
                 }
-                backup_flush(300);
-            }
 
-            if ($newid) {
-                //We have the newid, update backup_ids
-                backup_putid($restore->backup_unique_code,"choice_answers",$oldid,
+                if ($newid) {
+                    //We have the newid, update backup_ids
+                    backup_putid($restore->backup_unique_code,"choice_answers",$oldid,
                              $newid);
-            } else {
-                $status = false;
+                } else {
+                    $status = false;
+                }
             }
         }
-
         return $status;
     }