Too many bugs, not enough time!
[moodle.git] / mod / workshop / restorelib.php
blobf94cf7634cd59b9a7ea62af2ab969f940203403e
1 <?PHP //$Id$
2 //This php script contains all the stuff to backup/restore
3 //workshop mods
5 //This is the "graphical" structure of the workshop mod:
6 //
7 // workshop
8 // (CL,pk->id)
9 // |
10 // |
11 // |
12 // |------------------------------|-----------------------------------------------------|
13 // | |
14 // | |
15 // | |
16 // | workshop_submissions
17 // | (UL,pk->id,fk->workshopid,files)
18 // | |
19 // | |---------------------------| |--------------------------------| |
20 // | | | | | |
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 ) |
24 // | |
25 // | |
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) {
41 global $CFG;
43 $status = true;
45 //Get record from backup_ids
46 $data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);
48 if ($data) {
49 //Now get completed xmlized object
50 $info = $data->info;
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);
89 //Do some output
90 echo "<ul><li>".get_string("modulename","workshop")." \"".$workshop->name."\"<br>";
91 backup_flush(300);
93 if ($newid) {
94 //We have the newid, update backup_ids
95 backup_putid($restore->backup_unique_code,$mod->modtype,
96 $mod->id, $newid);
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);
104 } else {
105 $status = false;
108 //Finalize ul
109 echo "</ul>";
111 } else {
112 $status = false;
115 return $status;
118 //This function restores the workshop_elements
119 function workshop_elements_restore_mods($workshop_id,$info,$restore) {
121 global $CFG;
123 $status = true;
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);
146 //Do some output
147 if (($i+1) % 10 == 0) {
148 echo ".";
149 if (($i+1) % 200 == 0) {
150 echo "<br>";
152 backup_flush(300);
155 if ($newid) {
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);
158 } else {
159 $status = false;
163 return $status;
167 //This function restores the workshop_rubrics
168 function workshop_rubrics_restore_mods($workshop_id,$elementno,$info,$restore) {
170 global $CFG;
172 $status = true;
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);
194 //Do some output
195 if (($i+1) % 10 == 0) {
196 echo ".";
197 if (($i+1) % 200 == 0) {
198 echo "<br>";
200 backup_flush(300);
203 if (!$newid) {
204 $status = false;
208 return $status;
212 //This function restores the workshop_submissions
213 function workshop_submissions_restore_mods($old_workshop_id, $new_workshop_id,$info,$restore) {
215 global $CFG;
217 $status = true;
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);
248 if ($user) {
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);
255 //Do some output
256 if (($i+1) % 50 == 0) {
257 echo ".";
258 if (($i+1) % 1000 == 0) {
259 echo "<br>";
261 backup_flush(300);
264 if ($newid) {
265 //We have the newid, update backup_ids
266 backup_putid($restore->backup_unique_code,"workshop_submissions",$oldid,
267 $newid);
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)
272 if ($status) {
273 $status = workshop_assessments_restore_mods ($new_workshop_id, $newid,$sub_info,$restore);
275 } else {
276 $status = false;
280 return $status;
283 //This function restores the workshop_assessments
284 function workshop_assessments_restore_mods($new_workshop_id, $new_submission_id,$info,$restore) {
286 global $CFG;
288 $status = true;
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);
322 if ($user) {
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);
329 //Do some output
330 if (($i+1) % 50 == 0) {
331 echo ".";
332 if (($i+1) % 1000 == 0) {
333 echo "<br>";
335 backup_flush(300);
338 if ($newid) {
339 //We have the newid, update backup_ids
340 backup_putid($restore->backup_unique_code,"workshop_assessments",$oldid,
341 $newid);
343 //Now we need to restore workshop_comments (user level table)
344 if ($status) {
345 $status = workshop_comments_restore_mods ($new_workshop_id, $newid,$ass_info,$restore);
347 //Now we need to restore workshop_grades (user level table)
348 if ($status) {
349 $status = workshop_grades_restore_mods ($new_workshop_id, $newid,$ass_info,$restore);
351 } else {
352 $status = false;
357 return $status;
360 //This function restores the workshop_comments
361 function workshop_comments_restore_mods($new_workshop_id, $new_assessment_id,$info,$restore) {
363 global $CFG;
365 $status = true;
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);
391 if ($user) {
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);
398 //Do some output
399 if (($i+1) % 50 == 0) {
400 echo ".";
401 if (($i+1) % 1000 == 0) {
402 echo "<br>";
404 backup_flush(300);
407 if (!$newid) {
408 $status = false;
413 return $status;
416 //This function restores the workshop_grades
417 function workshop_grades_restore_mods($new_workshop_id, $new_assessment_id,$info,$restore) {
419 global $CFG;
421 $status = true;
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);
444 //Do some output
445 if (($i+1) % 50 == 0) {
446 echo ".";
447 if (($i+1) % 1000 == 0) {
448 echo "<br>";
450 backup_flush(300);
453 if (!$newid) {
454 $status = false;
459 return $status;
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) {
466 global $CFG;
468 $status = true;
469 $todo = false;
470 $moddata_path = "";
471 $workshop_path = "";
472 $temp_path = "";
474 //First, we check to "course_id" exists and create is as necessary
475 //in CFG->dataroot
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
486 if ($status) {
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
493 if ($status) {
494 $temp_path = $CFG->dataroot."/temp/backup/".$restore->backup_unique_code.
495 "/moddata/workshop/".$oldsubmiss;
496 //Check it exists
497 if (is_dir($temp_path)) {
498 $todo = true;
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);
511 return $status;
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) {
518 $status = false;
520 //Depending of the action, we recode different things
521 switch ($log->action) {
522 case "add":
523 if ($log->cmid) {
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);
526 if ($mod) {
527 $log->url = "view.php?id=".$log->cmid;
528 $log->info = $mod->new_id;
529 $status = true;
532 break;
533 case "update":
534 if ($log->cmid) {
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);
537 if ($mod) {
538 $log->url = "view.php?id=".$log->cmid;
539 $log->info = $mod->new_id;
540 $status = true;
543 break;
544 case "view":
545 if ($log->cmid) {
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);
548 if ($mod) {
549 $log->url = "view.php?id=".$log->cmid;
550 $log->info = $mod->new_id;
551 $status = true;
554 break;
555 case "view all":
556 $log->url = "index.php?id=".$log->course;
557 $status = true;
558 break;
559 case "submit":
560 if ($log->cmid) {
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);
563 if ($mod) {
564 $log->url = "view.php?id=".$log->cmid;
565 $log->info = $mod->new_id;
566 $status = true;
569 break;
570 case "resubmit":
571 if ($log->cmid) {
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);
574 if ($mod) {
575 $log->url = "view.php?id=".$log->cmid;
576 $log->info = $mod->new_id;
577 $status = true;
580 break;
581 case "league table":
582 if ($log->cmid) {
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);
585 if ($mod) {
586 $log->url = "view.php?id=".$log->cmid;
587 $log->info = $mod->new_id;
588 $status = true;
591 break;
592 case "submissions":
593 if ($log->cmid) {
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);
596 if ($mod) {
597 $log->url = "view.php?id=".$log->cmid;
598 $log->info = $mod->new_id;
599 $status = true;
602 break;
603 case "allow both":
604 if ($log->cmid) {
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);
607 if ($mod) {
608 $log->url = "view.php?id=".$log->cmid;
609 $log->info = $mod->new_id;
610 $status = true;
613 break;
614 case "set up":
615 if ($log->cmid) {
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);
618 if ($mod) {
619 $log->url = "view.php?id=".$log->cmid;
620 $log->info = $mod->new_id;
621 $status = true;
624 break;
625 case "assessments onl":
626 if ($log->cmid) {
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);
629 if ($mod) {
630 $log->url = "view.php?id=".$log->cmid;
631 $log->info = $mod->new_id;
632 $status = true;
635 break;
636 case "close":
637 if ($log->cmid) {
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);
640 if ($mod) {
641 $log->url = "view.php?id=".$log->cmid;
642 $log->info = $mod->new_id;
643 $status = true;
646 break;
647 case "display grades":
648 if ($log->cmid) {
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);
651 if ($mod) {
652 $log->url = "view.php?id=".$log->cmid;
653 $log->info = $mod->new_id;
654 $status = true;
657 break;
658 case "over allocation":
659 if ($log->cmid) {
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);
662 if ($mod) {
663 $log->url = "view.php?id=".$log->cmid;
664 $log->info = $mod->new_id;
665 $status = true;
668 break;
669 case "assess":
670 if ($log->cmid) {
671 //Get the new_id of the workshop assessments
672 $ass = backup_getid($restore->backup_unique_code,"workshop_assessments",$log->info);
673 if ($ass) {
674 $log->url = "assessments.php?action=viewassessment&id=".$log->cmid."&aid=".$ass->new_id;
675 $log->info = $ass->new_id;
676 $status = true;
679 break;
680 case "grade":
681 if ($log->cmid) {
682 //Get the new_id of the workshop assessments
683 $ass = backup_getid($restore->backup_unique_code,"workshop_assessments",$log->info);
684 if ($ass) {
685 $log->url = "assessments.php?action=viewassessment&id=".$log->cmid."&aid=".$ass->new_id;
686 $log->info = $ass->new_id;
687 $status = true;
690 break;
691 default:
692 echo "action (".$log->module."-".$log->action.") unknow. Not restored<br>"; //Debug
693 break;
696 if ($status) {
697 $status = $log;
699 return $status;