2 //This php script contains all the stuff to backup/restore
5 //This is the "graphical" structure of the glossary mod:
7 // glossary ----------------------------------------- glossary_categories
8 // (CL,pk->id) (CL,pk->id,fk->glossaryid)
12 // glossary_entries --------------------------------glossary_entries_categories
13 // (UL,pk->id, fk->glossaryid, files) | (UL, pk->categoryid,entryid)
15 // | |--------------------glossary_ratings
16 // | | (UL, pk->id, pk->entryid)
17 // glossary_comments |
18 // (UL,pk->id, fk->entryid) |---------------------glossary_alias
19 // (UL, pk->id, pk->entryid)
22 // Meaning: pk->primary key field of the table
23 // fk->foreign key to link with parent
24 // nt->nested field (recursive data)
25 // CL->course level info
26 // UL->user level info
27 // files->table may have files)
29 //-----------------------------------------------------------
31 //This function executes all the restore procedure about this mod
32 function glossary_restore_mods($mod,$restore) {
38 //Get record from backup_ids
39 $data = backup_getid($restore->backup_unique_code
,$mod->modtype
,$mod->id
);
42 //Now get completed xmlized object
44 // if necessary, write to restorelog and adjust date/time fields
45 if ($restore->course_startdateoffset
) {
46 restore_log_date_changes('Glossary', $restore, $info['MOD']['#'], array('ASSESSTIMESTART', 'ASSESSTIMEFINISH'));
48 //traverse_xmlize($info); //Debug
49 //print_object ($GLOBALS['traverse_array']); //Debug
50 //$GLOBALS['traverse_array']=""; //Debug
52 //Now, build the glossary record structure
53 $glossary->course
= $restore->course_id
;
54 $glossary->name
= backup_todb($info['MOD']['#']['NAME']['0']['#']);
55 $glossary->intro
= backup_todb($info['MOD']['#']['INTRO']['0']['#']);
56 $glossary->allowduplicatedentries
= backup_todb($info['MOD']['#']['ALLOWDUPLICATEDENTRIES']['0']['#']);
57 $glossary->displayformat
= backup_todb($info['MOD']['#']['DISPLAYFORMAT']['0']['#']);
58 $glossary->mainglossary
= backup_todb($info['MOD']['#']['MAINGLOSSARY']['0']['#']);
59 $glossary->showspecial
= backup_todb($info['MOD']['#']['SHOWSPECIAL']['0']['#']);
60 $glossary->showalphabet
= backup_todb($info['MOD']['#']['SHOWALPHABET']['0']['#']);
61 $glossary->showall
= backup_todb($info['MOD']['#']['SHOWALL']['0']['#']);
62 $glossary->allowcomments
= backup_todb($info['MOD']['#']['ALLOWCOMMENTS']['0']['#']);
63 $glossary->allowprintview
= backup_todb($info['MOD']['#']['ALLOWPRINTVIEW']['0']['#']);
64 $glossary->usedynalink
= backup_todb($info['MOD']['#']['USEDYNALINK']['0']['#']);
65 $glossary->defaultapproval
= backup_todb($info['MOD']['#']['DEFAULTAPPROVAL']['0']['#']);
66 $glossary->globalglossary
= backup_todb($info['MOD']['#']['GLOBALGLOSSARY']['0']['#']);
67 $glossary->entbypage
= backup_todb($info['MOD']['#']['ENTBYPAGE']['0']['#']);
68 $glossary->editalways
= backup_todb($info['MOD']['#']['EDITALWAYS']['0']['#']);
69 $glossary->rsstype
= backup_todb($info['MOD']['#']['RSSTYPE']['0']['#']);
70 $glossary->rssarticles
= backup_todb($info['MOD']['#']['RSSARTICLES']['0']['#']);
71 $glossary->timecreated
= backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
72 $glossary->timemodified
= backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
74 $glossary->assessed
= backup_todb($info['MOD']['#']['ASSESSED']['0']['#']);
75 $glossary->assesstimestart
= backup_todb($info['MOD']['#']['ASSESSTIMESTART']['0']['#']);
76 $glossary->assesstimefinish
= backup_todb($info['MOD']['#']['ASSESSTIMEFINISH']['0']['#']);
77 $glossary->scale
= backup_todb($info['MOD']['#']['SCALE']['0']['#']);
79 //We have to recode the scale field if it's <0 (positive is a grade, not a scale)
80 if ($glossary->scale
< 0) {
81 $scale = backup_getid($restore->backup_unique_code
,"scale",abs($glossary->scale
));
83 $glossary->scale
= -($scale->new_id
);
87 //To mantain upwards compatibility (pre 1.4) we have to check the displayformat field
88 //If it's numeric (0-6) we have to convert it to its new formatname.
89 //Define current 0-6 format names
90 $formatnames = array('dictionary','continuous','fullwithauthor','encyclopedia',
91 'faq','fullwithoutauthor','entrylist');
92 //If it's numeric, we are restoring a pre 1.4 course, do the conversion
93 if (is_numeric($glossary->displayformat
)) {
94 $displayformat = 'dictionary'; //Default format
95 if ($glossary->displayformat
>= 0 && $glossary->displayformat
<= 6) {
96 $displayformat = $formatnames[$glossary->displayformat
];
98 $glossary->displayformat
= $displayformat;
101 //Now check that the displayformat exists in the server, else default to dictionary
102 $formats = get_list_of_plugins('mod/glossary/formats');
103 if (!in_array($glossary->displayformat
,$formats)) {
104 $glossary->displayformat
= 'dictionary';
107 //If the backup file doesn't include the editalways field, activate it
108 //in secondary glossaries (old behaviour, pre 1.4)
109 if (! isset($info['MOD']['#']['EDITALWAYS']['0']['#'])) { //It's a pre-14 backup file
110 if ($glossary->mainglossary
== '0') {
111 $glossary->editalways
= '1';
115 //The structure is equal to the db, so insert the glossary
116 $newid = insert_record ("glossary",$glossary);
119 if (!defined('RESTORE_SILENTLY')) {
120 echo "<li>".get_string("modulename","glossary")." \"".format_string(stripslashes($glossary->name
),true)."\"</li>";
125 //We have the newid, update backup_ids
126 backup_putid($restore->backup_unique_code
,$mod->modtype
,
128 //Restore glossary_entries
129 $status = glossary_entries_restore_mods($mod->id
,$newid,$info,$restore);
130 //Restore glossary_categories and glossary_category_entries
131 $status = glossary_categories_restore_mods($mod->id
,$newid,$info,$restore);
142 //This function restores the glossary_entries
143 function glossary_entries_restore_mods($old_glossary_id,$new_glossary_id,$info,$restore) {
149 //Get the entries array
150 $entries = isset($info['MOD']['#']['ENTRIES']['0']['#']['ENTRY'])?
$info['MOD']['#']['ENTRIES']['0']['#']['ENTRY']:array();
152 //Iterate over entries
153 for($i = 0; $i < sizeof($entries); $i++
) {
154 $ent_info = $entries[$i];
155 //traverse_xmlize($ent_info); //Debug
156 //print_object ($GLOBALS['traverse_array']); //Debug
157 //$GLOBALS['traverse_array']=""; //Debug
159 //We'll need this later!!
160 $oldid = backup_todb($ent_info['#']['ID']['0']['#']);
161 $olduserid = backup_todb($ent_info['#']['USERID']['0']['#']);
163 //Now, build the GLOSSARY_ENTRIES record structure
164 $entry->glossaryid
= $new_glossary_id;
165 $entry->userid
= backup_todb($ent_info['#']['USERID']['0']['#']);
166 $entry->concept
= backup_todb(trim($ent_info['#']['CONCEPT']['0']['#']));
167 $entry->definition
= backup_todb($ent_info['#']['DEFINITION']['0']['#']);
168 $entry->format
= backup_todb($ent_info['#']['FORMAT']['0']['#']);
169 $entry->attachment
= backup_todb($ent_info['#']['ATTACHMENT']['0']['#']);
170 $entry->sourceglossaryid
= backup_todb($ent_info['#']['SOURCEGLOSSARYID']['0']['#']);
171 $entry->usedynalink
= backup_todb($ent_info['#']['USEDYNALINK']['0']['#']);
172 $entry->casesensitive
= backup_todb($ent_info['#']['CASESENSITIVE']['0']['#']);
173 $entry->fullmatch
= backup_todb($ent_info['#']['FULLMATCH']['0']['#']);
174 $entry->approved
= backup_todb($ent_info['#']['APPROVED']['0']['#']);
175 $entry->timecreated
= backup_todb($ent_info['#']['TIMECREATED']['0']['#']);
176 $entry->timemodified
= backup_todb($ent_info['#']['TIMEMODIFIED']['0']['#']);
177 $entry->teacherentry
= backup_todb($ent_info['#']['TEACHERENTRY']['0']['#']);
179 //We have to recode the userid field
180 $user = backup_getid($restore->backup_unique_code
,"user",$entry->userid
);
182 $entry->userid
= $user->new_id
;
184 //We have to recode the sourceglossaryid field
185 $source = backup_getid($restore->backup_unique_code
,"glossary",$entry->sourceglossaryid
);
187 $entry->sourceglossaryid
= $source->new_id
;
189 //If it's a teacher entry or userinfo was selected, restore the entry
190 if ($entry->teacherentry
or restore_userdata_selected($restore,'glossary',$old_glossary_id)) {
191 //The structure is equal to the db, so insert the glossary_entries
192 $newid = insert_record ("glossary_entries",$entry);
195 if (($i+
1) %
50 == 0) {
196 if (!defined('RESTORE_SILENTLY')) {
198 if (($i+
1) %
1000 == 0) {
205 //We have the newid, update backup_ids
206 backup_putid($restore->backup_unique_code
,"glossary_entries",$oldid,$newid);
207 //Restore glossary_alias
208 $status = glossary_alias_restore_mods($oldid,$newid,$ent_info,$restore);
209 //Now restore glossary_comments
210 $status = glossary_comments_restore_mods($oldid,$newid,$ent_info,$restore);
211 //Now restore glossary_ratings
212 $status = glossary_ratings_restore_mods($oldid,$newid,$ent_info,$restore);
213 //Now copy moddata associated files if needed
214 if ($entry->attachment
) {
215 $status = glossary_restore_files ($old_glossary_id, $new_glossary_id,
216 $oldid, $newid, $restore);
227 //This function restores the glossary_comments
228 function glossary_comments_restore_mods($old_entry_id,$new_entry_id,$info,$restore) {
234 //Get the comments array
235 $comments = isset($info['#']['COMMENTS']['0']['#']['COMMENT'])?
$info['#']['COMMENTS']['0']['#']['COMMENT']:array();
237 //Iterate over comments
238 for($i = 0; $i < sizeof($comments); $i++
) {
239 $com_info = $comments[$i];
240 //traverse_xmlize($com_info); //Debug
241 //print_object ($GLOBALS['traverse_array']); //Debug
242 //$GLOBALS['traverse_array']=""; //Debug
244 //We'll need this later!!
245 $oldid = backup_todb($com_info['#']['ID']['0']['#']);
247 //Now, build the GLOSSARY_COMMENTS record structure
248 $comment->entryid
= $new_entry_id;
249 $comment->userid
= backup_todb($com_info['#']['USERID']['0']['#']);
250 if (isset($com_info['#']['COMMENT']['0']['#'])) {
251 $comment->entrycomment
= backup_todb($com_info['#']['COMMENT']['0']['#']);
253 $comment->entrycomment
= backup_todb($com_info['#']['ENTRYCOMMENT']['0']['#']);
255 $comment->timemodified
= backup_todb($com_info['#']['TIMEMODIFIED']['0']['#']);
256 $comment->format
= backup_todb($com_info['#']['FORMAT']['0']['#']);
258 //We have to recode the userid field
259 $user = backup_getid($restore->backup_unique_code
,"user",$comment->userid
);
261 $comment->userid
= $user->new_id
;
264 //The structure is equal to the db, so insert the glossary_comments
265 $newid = insert_record ("glossary_comments",$comment);
268 if (($i+
1) %
50 == 0) {
269 if (!defined('RESTORE_SILENTLY')) {
271 if (($i+
1) %
1000 == 0) {
278 //We have the newid, update backup_ids
279 backup_putid($restore->backup_unique_code
,"glossary_comments",$oldid,$newid);
288 //This function restores the glossary_ratings
289 function glossary_ratings_restore_mods($old_entry_id,$new_entry_id,$info,$restore) {
295 //Get the ratings array
296 $ratings = isset($info['#']['RATINGS']['0']['#']['RATING'])?
$info['#']['RATINGS']['0']['#']['RATING']:array();
298 //Iterate over ratings
299 for($i = 0; $i < sizeof($ratings); $i++
) {
300 $rat_info = $ratings[$i];
301 //traverse_xmlize($rat_info); //Debug
302 //print_object ($GLOBALS['traverse_array']); //Debug
303 //$GLOBALS['traverse_array']=""; //Debug
305 //Now, build the GLOSSARY_RATINGS record structure
306 $rating->entryid
= $new_entry_id;
307 $rating->userid
= backup_todb($rat_info['#']['USERID']['0']['#']);
308 $rating->time
= backup_todb($rat_info['#']['TIME']['0']['#']);
309 $rating->rating
= backup_todb($rat_info['#']['RATING']['0']['#']);
311 //We have to recode the userid field
312 $user = backup_getid($restore->backup_unique_code
,"user",$rating->userid
);
314 $rating->userid
= $user->new_id
;
317 //The structure is equal to the db, so insert the glossary_ratings
318 $newid = insert_record ("glossary_ratings",$rating);
321 if (($i+
1) %
50 == 0) {
322 if (!defined('RESTORE_SILENTLY')) {
324 if (($i+
1) %
1000 == 0) {
339 //This function restores the glossary_alias table
340 function glossary_alias_restore_mods($old_entry_id,$new_entry_id,$info,$restore) {
346 //Get the comments array
347 $aliases = isset($info['#']['ALIASES']['0']['#']['ALIAS'])?
$info['#']['ALIASES']['0']['#']['ALIAS']:array();
349 //Iterate over comments
350 for($i = 0; $i < sizeof($aliases); $i++
) {
351 $alias_info = $aliases[$i];
353 //Now, build the GLOSSARY_ALIAS record structure
354 $alias->entryid
= $new_entry_id;
355 $alias->alias
= backup_todb(trim($alias_info['#']['ALIAS_TEXT']['0']['#']));
357 //The structure is equal to the db, so insert the glossary_comments
358 $newid = insert_record ("glossary_alias",$alias);
361 if (($i+
1) %
50 == 0) {
362 if (!defined('RESTORE_SILENTLY')) {
364 if (($i+
1) %
1000 == 0) {
379 //This function restores the glossary_categories
380 function glossary_categories_restore_mods($old_glossary_id,$new_glossary_id,$info,$restore) {
386 //Get the categories array
387 $categories = isset($info['MOD']['#']['CATEGORIES']['0']['#']['CATEGORY'])?
$info['MOD']['#']['CATEGORIES']['0']['#']['CATEGORY']:array();
389 //Iterate over categories
390 for($i = 0; $i < sizeof($categories); $i++
) {
391 $cat_info = $categories[$i];
392 //traverse_xmlize($cat_info); //Debug
393 //print_object ($GLOBALS['traverse_array']); //Debug
394 //$GLOBALS['traverse_array']=""; //Debug
396 //We'll need this later!!
397 $oldid = backup_todb($cat_info['#']['ID']['0']['#']);
399 //Now, build the GLOSSARY_CATEGORIES record structure
400 $category->glossaryid
= $new_glossary_id;
401 $category->name
= backup_todb($cat_info['#']['NAME']['0']['#']);
402 $category->usedynalink
= backup_todb($cat_info['#']['USEDYNALINK']['0']['#']);
404 $newid = insert_record ("glossary_categories",$category);
407 if (($i+
1) %
50 == 0) {
408 if (!defined('RESTORE_SILENTLY')) {
410 if (($i+
1) %
1000 == 0) {
418 //We have the newid, update backup_ids
419 backup_putid($restore->backup_unique_code
,"glossary_categories",$oldid,$newid);
420 //Now restore glossary_entries_categories
421 $status = glossary_entries_categories_restore_mods($oldid,$newid,$cat_info,$restore);
431 //This function restores the glossary_entries_categories
432 function glossary_entries_categories_restore_mods($old_category_id,$new_category_id,$info,$restore) {
438 //Get the entryids array
439 $entryids = isset($info['#']['ENTRIES']['0']['#']['ENTRY'])?
$info['#']['ENTRIES']['0']['#']['ENTRY']:array();
441 //Iterate over entryids
442 for($i = 0; $i < sizeof($entryids); $i++
) {
443 $ent_info = $entryids[$i];
444 //traverse_xmlize($ent_info); //Debug
445 //print_object ($GLOBALS['traverse_array']); //Debug
446 //$GLOBALS['traverse_array']=""; //Debug
448 //Now, build the GLOSSARY_ENTRIES_CATEGORIES record structure
449 $entry_category->categoryid
= $new_category_id;
450 $entry_category->entryid
= backup_todb($ent_info['#']['ENTRYID']['0']['#']);
452 //We have to recode the entryid field
453 $entry = backup_getid($restore->backup_unique_code
,"glossary_entries",$entry_category->entryid
);
455 $entry_category->entryid
= $entry->new_id
;
458 $newid = insert_record ("glossary_entries_categories",$entry_category);
461 if (($i+
1) %
50 == 0) {
462 if (!defined('RESTORE_SILENTLY')) {
464 if (($i+
1) %
1000 == 0) {
479 //This function copies the glossary related info from backup temp dir to course moddata folder,
480 //creating it if needed and recoding everything (glossary id and entry id)
481 function glossary_restore_files ($oldgloid, $newgloid, $oldentryid, $newentryid, $restore) {
491 //First, we check to "course_id" exists and create is as necessary
493 $dest_dir = $CFG->dataroot
."/".$restore->course_id
;
494 $status = check_dir_exists($dest_dir,true);
496 //Now, locate course's moddata directory
497 $moddata_path = $CFG->dataroot
."/".$restore->course_id
."/".$CFG->moddata
;
499 //Check it exists and create it
500 $status = check_dir_exists($moddata_path,true);
502 //Now, locate glossary directory
504 $glossary_path = $moddata_path."/glossary";
505 //Check it exists and create it
506 $status = check_dir_exists($glossary_path,true);
509 //Now locate the temp dir we are restoring from
511 $temp_path = $CFG->dataroot
."/temp/backup/".$restore->backup_unique_code
.
512 "/moddata/glossary/".$oldgloid."/".$oldentryid;
514 if (is_dir($temp_path)) {
519 //If todo, we create the neccesary dirs in course moddata/glossary
520 if ($status and $todo) {
521 //First this glossary id
522 $this_glossary_path = $glossary_path."/".$newgloid;
523 $status = check_dir_exists($this_glossary_path,true);
525 $entry_glossary_path = $this_glossary_path."/".$newentryid;
526 //And now, copy temp_path to entry_glossary_path
527 $status = backup_copy_file($temp_path, $entry_glossary_path);
533 //Return a content decoded to support interactivities linking. Every module
534 //should have its own. They are called automatically from
535 //glossary_decode_content_links_caller() function in each module
536 //in the restore process
537 function glossary_decode_content_links ($content,$restore) {
543 //Link to the list of glossarys
545 $searchstring='/\$@(GLOSSARYINDEX)\*([0-9]+)@\$/';
547 preg_match_all($searchstring,$content,$foundset);
548 //If found, then we are going to look for its new id (in backup tables)
550 //print_object($foundset); //Debug
551 //Iterate over foundset[2]. They are the old_ids
552 foreach($foundset[2] as $old_id) {
553 //We get the needed variables here (course id)
554 $rec = backup_getid($restore->backup_unique_code
,"course",$old_id);
555 //Personalize the searchstring
556 $searchstring='/\$@(GLOSSARYINDEX)\*('.$old_id.')@\$/';
557 //If it is a link to this course, update the link to its new location
560 $result= preg_replace($searchstring,$CFG->wwwroot
.'/mod/glossary/index.php?id='.$rec->new_id
,$result);
562 //It's a foreign link so leave it as original
563 $result= preg_replace($searchstring,$restore->original_wwwroot
.'/mod/glossary/index.php?id='.$old_id,$result);
568 //Link to glossary view by moduleid
570 $searchstring='/\$@(GLOSSARYVIEWBYID)\*([0-9]+)@\$/';
572 preg_match_all($searchstring,$result,$foundset);
573 //If found, then we are going to look for its new id (in backup tables)
575 //print_object($foundset); //Debug
576 //Iterate over foundset[2]. They are the old_ids
577 foreach($foundset[2] as $old_id) {
578 //We get the needed variables here (course_modules id)
579 $rec = backup_getid($restore->backup_unique_code
,"course_modules",$old_id);
580 //Personalize the searchstring
581 $searchstring='/\$@(GLOSSARYVIEWBYID)\*('.$old_id.')@\$/';
582 //If it is a link to this course, update the link to its new location
585 $result= preg_replace($searchstring,$CFG->wwwroot
.'/mod/glossary/view.php?id='.$rec->new_id
,$result);
587 //It's a foreign link so leave it as original
588 $result= preg_replace($searchstring,$restore->original_wwwroot
.'/mod/glossary/view.php?id='.$old_id,$result);
596 //This function makes all the necessary calls to xxxx_decode_content_links()
597 //function in each module, passing them the desired contents to be decoded
598 //from backup format to destination site/course in order to mantain inter-activities
599 //working in the backup/restore process. It's called from restore_decode_content_links()
600 //function in restore process
601 function glossary_decode_content_links_caller($restore) {
605 //Process every glossary ENTRY in the course
606 if ($entries = get_records_sql ("SELECT e.id, e.definition
607 FROM {$CFG->prefix}glossary_entries e,
608 {$CFG->prefix}glossary g
609 WHERE g.course = $restore->course_id AND
610 e.glossaryid = g.id")) {
611 //Iterate over each post->message
612 $i = 0; //Counter to send some output to the browser to avoid timeouts
613 foreach ($entries as $entry) {
616 $content = $entry->definition
;
617 $result = restore_decode_content_links_worker($content,$restore);
618 if ($result != $content) {
620 $entry->definition
= addslashes($result);
621 $status = update_record("glossary_entries",$entry);
623 if (!defined('RESTORE_SILENTLY')) {
624 echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
629 if (($i+
1) %
5 == 0) {
630 if (!defined('RESTORE_SILENTLY')) {
632 if (($i+
1) %
100 == 0) {
641 //Process every glossary (intro) in the course
642 if ($glossarys = get_records_sql ("SELECT g.id, g.intro
643 FROM {$CFG->prefix}glossary g
644 WHERE g.course = $restore->course_id")) {
645 //Iterate over each glossary->intro
646 $i = 0; //Counter to send some output to the browser to avoid timeouts
647 foreach ($glossarys as $glossary) {
650 $content = $glossary->intro
;
651 $result = restore_decode_content_links_worker($content,$restore);
652 if ($result != $content) {
654 $glossary->intro
= addslashes($result);
655 $status = update_record("glossary",$glossary);
657 if (!defined('RESTORE_SILENTLY')) {
658 echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
663 if (($i+
1) %
5 == 0) {
664 if (!defined('RESTORE_SILENTLY')) {
666 if (($i+
1) %
100 == 0) {
678 //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
679 //some texts in the module
680 function glossary_restore_wiki2markdown ($restore) {
686 //Convert glossary_comments->entrycomment
687 if ($records = get_records_sql ("SELECT c.id, c.entrycomment, c.format
688 FROM {$CFG->prefix}glossary_comments c,
689 {$CFG->prefix}glossary_entries e,
690 {$CFG->prefix}glossary g,
691 {$CFG->prefix}backup_ids b
692 WHERE e.id = c.entryid AND
693 g.id = e.glossaryid AND
694 g.course = $restore->course_id AND
695 c.format = ".FORMAT_WIKI
. " AND
696 b.backup_code = $restore->backup_unique_code AND
697 b.table_name = 'glossary_comments' AND
699 foreach ($records as $record) {
701 $record->entrycomment
= restore_decode_wiki_content($record->entrycomment
, $restore);
702 //Convert to Markdown
703 $wtm = new WikiToMarkdown();
704 $record->entrycomment
= $wtm->convert($record->entrycomment
, $restore->course_id
);
705 $record->format
= FORMAT_MARKDOWN
;
706 $status = update_record('glossary_comments', addslashes_object($record));
709 if (($i+
1) %
1 == 0) {
710 if (!defined('RESTORE_SILENTLY')) {
712 if (($i+
1) %
20 == 0) {
722 //Convert glossary_entries->definition
723 if ($records = get_records_sql ("SELECT e.id, e.definition, e.format
724 FROM {$CFG->prefix}glossary_entries e,
725 {$CFG->prefix}glossary g,
726 {$CFG->prefix}backup_ids b
727 WHERE g.id = e.glossaryid AND
728 g.course = $restore->course_id AND
729 e.format = ".FORMAT_WIKI
. " AND
730 b.backup_code = $restore->backup_unique_code AND
731 b.table_name = 'glossary_entries' AND
733 foreach ($records as $record) {
735 $record->definition
= restore_decode_wiki_content($record->definition
, $restore);
736 //Convert to Markdown
737 $wtm = new WikiToMarkdown();
738 $record->definition
= $wtm->convert($record->definition
, $restore->course_id
);
739 $record->format
= FORMAT_MARKDOWN
;
740 $status = update_record('glossary_entries', addslashes_object($record));
743 if (($i+
1) %
1 == 0) {
744 if (!defined('RESTORE_SILENTLY')) {
746 if (($i+
1) %
20 == 0) {
759 //This function returns a log record with all the necessay transformations
760 //done. It's used by restore_log_module() to restore modules log.
761 function glossary_restore_logs($restore,$log) {
765 //Depending of the action, we recode different things
766 switch ($log->action
) {
769 //Get the new_id of the module (to recode the info field)
770 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
772 $log->url
= "view.php?id=".$log->cmid
;
773 $log->info
= $mod->new_id
;
780 //Get the new_id of the module (to recode the info field)
781 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
783 $log->url
= "view.php?id=".$log->cmid
;
784 $log->info
= $mod->new_id
;
791 //Get the new_id of the module (to recode the info field)
792 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
794 $log->url
= "view.php?id=".$log->cmid
;
795 $log->info
= $mod->new_id
;
801 $log->url
= "index.php?id=".$log->course
;
806 //Get the new_id of the glossary_category (to recode the info field)
807 $cat = backup_getid($restore->backup_unique_code
,"glossary_categories",$log->info
);
809 $log->url
= "editcategories.php?id=".$log->cmid
;
810 $log->info
= $cat->new_id
;
815 case "edit category":
817 //Get the new_id of the glossary_category (to recode the info field)
818 $cat = backup_getid($restore->backup_unique_code
,"glossary_categories",$log->info
);
820 $log->url
= "editcategories.php?id=".$log->cmid
;
821 $log->info
= $cat->new_id
;
826 case "delete category":
828 //Get the new_id of the glossary_category (to recode the info field)
829 $cat = backup_getid($restore->backup_unique_code
,"glossary_categories",$log->info
);
831 $log->url
= "editcategories.php?id=".$log->cmid
;
832 $log->info
= $cat->new_id
;
839 //Get the new_id of the glossary_entry (to recode the info and url field)
840 $ent = backup_getid($restore->backup_unique_code
,"glossary_entries",$log->info
);
842 $log->url
= "view.php?id=".$log->cmid
."&mode=entry&hook=".$ent->new_id
;
843 $log->info
= $ent->new_id
;
850 //Get the new_id of the glossary_entry (to recode the info and url field)
851 $ent = backup_getid($restore->backup_unique_code
,"glossary_entries",$log->info
);
853 $log->url
= "view.php?id=".$log->cmid
."&mode=entry&hook=".$ent->new_id
;
854 $log->info
= $ent->new_id
;
861 //Get the new_id of the glossary_entry (to recode the info and url field)
862 $ent = backup_getid($restore->backup_unique_code
,"glossary_entries",$log->info
);
864 $log->url
= "view.php?id=".$log->cmid
."&mode=entry&hook=".$ent->new_id
;
865 $log->info
= $ent->new_id
;
870 case "approve entry":
872 //Get the new_id of the glossary_entry (to recode the info and url field)
873 $ent = backup_getid($restore->backup_unique_code
,"glossary_entries",$log->info
);
875 $log->url
= "showentry.php?id=".$log->cmid
."&eid=".$ent->new_id
;
876 $log->info
= $ent->new_id
;
883 //Get the new_id of the glossary_entry (to recode the info and url field)
884 $ent = backup_getid($restore->backup_unique_code
,"glossary_entries",$log->info
);
886 $log->url
= "showentry.php?&eid=".$ent->new_id
;
887 $log->info
= $ent->new_id
;
894 //Extract the entryid from the url field
895 $entid = substr(strrchr($log->url
,"="),1);
896 //Get the new_id of the glossary_entry (to recode the url field)
897 $ent = backup_getid($restore->backup_unique_code
,"glossary_entries",$entid);
898 //Get the new_id of the glossary_comment (to recode the info field)
899 $com = backup_getid($restore->backup_unique_code
,"glossary_comments",$log->info
);
901 $log->url
= "comments.php?id=".$log->cmid
."&eid=".$ent->new_id
;
902 $log->info
= $com->new_id
;
907 case "update comment":
909 //Extract the entryid from the url field
910 $entid = substr(strrchr($log->url
,"="),1);
911 //Get the new_id of the glossary_entry (to recode the url field)
912 $ent = backup_getid($restore->backup_unique_code
,"glossary_entries",$entid);
913 //Get the new_id of the glossary_comment (to recode the info field)
914 $com = backup_getid($restore->backup_unique_code
,"glossary_comments",$log->info
);
916 $log->url
= "comments.php?id=".$log->cmid
."&eid=".$ent->new_id
;
917 $log->info
= $com->new_id
;
922 case "delete comment":
924 //Extract the entryid from the url field
925 $entid = substr(strrchr($log->url
,"="),1);
926 //Get the new_id of the glossary_entry (to recode the url field)
927 $ent = backup_getid($restore->backup_unique_code
,"glossary_entries",$entid);
928 //Get the new_id of the glossary_comment (to recode the info field)
929 $com = backup_getid($restore->backup_unique_code
,"glossary_comments",$log->info
);
931 $log->url
= "comments.php?id=".$log->cmid
."&eid=".$ent->new_id
;
932 $log->info
= $com->new_id
;
938 if (!defined('RESTORE_SILENTLY')) {
939 echo "action (".$log->module
."-".$log->action
.") unknown. Not restored<br />"; //Debug