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_stockcomments workshop_comments
27 // (CL,pk->id,fk->elementno) (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 //if necessary, write to restorelog and adjust date/time fields
52 if ($restore->course_startdateoffset
) {
53 restore_log_date_changes('Workshop', $restore, $info['MOD']['#'], array('SUBMISSIONSTART','ASSESSMENTSTART', 'SUBMISSIONEND', 'ASSESSMENTEND', 'RELEASEGRADES'));
55 //traverse_xmlize($info); //Debug
56 //print_object ($GLOBALS['traverse_array']); //Debug
57 //$GLOBALS['traverse_array']=""; //Debug
59 //Now, build the WORKSHOP record structure
60 $workshop->course
= $restore->course_id
;
61 $workshop->name
= backup_todb($info['MOD']['#']['NAME']['0']['#']);
62 $workshop->description
= backup_todb($info['MOD']['#']['DESCRIPTION']['0']['#']);
63 $workshop->wtype
= backup_todb($info['MOD']['#']['WTYPE']['0']['#']);
64 $workshop->nelements
= backup_todb($info['MOD']['#']['NELEMENTS']['0']['#']);
65 $workshop->nattachments
= backup_todb($info['MOD']['#']['NATTACHMENTS']['0']['#']);
66 $workshop->phase
= backup_todb($info['MOD']['#']['PHASE']['0']['#']);
67 $workshop->format
= backup_todb($info['MOD']['#']['FORMAT']['0']['#']);
68 $workshop->gradingstrategy
= backup_todb($info['MOD']['#']['GRADINGSTRATEGY']['0']['#']);
69 $workshop->resubmit
= backup_todb($info['MOD']['#']['RESUBMIT']['0']['#']);
70 $workshop->agreeassessments
= backup_todb($info['MOD']['#']['AGREEASSESSMENTS']['0']['#']);
71 $workshop->hidegrades
= backup_todb($info['MOD']['#']['HIDEGRADES']['0']['#']);
72 $workshop->anonymous
= backup_todb($info['MOD']['#']['ANONYMOUS']['0']['#']);
73 $workshop->includeself
= backup_todb($info['MOD']['#']['INCLUDESELF']['0']['#']);
74 $workshop->maxbytes
= backup_todb($info['MOD']['#']['MAXBYTES']['0']['#']);
75 $workshop->submissionstart
= backup_todb($info['MOD']['#']['SUBMISSIONSTART']['0']['#']);
76 $workshop->assessmentstart
= backup_todb($info['MOD']['#']['ASSESSMENTSTART']['0']['#']);
77 $workshop->deadline
= backup_todb($info['MOD']['#']['DEADLINE']['0']['#']);
78 $workshop->submissionend
= backup_todb($info['MOD']['#']['SUBMISSIONEND']['0']['#']);
79 $workshop->assessmentend
= backup_todb($info['MOD']['#']['ASSESSMENTEND']['0']['#']);
80 $workshop->releasegrades
= backup_todb($info['MOD']['#']['RELEASEGRADES']['0']['#']);
81 $workshop->grade
= backup_todb($info['MOD']['#']['GRADE']['0']['#']);
82 $workshop->gradinggrade
= backup_todb($info['MOD']['#']['GRADINGGRADE']['0']['#']);
83 $workshop->ntassessments
= backup_todb($info['MOD']['#']['NTASSESSMENTS']['0']['#']);
84 $workshop->assessmentcomps
= backup_todb($info['MOD']['#']['ASSESSMENTCOMPS']['0']['#']);
85 $workshop->nsassessments
= backup_todb($info['MOD']['#']['NSASSESSMENTS']['0']['#']);
86 $workshop->overallocation
= backup_todb($info['MOD']['#']['OVERALLOCATION']['0']['#']);
87 $workshop->timemodified
= backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
88 $workshop->teacherweight
= backup_todb($info['MOD']['#']['TEACHERWEIGHT']['0']['#']);
89 $workshop->showleaguetable
= backup_todb($info['MOD']['#']['SHOWLEAGUETABLE']['0']['#']);
90 $workshop->usepassword
= backup_todb($info['MOD']['#']['USEPASSWORD']['0']['#']);
91 $workshop->password
= backup_todb($info['MOD']['#']['PASSWORD']['0']['#']);
93 //If we have retrieved workshop->phase, it's a pre 1.5 backup, so we have to do
94 //some conversions before inserting to DB. Upwards compatibility :-)
95 if ( isset($info['MOD']['#']['PHASE']['0']['#'])) { //It's a pre-15 backup file
97 //Adjust the wtype field (mimetised from the upgrade script)
99 if ($workshop->includeself ||
$workshop->ntassessments
) {
100 $workshop->wtype
= 1; // 3 phases with grading grades
101 } else if ($workshop->nsassessments
) {
102 $workshop->wtype
= 2; // 5 phases with grading grades
105 //Now, adjust phases time limits (mimetised from the upgrade script too)
109 if ($now < $workshop->deadline
) {
110 $late = $workshop->deadline
;
112 $early = $workshop->deadline
;
114 if ($workshop->phase
> 1) {
115 $workshop->submissionstart
= $early;
117 $workshop->submissionstart
= $late;
119 if ($workshop->phase
> 2) {
120 $workshop->assessmentstart
= $early;
122 $workshop->assessmentstart
= $late;
124 if ($workshop->phase
> 3) {
125 $workshop->submissionend
= $early;
127 $workshop->submissionend
= $late;
129 if ($workshop->phase
> 4) {
130 $workshop->assessmentend
= $early;
132 $workshop->assessmentend
= $late;
134 if ($workshop->phase
> 5) {
135 $workshop->releasegrades
= $now;
137 $workshop->releasegrades
= $now +
(4 * 7 * 24 * 60 * 60); //Grades will be available in 4 weeks
141 //The structure is equal to the db, so insert the workshop
142 $newid = insert_record ("workshop",$workshop);
145 if (!defined('RESTORE_SILENTLY')) {
146 echo "<li>".get_string("modulename","workshop")." \"".format_string(stripslashes($workshop->name
),true)."\"</li>";
151 //We have the newid, update backup_ids
152 backup_putid($restore->backup_unique_code
,$mod->modtype
,
154 //We have to restore the workshop_elements table now (course level table)
155 $status = workshop_elements_restore_mods($newid,$info,$restore);
156 //Now check if want to restore user data and do it.
157 if (restore_userdata_selected($restore,'workshop',$mod->id
)) {
158 //Restore workshop_submissions
159 $status = workshop_submissions_restore_mods ($mod->id
, $newid,$info,$restore);
171 //This function restores the workshop_elements
172 function workshop_elements_restore_mods($workshop_id,$info,$restore) {
178 //Get the workshop_elements array
179 $elements = $info['MOD']['#']['ELEMENTS']['0']['#']['ELEMENT'];
181 //Iterate over workshop_elements
182 for($i = 0; $i < sizeof($elements); $i++
) {
183 $ele_info = $elements[$i];
184 //traverse_xmlize($ele_info); //Debug
185 //print_object ($GLOBALS['traverse_array']); //Debug
186 //$GLOBALS['traverse_array']=""; //Debug
188 //Now, build the WORKSHOP_ELEMENTS record structure
189 $element->workshopid
= $workshop_id;
190 $element->elementno
= backup_todb($ele_info['#']['ELEMENTNO']['0']['#']);
191 $element->description
= backup_todb($ele_info['#']['DESCRIPTION']['0']['#']);
192 $element->scale
= backup_todb($ele_info['#']['SCALE']['0']['#']);
193 $element->maxscore
= backup_todb($ele_info['#']['MAXSCORE']['0']['#']);
194 $element->weight
= backup_todb($ele_info['#']['WEIGHT']['0']['#']);
195 $element->stddev
= backup_todb($ele_info['#']['STDDEV']['0']['#']);
196 $element->totalassessments
= backup_todb($ele_info['#']['TOTALASSESSMENTS']['0']['#']);
198 //The structure is equal to the db, so insert the workshop_elements
199 $newid = insert_record ("workshop_elements",$element);
202 if (($i+
1) %
10 == 0) {
203 if (!defined('RESTORE_SILENTLY')) {
205 if (($i+
1) %
200 == 0) {
213 //We have to restore the workshop_rubrics table now (course level table)
214 $status = workshop_rubrics_restore_mods($workshop_id,$element->elementno
,$ele_info,$restore);
215 //We have to restore the workshop_stockcomment table now (course level table)
216 $status = workshop_stockcomments_restore_mods($workshop_id,$element->elementno
,$ele_info,$restore);
226 //This function restores the workshop_rubrics
227 function workshop_rubrics_restore_mods($workshop_id,$elementno,$info,$restore) {
233 //Get the workshop_rubrics array (optional)
234 if (isset($info['#']['RUBRICS']['0']['#']['RUBRIC'])) {
235 $rubrics = $info['#']['RUBRICS']['0']['#']['RUBRIC'];
237 //Iterate over workshop_rubrics
238 for($i = 0; $i < sizeof($rubrics); $i++
) {
239 $rub_info = $rubrics[$i];
240 //traverse_xmlize($rub_info); //Debug
241 //print_object ($GLOBALS['traverse_array']); //Debug
242 //$GLOBALS['traverse_array']=""; //Debug
244 //Now, build the WORKSHOP_RUBRICS record structure
245 $rubric->workshopid
= $workshop_id;
246 $rubric->elementno
= $elementno;
247 $rubric->rubricno
= backup_todb($rub_info['#']['RUBRICNO']['0']['#']);
248 $rubric->description
= backup_todb($rub_info['#']['DESCRIPTION']['0']['#']);
250 //The structure is equal to the db, so insert the workshop_rubrics
251 $newid = insert_record ("workshop_rubrics",$rubric);
254 if (($i+
1) %
10 == 0) {
255 if (!defined('RESTORE_SILENTLY')) {
257 if (($i+
1) %
200 == 0) {
273 //This function restores the workshop_stockcomments
274 function workshop_stockcomments_restore_mods($new_workshop_id, $elementno, $info, $restore) {
280 //Get the stockcomments array (optional)
281 if (isset($info['#']['STOCKCOMMENTS']['0']['#']['STOCKCOMMENT'])) {
282 $stockcomments = $info['#']['STOCKCOMMENTS']['0']['#']['STOCKCOMMENT'];
284 //Iterate over stock comments
285 for($i = 0; $i < sizeof($stockcomments); $i++
) {
286 $com_info = $stockcomments[$i];
287 //traverse_xmlize($com_info); //Debug
288 //print_object ($GLOBALS['traverse_array']); //Debug
289 //$GLOBALS['traverse_array']=""; //Debug
291 //Now, build the WORKSHOP_STOCKCOMMENTS record structure
292 $stockcomment->workshopid
= $new_workshop_id;
293 $stockcomment->elementno
= $elementno;
294 $stockcomment->comments
= backup_todb($com_info['#']['COMMENT_TEXT']['0']['#']);
296 //The structure is equal to the db, so insert the workshop_comment
297 $newid = insert_record ("workshop_stockcomments",$stockcomment);
300 if (($i+
1) %
50 == 0) {
301 if (!defined('RESTORE_SILENTLY')) {
303 if (($i+
1) %
1000 == 0) {
319 //This function restores the workshop_submissions
320 function workshop_submissions_restore_mods($old_workshop_id, $new_workshop_id,$info,$restore) {
326 //Get the submissions array
327 $submissions = $info['MOD']['#']['SUBMISSIONS']['0']['#']['SUBMISSION'];
329 //Iterate over submissions
330 for($i = 0; $i < sizeof($submissions); $i++
) {
331 $sub_info = $submissions[$i];
332 //traverse_xmlize($sub_info); //Debug
333 //print_object ($GLOBALS['traverse_array']); //Debug
334 //$GLOBALS['traverse_array']=""; //Debug
336 //We'll need this later!!
337 $oldid = backup_todb($sub_info['#']['ID']['0']['#']);
338 $olduserid = backup_todb($sub_info['#']['USERID']['0']['#']);
340 //Now, build the WORKSHOP_SUBMISSIONS record structure
341 $submission->workshopid
= $new_workshop_id;
342 $submission->userid
= backup_todb($sub_info['#']['USERID']['0']['#']);
343 $submission->title
= backup_todb($sub_info['#']['TITLE']['0']['#']);
344 $submission->timecreated
= backup_todb($sub_info['#']['TIMECREATED']['0']['#']);
345 $submission->timecreated +
= $restore->course_startdateoffset
;
346 $submission->mailed
= backup_todb($sub_info['#']['MAILED']['0']['#']);
347 $submission->description
= backup_todb($sub_info['#']['DESCRIPTION']['0']['#']);
348 $submission->gradinggrade
= backup_todb($sub_info['#']['GRADINGGRADE']['0']['#']);
349 $submission->finalgrade
= backup_todb($sub_info['#']['FINALGRADE']['0']['#']);
350 $submission->late
= backup_todb($sub_info['#']['LATE']['0']['#']);
351 $submission->nassessments
= backup_todb($sub_info['#']['NASSESSMENTS']['0']['#']);
353 //We have to recode the userid field
354 $user = backup_getid($restore->backup_unique_code
,"user",$olduserid);
356 $submission->userid
= $user->new_id
;
359 //The structure is equal to the db, so insert the workshop_submission
360 $newid = insert_record ("workshop_submissions",$submission);
363 if (($i+
1) %
50 == 0) {
364 if (!defined('RESTORE_SILENTLY')) {
366 if (($i+
1) %
1000 == 0) {
374 //We have the newid, update backup_ids
375 backup_putid($restore->backup_unique_code
,"workshop_submissions",$oldid,
378 //Now copy moddata associated files
379 $status = workshop_restore_files ($oldid, $newid,$restore);
380 //Now we need to restore workshop_assessments (user level table)
382 $status = workshop_assessments_restore_mods ($new_workshop_id, $newid,$sub_info,$restore);
392 //This function restores the workshop_assessments
393 function workshop_assessments_restore_mods($new_workshop_id, $new_submission_id,$info,$restore) {
399 //Get the assessments array (if any)
400 if (isset($info['#']['ASSESSMENTS']['0']['#']['ASSESSMENT'])) {
401 $assessments = $info['#']['ASSESSMENTS']['0']['#']['ASSESSMENT'];
403 //Iterate over assessments
404 for($i = 0; $i < sizeof($assessments); $i++
) {
405 $ass_info = $assessments[$i];
406 //traverse_xmlize($ass_info); //Debug
407 //print_object ($GLOBALS['traverse_array']); //Debug
408 //$GLOBALS['traverse_array']=""; //Debug
410 //We'll need this later!!
411 $oldid = backup_todb($ass_info['#']['ID']['0']['#']);
412 $olduserid = backup_todb($ass_info['#']['USERID']['0']['#']);
414 //Now, build the WORKSHOP_ASSESSMENTS record structure
415 $assessment->workshopid
= $new_workshop_id;
416 $assessment->submissionid
= $new_submission_id;
417 $assessment->userid
= backup_todb($ass_info['#']['USERID']['0']['#']);
418 $assessment->timecreated
= backup_todb($ass_info['#']['TIMECREATED']['0']['#']);
419 $assessment->timegraded
= backup_todb($ass_info['#']['TIMEGRADED']['0']['#']);
420 $assessment->timeagreed
= backup_todb($ass_info['#']['TIMEAGREED']['0']['#']);
421 $assessment->grade
= backup_todb($ass_info['#']['GRADE']['0']['#']);
422 $assessment->gradinggrade
= backup_todb($ass_info['#']['GRADINGGRADE']['0']['#']);
423 $assessment->mailed
= backup_todb($ass_info['#']['MAILED']['0']['#']);
424 $assessment->resubmission
= backup_todb($ass_info['#']['RESUBMISSION']['0']['#']);
425 $assessment->donotuse
= backup_todb($ass_info['#']['DONOTUSE']['0']['#']);
426 $assessment->generalcomment
= backup_todb($ass_info['#']['GENERALCOMMENT']['0']['#']);
427 $assessment->teachercomment
= backup_todb($ass_info['#']['TEACHERCOMMENT']['0']['#']);
429 //We have to recode the userid field
430 $user = backup_getid($restore->backup_unique_code
,"user",$olduserid);
432 $assessment->userid
= $user->new_id
;
435 //The structure is equal to the db, so insert the workshop_assessment
436 $newid = insert_record ("workshop_assessments",$assessment);
439 if (($i+
1) %
50 == 0) {
440 if (!defined('RESTORE_SILENTLY')) {
442 if (($i+
1) %
1000 == 0) {
450 //We have the newid, update backup_ids
451 backup_putid($restore->backup_unique_code
,"workshop_assessments",$oldid,
454 //Now we need to restore workshop_comments (user level table)
456 $status = workshop_comments_restore_mods ($new_workshop_id, $newid,$ass_info,$restore);
458 //Now we need to restore workshop_grades (user level table)
460 $status = workshop_grades_restore_mods ($new_workshop_id, $newid,$ass_info,$restore);
471 //This function restores the workshop_comments
472 function workshop_comments_restore_mods($new_workshop_id, $new_assessment_id,$info,$restore) {
478 //Get the comments array (optional)
479 if (isset($info['#']['COMMENTS']['0']['#']['COMMENT'])) {
480 $comments = $info['#']['COMMENTS']['0']['#']['COMMENT'];
482 //Iterate over comments
483 for($i = 0; $i < sizeof($comments); $i++
) {
484 $com_info = $comments[$i];
485 //traverse_xmlize($com_info); //Debug
486 //print_object ($GLOBALS['traverse_array']); //Debug
487 //$GLOBALS['traverse_array']=""; //Debug
489 //We'll need this later!!
490 $olduserid = backup_todb($com_info['#']['USERID']['0']['#']);
492 //Now, build the WORKSHOP_COMMENTS record structure
493 $comment->workshopid
= $new_workshop_id;
494 $comment->assessmentid
= $new_assessment_id;
495 $comment->userid
= backup_todb($com_info['#']['USERID']['0']['#']);
496 $comment->timecreated
= backup_todb($com_info['#']['TIMECREATED']['0']['#']);
497 $comment->mailed
= backup_todb($com_info['#']['MAILED']['0']['#']);
498 $comment->comments
= backup_todb($com_info['#']['COMMENT_TEXT']['0']['#']);
500 //We have to recode the userid field
501 $user = backup_getid($restore->backup_unique_code
,"user",$olduserid);
503 $comment->userid
= $user->new_id
;
506 //The structure is equal to the db, so insert the workshop_comment
507 $newid = insert_record ("workshop_comments",$comment);
510 if (($i+
1) %
50 == 0) {
511 if (!defined('RESTORE_SILENTLY')) {
513 if (($i+
1) %
1000 == 0) {
529 //This function restores the workshop_grades
530 function workshop_grades_restore_mods($new_workshop_id, $new_assessment_id,$info,$restore) {
536 //Get the grades array (optional)
537 if (isset($info['#']['GRADES']['0']['#']['GRADE'])) {
538 $grades = $info['#']['GRADES']['0']['#']['GRADE'];
540 //Iterate over grades
541 for($i = 0; $i < sizeof($grades); $i++
) {
542 $gra_info = $grades[$i];
543 //traverse_xmlize($gra_info); //Debug
544 //print_object ($GLOBALS['traverse_array']); //Debug
545 //$GLOBALS['traverse_array']=""; //Debug
547 //Now, build the WORKSHOP_GRADES record structure
548 $grade->workshopid
= $new_workshop_id;
549 $grade->assessmentid
= $new_assessment_id;
550 $grade->elementno
= backup_todb($gra_info['#']['ELEMENTNO']['0']['#']);
551 $grade->feedback
= backup_todb($gra_info['#']['FEEDBACK']['0']['#']);
552 $grade->grade
= backup_todb($gra_info['#']['GRADE_VALUE']['0']['#']);
554 //The structure is equal to the db, so insert the workshop_grade
555 $newid = insert_record ("workshop_grades",$grade);
558 if (($i+
1) %
50 == 0) {
559 if (!defined('RESTORE_SILENTLY')) {
561 if (($i+
1) %
1000 == 0) {
577 //This function copies the workshop related info from backup temp dir to course moddata folder,
578 //creating it if needed and recoding everything (submission_id)
579 function workshop_restore_files ($oldsubmiss, $newsubmiss, $restore) {
589 //First, we check to "course_id" exists and create is as necessary
591 $dest_dir = $CFG->dataroot
."/".$restore->course_id
;
592 $status = check_dir_exists($dest_dir,true);
594 //Now, locate course's moddata directory
595 $moddata_path = $CFG->dataroot
."/".$restore->course_id
."/".$CFG->moddata
;
597 //Check it exists and create it
598 $status = check_dir_exists($moddata_path,true);
600 //Now, locate workshop directory
602 $workshop_path = $moddata_path."/workshop";
603 //Check it exists and create it
604 $status = check_dir_exists($workshop_path,true);
607 //Now locate the temp dir we are gong to restore
609 $temp_path = $CFG->dataroot
."/temp/backup/".$restore->backup_unique_code
.
610 "/moddata/workshop/".$oldsubmiss;
612 if (is_dir($temp_path)) {
617 //If todo, we create the neccesary dirs in course moddata/workshop
618 if ($status and $todo) {
619 //First this workshop id
620 $this_workshop_path = $workshop_path."/".$newsubmiss;
621 $status = check_dir_exists($this_workshop_path,true);
622 //And now, copy temp_path to this_workshop_path
623 $status = backup_copy_file($temp_path, $this_workshop_path);
629 //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
630 //some texts in the module
631 function workshop_restore_wiki2markdown ($restore) {
637 //Convert workshop->description
638 if ($records = get_records_sql ("SELECT w.id, w.description, w.format
639 FROM {$CFG->prefix}workshop w,
640 {$CFG->prefix}backup_ids b
641 WHERE w.course = $restore->course_id AND
642 format = ".FORMAT_WIKI
. " AND
643 b.backup_code = $restore->backup_unique_code AND
644 b.table_name = 'workshop' AND
646 foreach ($records as $record) {
648 $record->description
= restore_decode_wiki_content($record->description
, $restore);
649 //Convert to Markdown
650 $wtm = new WikiToMarkdown();
651 $record->description
= $wtm->convert($record->description
, $restore->course_id
);
652 $record->format
= FORMAT_MARKDOWN
;
653 $status = update_record('workshop', addslashes_object($record));
656 if (($i+
1) %
1 == 0) {
657 if (!defined('RESTORE_SILENTLY')) {
659 if (($i+
1) %
20 == 0) {
671 //Return a content decoded to support interactivities linking. Every module
672 //should have its own. They are called automatically from
673 //workshop_decode_content_links_caller() function in each module
674 //in the restore process
675 function workshop_decode_content_links ($content,$restore) {
681 //Link to the list of workshops
683 $searchstring='/\$@(WORKSHOPINDEX)\*([0-9]+)@\$/';
685 preg_match_all($searchstring,$content,$foundset);
686 //If found, then we are going to look for its new id (in backup tables)
688 //print_object($foundset); //Debug
689 //Iterate over foundset[2]. They are the old_ids
690 foreach($foundset[2] as $old_id) {
691 //We get the needed variables here (course id)
692 $rec = backup_getid($restore->backup_unique_code
,"course",$old_id);
693 //Personalize the searchstring
694 $searchstring='/\$@(WORKSHOPINDEX)\*('.$old_id.')@\$/';
695 //If it is a link to this course, update the link to its new location
698 $result= preg_replace($searchstring,$CFG->wwwroot
.'/mod/workshop/index.php?id='.$rec->new_id
,$result);
700 //It's a foreign link so leave it as original
701 $result= preg_replace($searchstring,$restore->original_wwwroot
.'/mod/workshop/index.php?id='.$old_id,$result);
706 //Link to workshop view by moduleid
708 $searchstring='/\$@(WORKSHOPVIEWBYID)\*([0-9]+)@\$/';
710 preg_match_all($searchstring,$result,$foundset);
711 //If found, then we are going to look for its new id (in backup tables)
713 //print_object($foundset); //Debug
714 //Iterate over foundset[2]. They are the old_ids
715 foreach($foundset[2] as $old_id) {
716 //We get the needed variables here (course_modules id)
717 $rec = backup_getid($restore->backup_unique_code
,"course_modules",$old_id);
718 //Personalize the searchstring
719 $searchstring='/\$@(WORKSHOPVIEWBYID)\*('.$old_id.')@\$/';
720 //If it is a link to this course, update the link to its new location
723 $result= preg_replace($searchstring,$CFG->wwwroot
.'/mod/workshop/view.php?id='.$rec->new_id
,$result);
725 //It's a foreign link so leave it as original
726 $result= preg_replace($searchstring,$restore->original_wwwroot
.'/mod/workshop/view.php?id='.$old_id,$result);
734 //This function makes all the necessary calls to xxxx_decode_content_links()
735 //function in each module, passing them the desired contents to be decoded
736 //from backup format to destination site/course in order to mantain inter-activities
737 //working in the backup/restore process. It's called from restore_decode_content_links()
738 //function in restore process
739 function workshop_decode_content_links_caller($restore) {
743 //Process every WORKSHOP (description) in the course
744 if ($workshops = get_records_sql ("SELECT w.id, w.description
745 FROM {$CFG->prefix}workshop w
746 WHERE w.course = $restore->course_id")) {
747 //Iterate over each workshop->description
748 $i = 0; //Counter to send some output to the browser to avoid timeouts
749 foreach ($workshops as $workshop) {
752 $content = $workshop->description
;
753 $result = restore_decode_content_links_worker($content,$restore);
754 if ($result != $content) {
756 $workshop->description
= addslashes($result);
757 $status = update_record("workshop",$workshop);
759 if (!defined('RESTORE_SILENTLY')) {
760 echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
765 if (($i+
1) %
5 == 0) {
766 if (!defined('RESTORE_SILENTLY')) {
768 if (($i+
1) %
100 == 0) {
780 //This function returns a log record with all the necessay transformations
781 //done. It's used by restore_log_module() to restore modules log.
782 function workshop_restore_logs($restore,$log) {
786 //Depending of the action, we recode different things
787 switch ($log->action
) {
790 //Get the new_id of the module (to recode the info field)
791 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
793 $log->url
= "view.php?id=".$log->cmid
;
794 $log->info
= $mod->new_id
;
801 //Get the new_id of the module (to recode the info field)
802 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
804 $log->url
= "view.php?id=".$log->cmid
;
805 $log->info
= $mod->new_id
;
812 //Get the new_id of the module (to recode the info field)
813 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
815 $log->url
= "view.php?id=".$log->cmid
;
816 $log->info
= $mod->new_id
;
822 $log->url
= "index.php?id=".$log->course
;
827 //Get the new_id of the module (to recode the info field)
828 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
830 $log->url
= "view.php?id=".$log->cmid
;
831 $log->info
= $mod->new_id
;
838 //Get the new_id of the module (to recode the info field)
839 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
841 $log->url
= "view.php?id=".$log->cmid
;
842 $log->info
= $mod->new_id
;
849 //Get the new_id of the module (to recode the info field)
850 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
852 $log->url
= "view.php?id=".$log->cmid
;
853 $log->info
= $mod->new_id
;
860 //Get the new_id of the module (to recode the info field)
861 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
863 $log->url
= "view.php?id=".$log->cmid
;
864 $log->info
= $mod->new_id
;
871 //Get the new_id of the module (to recode the info field)
872 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
874 $log->url
= "view.php?id=".$log->cmid
;
875 $log->info
= $mod->new_id
;
882 //Get the new_id of the module (to recode the info field)
883 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
885 $log->url
= "view.php?id=".$log->cmid
;
886 $log->info
= $mod->new_id
;
891 case "assessments onl":
893 //Get the new_id of the module (to recode the info field)
894 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
896 $log->url
= "view.php?id=".$log->cmid
;
897 $log->info
= $mod->new_id
;
904 //Get the new_id of the module (to recode the info field)
905 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
907 $log->url
= "view.php?id=".$log->cmid
;
908 $log->info
= $mod->new_id
;
913 case "display grades":
915 //Get the new_id of the module (to recode the info field)
916 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
918 $log->url
= "view.php?id=".$log->cmid
;
919 $log->info
= $mod->new_id
;
924 case "over allocation":
926 //Get the new_id of the module (to recode the info field)
927 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
929 $log->url
= "view.php?id=".$log->cmid
;
930 $log->info
= $mod->new_id
;
937 //Get the new_id of the workshop assessments
938 $ass = backup_getid($restore->backup_unique_code
,"workshop_assessments",$log->info
);
940 $log->url
= "assessments.php?action=viewassessment&id=".$log->cmid
."&aid=".$ass->new_id
;
941 $log->info
= $ass->new_id
;
948 //Get the new_id of the workshop assessments
949 $ass = backup_getid($restore->backup_unique_code
,"workshop_assessments",$log->info
);
951 $log->url
= "assessments.php?action=viewassessment&id=".$log->cmid
."&aid=".$ass->new_id
;
952 $log->info
= $ass->new_id
;
958 if (!defined('RESTORE_SILENTLY')) {
959 echo "action (".$log->module
."-".$log->action
.") unknown. Not restored<br />"; //Debug