2 //This php script contains all the stuff to backup/restore
5 //This is the "graphical" structure of the workshop mod:
12 // |------------------------------|-----------------------------------------------------|
16 // | workshop_submissions
17 // | (UL,pk->id,fk->workshopid,files)
19 // | |---------------------------| |--------------------------------| |
21 // workshop_elements workshop_grades workshop_assessments
22 // (CL,pk->id,fk->workshopid) (UL,pk->id,fk->assessmentid) (UL,pk->id,fk->submissionid)
23 // | ( fk->elementno ) |
26 // workshop_rubrics workshop_comments
27 // (CL,pk->id,fk->elementno) (UL,pk->id,fk->assessmentid)
29 // Meaning: pk->primary key field of the table
30 // fk->foreign key to link with parent
31 // nt->nested field (recursive data)
32 // CL->course level info
33 // UL->user level info
34 // files->table may have files)
36 //-----------------------------------------------------------
38 //This function executes all the restore procedure about this mod
39 function workshop_restore_mods($mod,$restore) {
45 //Get record from backup_ids
46 $data = backup_getid($restore->backup_unique_code
,$mod->modtype
,$mod->id
);
49 //Now get completed xmlized object
51 //traverse_xmlize($info); //Debug
52 //print_object ($GLOBALS['traverse_array']); //Debug
53 //$GLOBALS['traverse_array']=""; //Debug
55 //Now, build the WORKSHOP record structure
56 $workshop->course
= $restore->course_id
;
57 $workshop->name
= backup_todb($info['MOD']['#']['NAME']['0']['#']);
58 $workshop->description
= backup_todb($info['MOD']['#']['DESCRIPTION']['0']['#']);
59 $workshop->nelements
= backup_todb($info['MOD']['#']['NELEMENTS']['0']['#']);
60 $workshop->phase
= backup_todb($info['MOD']['#']['PHASE']['0']['#']);
61 $workshop->format
= backup_todb($info['MOD']['#']['FORMAT']['0']['#']);
62 $workshop->gradingstrategy
= backup_todb($info['MOD']['#']['GRADINGSTRATEGY']['0']['#']);
63 $workshop->resubmit
= backup_todb($info['MOD']['#']['RESUBMIT']['0']['#']);
64 $workshop->agreeassessments
= backup_todb($info['MOD']['#']['AGREEASSESSMENTS']['0']['#']);
65 $workshop->hidegrades
= backup_todb($info['MOD']['#']['HIDEGRADES']['0']['#']);
66 $workshop->anonymous
= backup_todb($info['MOD']['#']['ANONYMOUS']['0']['#']);
67 $workshop->includeself
= backup_todb($info['MOD']['#']['INCLUDESELF']['0']['#']);
68 $workshop->maxbytes
= backup_todb($info['MOD']['#']['MAXBYTES']['0']['#']);
69 $workshop->deadline
= backup_todb($info['MOD']['#']['DEADLINE']['0']['#']);
70 $workshop->grade
= backup_todb($info['MOD']['#']['GRADE']['0']['#']);
71 $workshop->ntassessments
= backup_todb($info['MOD']['#']['NTASSESSMENTS']['0']['#']);
72 $workshop->nsassessments
= backup_todb($info['MOD']['#']['NSASSESSMENTS']['0']['#']);
73 $workshop->overallocation
= backup_todb($info['MOD']['#']['OVERALLOCATION']['0']['#']);
74 $workshop->timemodified
= backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
75 $workshop->mergegrades
= backup_todb($info['MOD']['#']['MERGEGRADES']['0']['#']);
76 $workshop->teacherweight
= backup_todb($info['MOD']['#']['TEACHERWEIGHT']['0']['#']);
77 $workshop->peerweight
= backup_todb($info['MOD']['#']['PEERWEIGHT']['0']['#']);
78 $workshop->includeteachersgrade
= backup_todb($info['MOD']['#']['INCLUDETEACHERSGRADE']['0']['#']);
79 $workshop->biasweight
= backup_todb($info['MOD']['#']['BIASWEIGHT']['0']['#']);
80 $workshop->reliabilityweight
= backup_todb($info['MOD']['#']['RELIABILITYWEIGHT']['0']['#']);
81 $workshop->gradingweight
= backup_todb($info['MOD']['#']['GRADINGWEIGHT']['0']['#']);
82 $workshop->showleaguetable
= backup_todb($info['MOD']['#']['SHOWLEAGUETABLE']['0']['#']);
83 $workshop->teacherloading
= backup_todb($info['MOD']['#']['TEACHERLOADING']['0']['#']);
84 $workshop->assessmentstodrop
= backup_todb($info['MOD']['#']['ASSESSMENTSTODROP']['0']['#']);
86 //The structure is equal to the db, so insert the workshop
87 $newid = insert_record ("workshop",$workshop);
90 echo "<ul><li>".get_string("modulename","workshop")." \"".$workshop->name
."\"<br>";
94 //We have the newid, update backup_ids
95 backup_putid($restore->backup_unique_code
,$mod->modtype
,
97 //We have to restore the workshop_elements table now (course level table)
98 $status = workshop_elements_restore_mods($newid,$info,$restore);
99 //Now check if want to restore user data and do it.
100 if ($restore->mods
['workshop']->userinfo
) {
101 //Restore workshop_submissions
102 $status = workshop_submissions_restore_mods ($mod->id
, $newid,$info,$restore);
118 //This function restores the workshop_elements
119 function workshop_elements_restore_mods($workshop_id,$info,$restore) {
125 //Get the workshop_elements array
126 $elements = $info['MOD']['#']['ELEMENTS']['0']['#']['ELEMENT'];
128 //Iterate over workshop_elements
129 for($i = 0; $i < sizeof($elements); $i++
) {
130 $ele_info = $elements[$i];
131 //traverse_xmlize($ele_info); //Debug
132 //print_object ($GLOBALS['traverse_array']); //Debug
133 //$GLOBALS['traverse_array']=""; //Debug
135 //Now, build the WORKSHOP_ELEMENTS record structure
136 $element->workshopid
= $workshop_id;
137 $element->elementno
= backup_todb($ele_info['#']['ELEMENTNO']['0']['#']);
138 $element->description
= backup_todb($ele_info['#']['DESCRIPTION']['0']['#']);
139 $element->scale
= backup_todb($ele_info['#']['SCALE']['0']['#']);
140 $element->maxscore
= backup_todb($ele_info['#']['MAXSCORE']['0']['#']);
141 $element->weight
= backup_todb($ele_info['#']['WEIGHT']['0']['#']);
143 //The structure is equal to the db, so insert the workshop_elements
144 $newid = insert_record ("workshop_elements",$element);
147 if (($i+
1) %
10 == 0) {
149 if (($i+
1) %
200 == 0) {
156 //We have to restore the workshop_rubrics table now (course level table)
157 $status = workshop_rubrics_restore_mods($workshop_id,$element->elementno
,$ele_info,$restore);
167 //This function restores the workshop_rubrics
168 function workshop_rubrics_restore_mods($workshop_id,$elementno,$info,$restore) {
174 //Get the workshop_rubrics array (optional)
175 if (isset($info['#']['RUBRICS']['0']['#']['RUBRIC'])) {
176 $rubrics = $info['#']['RUBRICS']['0']['#']['RUBRIC'];
178 //Iterate over workshop_rubrics
179 for($i = 0; $i < sizeof($rubrics); $i++
) {
180 $rub_info = $rubrics[$i];
181 //traverse_xmlize($rub_info); //Debug
182 //print_object ($GLOBALS['traverse_array']); //Debug
183 //$GLOBALS['traverse_array']=""; //Debug
185 //Now, build the WORKSHOP_RUBRICS record structure
186 $rubric->workshopid
= $workshop_id;
187 $rubric->elementno
= $elementno;
188 $rubric->rubricno
= backup_todb($rub_info['#']['RUBRICNO']['0']['#']);
189 $rubric->description
= backup_todb($rub_info['#']['DESCRIPTION']['0']['#']);
191 //The structure is equal to the db, so insert the workshop_rubrics
192 $newid = insert_record ("workshop_rubrics",$rubric);
195 if (($i+
1) %
10 == 0) {
197 if (($i+
1) %
200 == 0) {
212 //This function restores the workshop_submissions
213 function workshop_submissions_restore_mods($old_workshop_id, $new_workshop_id,$info,$restore) {
219 //Get the submissions array
220 $submissions = $info['MOD']['#']['SUBMISSIONS']['0']['#']['SUBMISSION'];
222 //Iterate over submissions
223 for($i = 0; $i < sizeof($submissions); $i++
) {
224 $sub_info = $submissions[$i];
225 //traverse_xmlize($sub_info); //Debug
226 //print_object ($GLOBALS['traverse_array']); //Debug
227 //$GLOBALS['traverse_array']=""; //Debug
229 //We'll need this later!!
230 $oldid = backup_todb($sub_info['#']['ID']['0']['#']);
231 $olduserid = backup_todb($sub_info['#']['USERID']['0']['#']);
233 //Now, build the WORKSHOP_SUBMISSIONS record structure
234 $submission->workshopid
= $new_workshop_id;
235 $submission->userid
= backup_todb($sub_info['#']['USERID']['0']['#']);
236 $submission->title
= backup_todb($sub_info['#']['TITLE']['0']['#']);
237 $submission->timecreated
= backup_todb($sub_info['#']['TIMECREATED']['0']['#']);
238 $submission->mailed
= backup_todb($sub_info['#']['MAILED']['0']['#']);
239 $submission->teachergrade
= backup_todb($sub_info['#']['TEACHERGRADE']['0']['#']);
240 $submission->peergrade
= backup_todb($sub_info['#']['PEERGRADE']['0']['#']);
241 $submission->biasgrade
= backup_todb($sub_info['#']['BIASGRADE']['0']['#']);
242 $submission->reliabilitygrade
= backup_todb($sub_info['#']['RELIABILITYGRADE']['0']['#']);
243 $submission->gradinggrade
= backup_todb($sub_info['#']['GRADINGGRADE']['0']['#']);
244 $submission->finalgrade
= backup_todb($sub_info['#']['FINALGRADE']['0']['#']);
246 //We have to recode the userid field
247 $user = backup_getid($restore->backup_unique_code
,"user",$olduserid);
249 $submission->userid
= $user->new_id
;
252 //The structure is equal to the db, so insert the workshop_submission
253 $newid = insert_record ("workshop_submissions",$submission);
256 if (($i+
1) %
50 == 0) {
258 if (($i+
1) %
1000 == 0) {
265 //We have the newid, update backup_ids
266 backup_putid($restore->backup_unique_code
,"workshop_submissions",$oldid,
269 //Now copy moddata associated files
270 $status = workshop_restore_files ($oldid, $newid,$restore);
271 //Now we need to restore workshop_assessments (user level table)
273 $status = workshop_assessments_restore_mods ($new_workshop_id, $newid,$sub_info,$restore);
283 //This function restores the workshop_assessments
284 function workshop_assessments_restore_mods($new_workshop_id, $new_submission_id,$info,$restore) {
290 //Get the assessments array (if any)
291 if (isset($info['#']['ASSESSMENTS']['0']['#']['ASSESSMENT'])) {
292 $assessments = $info['#']['ASSESSMENTS']['0']['#']['ASSESSMENT'];
294 //Iterate over assessments
295 for($i = 0; $i < sizeof($assessments); $i++
) {
296 $ass_info = $assessments[$i];
297 //traverse_xmlize($ass_info); //Debug
298 //print_object ($GLOBALS['traverse_array']); //Debug
299 //$GLOBALS['traverse_array']=""; //Debug
301 //We'll need this later!!
302 $oldid = backup_todb($ass_info['#']['ID']['0']['#']);
303 $olduserid = backup_todb($ass_info['#']['USERID']['0']['#']);
305 //Now, build the WORKSHOP_ASSESSMENTS record structure
306 $assessment->workshopid
= $new_workshop_id;
307 $assessment->submissionid
= $new_submission_id;
308 $assessment->userid
= backup_todb($ass_info['#']['USERID']['0']['#']);
309 $assessment->timecreated
= backup_todb($ass_info['#']['TIMECREATED']['0']['#']);
310 $assessment->timegraded
= backup_todb($ass_info['#']['TIMEGRADED']['0']['#']);
311 $assessment->timeagreed
= backup_todb($ass_info['#']['TIMEAGREED']['0']['#']);
312 $assessment->grade
= backup_todb($ass_info['#']['GRADE']['0']['#']);
313 $assessment->gradinggrade
= backup_todb($ass_info['#']['GRADINGGRADE']['0']['#']);
314 $assessment->mailed
= backup_todb($ass_info['#']['MAILED']['0']['#']);
315 $assessment->resubmission
= backup_todb($ass_info['#']['RESUBMISSION']['0']['#']);
316 $assessment->donotuse
= backup_todb($ass_info['#']['DONOTUSE']['0']['#']);
317 $assessment->generalcomment
= backup_todb($ass_info['#']['GENERALCOMMENT']['0']['#']);
318 $assessment->teachercomment
= backup_todb($ass_info['#']['TEACHERCOMMENT']['0']['#']);
320 //We have to recode the userid field
321 $user = backup_getid($restore->backup_unique_code
,"user",$olduserid);
323 $assessment->userid
= $user->new_id
;
326 //The structure is equal to the db, so insert the workshop_assessment
327 $newid = insert_record ("workshop_assessments",$assessment);
330 if (($i+
1) %
50 == 0) {
332 if (($i+
1) %
1000 == 0) {
339 //We have the newid, update backup_ids
340 backup_putid($restore->backup_unique_code
,"workshop_assessments",$oldid,
343 //Now we need to restore workshop_comments (user level table)
345 $status = workshop_comments_restore_mods ($new_workshop_id, $newid,$ass_info,$restore);
347 //Now we need to restore workshop_grades (user level table)
349 $status = workshop_grades_restore_mods ($new_workshop_id, $newid,$ass_info,$restore);
360 //This function restores the workshop_comments
361 function workshop_comments_restore_mods($new_workshop_id, $new_assessment_id,$info,$restore) {
367 //Get the comments array (optional)
368 if (isset($info['#']['COMMENTS']['0']['#']['COMMENT'])) {
369 $comments = $info['#']['COMMENTS']['0']['#']['COMMENT'];
371 //Iterate over comments
372 for($i = 0; $i < sizeof($comments); $i++
) {
373 $com_info = $comments[$i];
374 //traverse_xmlize($com_info); //Debug
375 //print_object ($GLOBALS['traverse_array']); //Debug
376 //$GLOBALS['traverse_array']=""; //Debug
378 //We'll need this later!!
379 $olduserid = backup_todb($com_info['#']['USERID']['0']['#']);
381 //Now, build the WORKSHOP_COMMENTS record structure
382 $comment->workshopid
= $new_workshop_id;
383 $comment->assessmentid
= $new_assessment_id;
384 $comment->userid
= backup_todb($com_info['#']['USERID']['0']['#']);
385 $comment->timecreated
= backup_todb($com_info['#']['TIMECREATED']['0']['#']);
386 $comment->mailed
= backup_todb($com_info['#']['MAILED']['0']['#']);
387 $comment->comments
= backup_todb($com_info['#']['COMMENT_TEXT']['0']['#']);
389 //We have to recode the userid field
390 $user = backup_getid($restore->backup_unique_code
,"user",$olduserid);
392 $comment->userid
= $user->new_id
;
395 //The structure is equal to the db, so insert the workshop_comment
396 $newid = insert_record ("workshop_comments",$comment);
399 if (($i+
1) %
50 == 0) {
401 if (($i+
1) %
1000 == 0) {
416 //This function restores the workshop_grades
417 function workshop_grades_restore_mods($new_workshop_id, $new_assessment_id,$info,$restore) {
423 //Get the grades array (optional)
424 if (isset($info['#']['GRADES']['0']['#']['GRADE'])) {
425 $grades = $info['#']['GRADES']['0']['#']['GRADE'];
427 //Iterate over grades
428 for($i = 0; $i < sizeof($grades); $i++
) {
429 $gra_info = $grades[$i];
430 //traverse_xmlize($gra_info); //Debug
431 //print_object ($GLOBALS['traverse_array']); //Debug
432 //$GLOBALS['traverse_array']=""; //Debug
434 //Now, build the WORKSHOP_GRADES record structure
435 $grade->workshopid
= $new_workshop_id;
436 $grade->assessmentid
= $new_assessment_id;
437 $grade->elementno
= backup_todb($gra_info['#']['ELEMENTNO']['0']['#']);
438 $grade->feedback
= backup_todb($gra_info['#']['FEEDBACK']['0']['#']);
439 $grade->grade
= backup_todb($gra_info['#']['GRADE_VALUE']['0']['#']);
441 //The structure is equal to the db, so insert the workshop_grade
442 $newid = insert_record ("workshop_grades",$grade);
445 if (($i+
1) %
50 == 0) {
447 if (($i+
1) %
1000 == 0) {
462 //This function copies the workshop related info from backup temp dir to course moddata folder,
463 //creating it if needed and recoding everything (submission_id)
464 function workshop_restore_files ($oldsubmiss, $newsubmiss, $restore) {
474 //First, we check to "course_id" exists and create is as necessary
476 $dest_dir = $CFG->dataroot
."/".$restore->course_id
;
477 $status = check_dir_exists($dest_dir,true);
479 //Now, locate course's moddata directory
480 $moddata_path = $CFG->dataroot
."/".$restore->course_id
."/".$CFG->moddata
;
482 //Check it exists and create it
483 $status = check_dir_exists($moddata_path,true);
485 //Now, locate workshop directory
487 $workshop_path = $moddata_path."/workshop";
488 //Check it exists and create it
489 $status = check_dir_exists($workshop_path,true);
492 //Now locate the temp dir we are gong to restore
494 $temp_path = $CFG->dataroot
."/temp/backup/".$restore->backup_unique_code
.
495 "/moddata/workshop/".$oldsubmiss;
497 if (is_dir($temp_path)) {
502 //If todo, we create the neccesary dirs in course moddata/workshop
503 if ($status and $todo) {
504 //First this workshop id
505 $this_workshop_path = $workshop_path."/".$newsubmiss;
506 $status = check_dir_exists($this_workshop_path,true);
507 //And now, copy temp_path to this_workshop_path
508 $status = backup_copy_file($temp_path, $this_workshop_path);
514 //This function returns a log record with all the necessay transformations
515 //done. It's used by restore_log_module() to restore modules log.
516 function workshop_restore_logs($restore,$log) {
520 //Depending of the action, we recode different things
521 switch ($log->action
) {
524 //Get the new_id of the module (to recode the info field)
525 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
527 $log->url
= "view.php?id=".$log->cmid
;
528 $log->info
= $mod->new_id
;
535 //Get the new_id of the module (to recode the info field)
536 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
538 $log->url
= "view.php?id=".$log->cmid
;
539 $log->info
= $mod->new_id
;
546 //Get the new_id of the module (to recode the info field)
547 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
549 $log->url
= "view.php?id=".$log->cmid
;
550 $log->info
= $mod->new_id
;
556 $log->url
= "index.php?id=".$log->course
;
561 //Get the new_id of the module (to recode the info field)
562 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
564 $log->url
= "view.php?id=".$log->cmid
;
565 $log->info
= $mod->new_id
;
572 //Get the new_id of the module (to recode the info field)
573 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
575 $log->url
= "view.php?id=".$log->cmid
;
576 $log->info
= $mod->new_id
;
583 //Get the new_id of the module (to recode the info field)
584 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
586 $log->url
= "view.php?id=".$log->cmid
;
587 $log->info
= $mod->new_id
;
594 //Get the new_id of the module (to recode the info field)
595 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
597 $log->url
= "view.php?id=".$log->cmid
;
598 $log->info
= $mod->new_id
;
605 //Get the new_id of the module (to recode the info field)
606 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
608 $log->url
= "view.php?id=".$log->cmid
;
609 $log->info
= $mod->new_id
;
616 //Get the new_id of the module (to recode the info field)
617 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
619 $log->url
= "view.php?id=".$log->cmid
;
620 $log->info
= $mod->new_id
;
625 case "assessments onl":
627 //Get the new_id of the module (to recode the info field)
628 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
630 $log->url
= "view.php?id=".$log->cmid
;
631 $log->info
= $mod->new_id
;
638 //Get the new_id of the module (to recode the info field)
639 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
641 $log->url
= "view.php?id=".$log->cmid
;
642 $log->info
= $mod->new_id
;
647 case "display grades":
649 //Get the new_id of the module (to recode the info field)
650 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
652 $log->url
= "view.php?id=".$log->cmid
;
653 $log->info
= $mod->new_id
;
658 case "over allocation":
660 //Get the new_id of the module (to recode the info field)
661 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
663 $log->url
= "view.php?id=".$log->cmid
;
664 $log->info
= $mod->new_id
;
671 //Get the new_id of the workshop assessments
672 $ass = backup_getid($restore->backup_unique_code
,"workshop_assessments",$log->info
);
674 $log->url
= "assessments.php?action=viewassessment&id=".$log->cmid
."&aid=".$ass->new_id
;
675 $log->info
= $ass->new_id
;
682 //Get the new_id of the workshop assessments
683 $ass = backup_getid($restore->backup_unique_code
,"workshop_assessments",$log->info
);
685 $log->url
= "assessments.php?action=viewassessment&id=".$log->cmid
."&aid=".$ass->new_id
;
686 $log->info
= $ass->new_id
;
692 echo "action (".$log->module
."-".$log->action
.") unknow. Not restored<br>"; //Debug