Permalink
Browse files

Restoring choices COMPLETED

  • Loading branch information...
1 parent b6f6c37 commit 304084d9370e4c784529550e0509ff34ead8e723 stronk7 committed Jun 1, 2003
Showing with 104 additions and 37 deletions.
  1. +11 −10 backup/STATUS.txt
  2. +93 −27 backup/mod/choice/restorelib.php
View
@@ -6,7 +6,8 @@ This documment shows the current status of the backup/restore option.
Backup: WORKING. COMPLETED but only assignments, resources,
choices and surveys.
-Restore: WORKING. COMPLETED but only assignments and resources.
+Restore: WORKING. COMPLETED but only assignments, resources
+ and choices.
========== ========== ========== ========== ========== ==========
@@ -159,10 +160,10 @@ Restore Details:
+ course data..................................DONE
+ user data....................................DONE
+ files........................................DONE
- x choices.........................................IN PROGRESS
- + course data..................................NO EXISTS
- + user data....................................NO EXISTS
- + files.(NOT EXISTS)...........................NO EXISTS
+ x choices.........................................DONE
+ + course data..................................DONE
+ + user data....................................DONE
+ + files.(NOT EXISTS)...........................DONE
x forums..........................................NO EXISTS
+ course data..................................NO EXISTS
+ user data....................................NO EXISTS
@@ -179,16 +180,16 @@ Restore Details:
+ course data..................................DONE
+ user data....................................DONE
+ files.(ARE COURSE FILES !!!).................DONE
- x surveys.........................................NO EXISTS
- + course data..................................NO EXISTS
- + user data....................................NO EXISTS
- + files.(NOT EXISTS)...........................NO EXISTS
+ x surveys.........................................IN PROGRESS
+ + course data..................................IN PROGRESS
+ + user data....................................IN PROGRESS
+ + files.(NOT EXISTS)...........................IN PROGRESS
- User files from temp.......................................DONE
- Course files from temp.....................................DONE
- Log entries................................................NO EXISTS
- Readjust instance in course_modules........................DONE
- Readjust modinfo in course (serialize).....................DONE
- - Delete old entries at restore end. .......................DONE
+ - Delete old entries at restore end. .......................DONE (COMMENTED !!!)
- From database...........................................DONE
- From filesystem.........................................DONE
- Upload backup files........................................DONE
@@ -21,40 +21,106 @@
//
//-----------------------------------------------------------
- function cchoice_restore_mods($bf,$preferences) {
-
+ //This function executes all the restore procedure about this mod
+ function choice_restore_mods($mod,$restore) {
+
global $CFG;
$status = true;
- //Iterate over choice table
- $choices = get_records ("choice","course",$preferences->backup_course,"id");
- if ($choices) {
- foreach ($choices as $choice) {
- //Start mod
- fwrite ($bf,start_tag("MOD",3,true));
- //Print choice data
- fwrite ($bf,full_tag("ID",4,false,$choice->id));
- fwrite ($bf,full_tag("MODTYPE",4,false,"choice"));
- fwrite ($bf,full_tag("NAME",4,false,$choice->name));
- fwrite ($bf,full_tag("TEXT",4,false,$choice->text));
- fwrite ($bf,full_tag("FORMAT",4,false,$choice->format));
- fwrite ($bf,full_tag("ANSWER1",4,false,$choice->answer1));
- fwrite ($bf,full_tag("ANSWER2",4,false,$choice->answer2));
- fwrite ($bf,full_tag("ANSWER3",4,false,$choice->answer3));
- fwrite ($bf,full_tag("ANSWER4",4,false,$choice->answer4));
- fwrite ($bf,full_tag("ANSWER5",4,false,$choice->answer5));
- fwrite ($bf,full_tag("ANSWER6",4,false,$choice->answer6));
- fwrite ($bf,full_tag("PUBLISH",4,false,$choice->publish));
- fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$choice->timemodified));
- //if we've selected to backup users info, then execute backup_choice_answers
- if ($preferences->mods["choice"]->userinfo) {
- $status = backup_choice_answers($bf,$preferences,$choice->id);
+ //Get record from backup_ids
+ $data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);
+
+ if ($data) {
+ //We have info, get and unserialize info
+ //First strip slashes
+ $temp = stripslashes($data->info);
+ //Now get completed xmlized object
+ $info = unserialize($temp);
+ //traverse_xmlize($info); //Debug
+ //print_object ($GLOBALS['traverse_array']); //Debug
+ //$GLOBALS['traverse_array']=""; //Debug
+
+ //Now, build the CHOICE record structure
+ $choice->course = $restore->course_id;
+ $choice->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
+ $choice->text = backup_todb($info['MOD']['#']['TEXT']['0']['#']);
+ $choice->format = backup_todb($info['MOD']['#']['FORMAT']['0']['#']);
+ $choice->answer1 = backup_todb($info['MOD']['#']['ANSWER1']['0']['#']);
+ $choice->answer2 = backup_todb($info['MOD']['#']['ANSWER2']['0']['#']);
+ $choice->answer3 = backup_todb($info['MOD']['#']['ANSWER3']['0']['#']);
+ $choice->answer4 = backup_todb($info['MOD']['#']['ANSWER4']['0']['#']);
+ $choice->answer5 = backup_todb($info['MOD']['#']['ANSWER5']['0']['#']);
+ $choice->answer6 = backup_todb($info['MOD']['#']['ANSWER6']['0']['#']);
+ $choice->publish = backup_todb($info['MOD']['#']['PUBLISH']['0']['#']);
+ $choice->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
+
+ //The structure is equal to the db, so insert the choice
+ $newid = insert_record ("choice",$choice);
+ if ($newid) {
+ //We have the newid, update backup_ids
+ backup_putid($restore->backup_unique_code,$mod->modtype,$mod->id,
+ $newid,$data->info);
+ //Now check if want to restore user data and do it.
+ if ($restore->mods[choice]->userinfo) {
+ //Restore choice_answers
+ $status = choice_answers_restore_mods ($newid,$info,$restore);
}
- //End mod
- $status =fwrite ($bf,end_tag("MOD",3,true));
+ } else {
+ $status = false;
}
+
+ } else {
+ $status = false;
}
+
+ return $status;
+ }
+
+ //This function restores the choice_answers
+ function choice_answers_restore_mods($choice_id,$info,$restore) {
+
+ global $CFG;
+
+ $status = true;
+
+ //Get the submissions array
+ $answers = $info['MOD']['#']['ANSWERS']['0']['#']['ANSWER'];
+
+ //Iterate over submissions
+ for($i = 0; $i < sizeof($answers); $i++) {
+ $sub_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($sub_info['#']['ID']['0']['#']);
+ $olduserid = backup_todb($sub_info['#']['USERID']['0']['#']);
+
+ //Now, build the CHOICE_ANSWERS record structure
+ $answer->choice = $choice_id;
+ $answer->userid = backup_todb($sub_info['#']['USERID']['0']['#']);
+ $answer->answer = backup_todb($sub_info['#']['CHOICE_ANSWER']['0']['#']);
+ $answer->timemodified = backup_todb($sub_info['#']['TIMEMODIFIED']['0']['#']);
+
+ //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 = insert_record ("choice_answers",$answer);
+ if ($newid) {
+ //We have the newid, update backup_ids
+ backup_putid($restore->backup_unique_code,"choice_answers",$oldid,
+ $newid);
+ } else {
+ $status = false;
+ }
+ }
+
return $status;
}

0 comments on commit 304084d

Please sign in to comment.