From 69731e2cc5bd43b73758ae66962245fc4a557bc6 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Mon, 4 Jul 2005 17:34:24 +0000 Subject: [PATCH] Improved automatic relinking in backup and restore. Credits go to skodak. Complete refactoring of the system that was really awful (my fault!). Now everything is in its place and working like a charm, making things really easier to be implemented and amplied. Bug 3678 (http://moodle.org/bugs/bug.php?op=show&bugid=3678) (http://moodle.org/mod/forum/discuss.php?d=26530) --- backup/restorelib.php | 21 ++- mod/assignment/backuplib.php | 14 ++ mod/assignment/restorelib.php | 103 +++++++++++++++ mod/chat/backuplib.php | 14 ++ mod/chat/restorelib.php | 104 +++++++++++++++ mod/choice/backuplib.php | 17 +++ mod/choice/restorelib.php | 104 +++++++++++++++ mod/forum/restorelib.php | 191 ++++++++------------------- mod/glossary/backuplib.php | 18 +++ mod/glossary/restorelib.php | 137 +++++++++++++++++++ mod/label/restorelib.php | 35 +++++ mod/lesson/backuplib.php | 17 +++ mod/lesson/restorelib.php | 109 ++++++++++++++- mod/quiz/backuplib.php | 18 +++ mod/quiz/restorelib.php | 104 +++++++++++++++ mod/resource/restorelib.php | 242 ++++------------------------------ mod/scorm/backuplib.php | 18 +++ mod/scorm/restorelib.php | 104 +++++++++++++++ mod/survey/backuplib.php | 14 ++ mod/survey/restorelib.php | 104 +++++++++++++++ mod/wiki/backuplib.php | 19 +++ mod/wiki/restorelib.php | 137 +++++++++++++++++++ 22 files changed, 1284 insertions(+), 360 deletions(-) diff --git a/backup/restorelib.php b/backup/restorelib.php index a5487a521a4..2717070ba10 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -63,9 +63,6 @@ //from backup format to destination site/course in order to mantain inter-activities //working in the backup/restore process function restore_decode_content_links($restore) { - - global $CFG; - $status = true; echo ""; + + // TODO: process all html text also in blocks too + return $status; } + + //This function is called from all xxxx_decode_content_links_caller(), + //its task is to ask all modules (maybe other linkable objects) to restore + //links to them. + function restore_decode_content_links_worker($content,$restore) { + foreach($restore->mods as $name => $info) { + $function_name = $name."_decode_content_links"; + if (function_exists($function_name)) { + $content = $function_name($content,$restore); + } + } + return $content; + } //This function converts all the wiki texts in the restored course //to the Markdown format. Used only for backup files prior 2005041100. diff --git a/mod/assignment/backuplib.php b/mod/assignment/backuplib.php index de3f872d711..7eaf8a0d1b1 100644 --- a/mod/assignment/backuplib.php +++ b/mod/assignment/backuplib.php @@ -156,10 +156,24 @@ return $info; } + //Return a content encoded to support interactivities linking. Every module + //should have its own. They are called automatically from the backup procedure. + function assignment_encode_content_links ($content,$preferences) { + global $CFG; + $base = preg_quote($CFG->wwwroot,"/"); + //Link to the list of assignments + $buscar="/(".$base."\/mod\/assignment\/index.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@ASSIGNMENTINDEX*$2@$',$content); + //Link to assignment view by moduleid + $buscar="/(".$base."\/mod\/assignment\/view.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@ASSIGNMENTVIEWBYID*$2@$',$result); + + return $result; + } // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE diff --git a/mod/assignment/restorelib.php b/mod/assignment/restorelib.php index 1d3fd8c8ca5..692e23f529d 100644 --- a/mod/assignment/restorelib.php +++ b/mod/assignment/restorelib.php @@ -232,6 +232,109 @@ return $status; } + //Return a content decoded to support interactivities linking. Every module + //should have its own. They are called automatically from + //assignment_decode_content_links_caller() function in each module + //in the restore process + function assignment_decode_content_links ($content,$restore) { + + global $CFG; + + $result = $content; + + //Link to the list of assignments + + $searchstring='/\$@(ASSIGNMENTINDEX)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$content,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course id) + $rec = backup_getid($restore->backup_unique_code,"course",$old_id); + //Personalize the searchstring + $searchstring='/\$@(ASSIGNMENTINDEX)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/assignment/index.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/assignment/index.php?id='.$old_id,$result); + } + } + } + + //Link to assignment view by moduleid + + $searchstring='/\$@(ASSIGNMENTVIEWBYID)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$result,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course_modules id) + $rec = backup_getid($restore->backup_unique_code,"course_modules",$old_id); + //Personalize the searchstring + $searchstring='/\$@(ASSIGNMENTVIEWBYID)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/assignment/view.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/assignment/view.php?id='.$old_id,$result); + } + } + } + + return $result; + } + + //This function makes all the necessary calls to xxxx_decode_content_links() + //function in each module, passing them the desired contents to be decoded + //from backup format to destination site/course in order to mantain inter-activities + //working in the backup/restore process. It's called from restore_decode_content_links() + //function in restore process + function assignment_decode_content_links_caller($restore) { + global $CFG; + $status = true; + + if ($assignments = get_records_sql ("SELECT a.id, a.description + FROM {$CFG->prefix}assignment a + WHERE a.course = $restore->course_id")) { + //Iterate over each assignment->description + $i = 0; //Counter to send some output to the browser to avoid timeouts + foreach ($assignments as $assignment) { + //Increment counter + $i++; + $content = $assignment->description; + $result = restore_decode_content_links_worker($content,$restore); + if ($result != $content) { + //Update record + $assignment->description = addslashes($result); + $status = update_record("assignment",$assignment); + if ($CFG->debug>7) { + echo "

".$content."
changed to
".$result."

"; + } + } + //Do some output + if (($i+1) % 5 == 0) { + echo "."; + if (($i+1) % 100 == 0) { + echo "
"; + } + backup_flush(300); + } + } + } + return $status; + } + //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for //some texts in the module function assignment_restore_wiki2markdown ($restore) { diff --git a/mod/chat/backuplib.php b/mod/chat/backuplib.php index b6e34f88558..e36873df832 100644 --- a/mod/chat/backuplib.php +++ b/mod/chat/backuplib.php @@ -109,10 +109,24 @@ return $info; } + //Return a content encoded to support interactivities linking. Every module + //should have its own. They are called automatically from the backup procedure. + function chat_encode_content_links ($content,$preferences) { + global $CFG; + $base = preg_quote($CFG->wwwroot,"/"); + //Link to the list of chats + $buscar="/(".$base."\/mod\/chat\/index.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@CHATINDEX*$2@$',$content); + //Link to chat view by moduleid + $buscar="/(".$base."\/mod\/chat\/view.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@CHATVIEWBYID*$2@$',$result); + + return $result; + } // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE diff --git a/mod/chat/restorelib.php b/mod/chat/restorelib.php index 52192bc56f6..1ebb00a3c04 100644 --- a/mod/chat/restorelib.php +++ b/mod/chat/restorelib.php @@ -130,6 +130,110 @@ return $status; } + //Return a content decoded to support interactivities linking. Every module + //should have its own. They are called automatically from + //chat_decode_content_links_caller() function in each module + //in the restore process + function chat_decode_content_links ($content,$restore) { + + global $CFG; + + $result = $content; + + //Link to the list of chats + + $searchstring='/\$@(CHATINDEX)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$content,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course id) + $rec = backup_getid($restore->backup_unique_code,"course",$old_id); + //Personalize the searchstring + $searchstring='/\$@(CHATINDEX)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/chat/index.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/chat/index.php?id='.$old_id,$result); + } + } + } + + //Link to chat view by moduleid + + $searchstring='/\$@(CHATVIEWBYID)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$result,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course_modules id) + $rec = backup_getid($restore->backup_unique_code,"course_modules",$old_id); + //Personalize the searchstring + $searchstring='/\$@(CHATVIEWBYID)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/chat/view.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/chat/view.php?id='.$old_id,$result); + } + } + } + + return $result; + } + + //This function makes all the necessary calls to xxxx_decode_content_links() + //function in each module, passing them the desired contents to be decoded + //from backup format to destination site/course in order to mantain inter-activities + //working in the backup/restore process. It's called from restore_decode_content_links() + //function in restore process + function chat_decode_content_links_caller($restore) { + global $CFG; + $status = true; + + if ($chats = get_records_sql ("SELECT c.id, c.intro + FROM {$CFG->prefix}chat c + WHERE c.course = $restore->course_id")) { + //Iterate over each chat->intro + $i = 0; //Counter to send some output to the browser to avoid timeouts + foreach ($chats as $chat) { + //Increment counter + $i++; + $content = $chat->intro; + $result = restore_decode_content_links_worker($content,$restore); + if ($result != $content) { + //Update record + $chat->intro = addslashes($result); + $status = update_record("chat",$chat); + if ($CFG->debug>7) { + echo "

".$content."
changed to
".$result."

"; + } + } + //Do some output + if (($i+1) % 5 == 0) { + echo "."; + if (($i+1) % 100 == 0) { + echo "
"; + } + backup_flush(300); + } + } + } + + return $status; + } + //This function returns a log record with all the necessay transformations //done. It's used by restore_log_module() to restore modules log. function chat_restore_logs($restore,$log) { diff --git a/mod/choice/backuplib.php b/mod/choice/backuplib.php index 1289e8586af..331938691f7 100644 --- a/mod/choice/backuplib.php +++ b/mod/choice/backuplib.php @@ -151,7 +151,24 @@ return $info; } + //Return a content encoded to support interactivities linking. Every module + //should have its own. They are called automatically from the backup procedure. + function choice_encode_content_links ($content,$preferences) { + global $CFG; + + $base = preg_quote($CFG->wwwroot,"/"); + + //Link to the list of choices + $buscar="/(".$base."\/mod\/choice\/index.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@CHOICEINDEX*$2@$',$content); + + //Link to choice view by moduleid + $buscar="/(".$base."\/mod\/choice\/view.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@CHOICEVIEWBYID*$2@$',$result); + + return $result; + } // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE diff --git a/mod/choice/restorelib.php b/mod/choice/restorelib.php index a13510945dd..b83c9597ef4 100644 --- a/mod/choice/restorelib.php +++ b/mod/choice/restorelib.php @@ -251,6 +251,110 @@ function choice_options_restore_mods($choiceid,$info,$restore) { return $status; } + //Return a content decoded to support interactivities linking. Every module + //should have its own. They are called automatically from + //choice_decode_content_links_caller() function in each module + //in the restore process + function choice_decode_content_links ($content,$restore) { + + global $CFG; + + $result = $content; + + //Link to the list of choices + + $searchstring='/\$@(CHOICEINDEX)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$content,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course id) + $rec = backup_getid($restore->backup_unique_code,"course",$old_id); + //Personalize the searchstring + $searchstring='/\$@(CHOICEINDEX)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/choice/index.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/choice/index.php?id='.$old_id,$result); + } + } + } + + //Link to choice view by moduleid + + $searchstring='/\$@(CHOICEVIEWBYID)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$result,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course_modules id) + $rec = backup_getid($restore->backup_unique_code,"course_modules",$old_id); + //Personalize the searchstring + $searchstring='/\$@(CHOICEVIEWBYID)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/choice/view.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/choice/view.php?id='.$old_id,$result); + } + } + } + + return $result; + } + + //This function makes all the necessary calls to xxxx_decode_content_links() + //function in each module, passing them the desired contents to be decoded + //from backup format to destination site/course in order to mantain inter-activities + //working in the backup/restore process. It's called from restore_decode_content_links() + //function in restore process + function choice_decode_content_links_caller($restore) { + global $CFG; + $status = true; + + if ($choices = get_records_sql ("SELECT c.id, c.text + FROM {$CFG->prefix}choice c + WHERE c.course = $restore->course_id")) { + //Iterate over each choice->text + $i = 0; //Counter to send some output to the browser to avoid timeouts + foreach ($choices as $choice) { + //Increment counter + $i++; + $content = $choice->text; + $result = restore_decode_content_links_worker($content,$restore); + if ($result != $content) { + //Update record + $choice->text = addslashes($result); + $status = update_record("choice",$choice); + if ($CFG->debug>7) { + echo "

".$content."
changed to
".$result."

"; + } + } + //Do some output + if (($i+1) % 5 == 0) { + echo "."; + if (($i+1) % 100 == 0) { + echo "
"; + } + backup_flush(300); + } + } + } + + return $status; + } + //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for //some texts in the module function choice_restore_wiki2markdown ($restore) { diff --git a/mod/forum/restorelib.php b/mod/forum/restorelib.php index 82b25cfa20c..e0b8be301d4 100644 --- a/mod/forum/restorelib.php +++ b/mod/forum/restorelib.php @@ -963,158 +963,71 @@ //working in the backup/restore process. It's called from restore_decode_content_links() //function in restore process function forum_decode_content_links_caller($restore) { - global $CFG; - $status = true; - - echo ""; return $status; } ?> diff --git a/mod/glossary/backuplib.php b/mod/glossary/backuplib.php index c170c4feca3..8c9b8b06e80 100644 --- a/mod/glossary/backuplib.php +++ b/mod/glossary/backuplib.php @@ -335,6 +335,24 @@ return $info; } + //Return a content encoded to support interactivities linking. Every module + //should have its own. They are called automatically from the backup procedure. + function glossary_encode_content_links ($content,$preferences) { + + global $CFG; + + $base = preg_quote($CFG->wwwroot,"/"); + + //Link to the list of glossarys + $buscar="/(".$base."\/mod\/glossary\/index.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@GLOSSARYINDEX*$2@$',$content); + + //Link to glossary view by moduleid + $buscar="/(".$base."\/mod\/glossary\/view.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@GLOSSARYVIEWBYID*$2@$',$result); + + return $result; + } // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE diff --git a/mod/glossary/restorelib.php b/mod/glossary/restorelib.php index ca2fe080f47..24fbad4f90f 100644 --- a/mod/glossary/restorelib.php +++ b/mod/glossary/restorelib.php @@ -509,6 +509,143 @@ return $status; } + //Return a content decoded to support interactivities linking. Every module + //should have its own. They are called automatically from + //glossary_decode_content_links_caller() function in each module + //in the restore process + function glossary_decode_content_links ($content,$restore) { + + global $CFG; + + $result = $content; + + //Link to the list of glossarys + + $searchstring='/\$@(GLOSSARYINDEX)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$content,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course id) + $rec = backup_getid($restore->backup_unique_code,"course",$old_id); + //Personalize the searchstring + $searchstring='/\$@(GLOSSARYINDEX)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/glossary/index.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/glossary/index.php?id='.$old_id,$result); + } + } + } + + //Link to glossary view by moduleid + + $searchstring='/\$@(GLOSSARYVIEWBYID)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$result,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course_modules id) + $rec = backup_getid($restore->backup_unique_code,"course_modules",$old_id); + //Personalize the searchstring + $searchstring='/\$@(GLOSSARYVIEWBYID)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/glossary/view.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/glossary/view.php?id='.$old_id,$result); + } + } + } + + return $result; + } + + //This function makes all the necessary calls to xxxx_decode_content_links() + //function in each module, passing them the desired contents to be decoded + //from backup format to destination site/course in order to mantain inter-activities + //working in the backup/restore process. It's called from restore_decode_content_links() + //function in restore process + function glossary_decode_content_links_caller($restore) { + global $CFG; + $status = true; + + //Process every glossary ENTRY in the course + if ($entries = get_records_sql ("SELECT e.id, e.definition + FROM {$CFG->prefix}glossary_entries e, + {$CFG->prefix}glossary g + WHERE g.course = $restore->course_id AND + e.glossaryid = g.id")) { + //Iterate over each post->message + $i = 0; //Counter to send some output to the browser to avoid timeouts + foreach ($entries as $entry) { + //Increment counter + $i++; + $content = $entry->definition; + $result = restore_decode_content_links_worker($content,$restore); + if ($result != $content) { + //Update record + $entry->definition = addslashes($result); + $status = update_record("glossary_entries",$entry); + if ($CFG->debug>7) { + echo "

".$content."
changed to
".$result."

"; + } + } + //Do some output + if (($i+1) % 5 == 0) { + echo "."; + if (($i+1) % 100 == 0) { + echo "
"; + } + backup_flush(300); + } + } + } + + //Process every glossary (intro) in the course + if ($glossarys = get_records_sql ("SELECT g.id, g.intro + FROM {$CFG->prefix}glossary g + WHERE g.course = $restore->course_id")) { + //Iterate over each glossary->intro + $i = 0; //Counter to send some output to the browser to avoid timeouts + foreach ($glossarys as $glossary) { + //Increment counter + $i++; + $content = $glossary->intro; + $result = restore_decode_content_links_worker($content,$restore); + if ($result != $content) { + //Update record + $glossary->intro = addslashes($result); + $status = update_record("glossary",$glossary); + if ($CFG->debug>7) { + echo "

".$content."
changed to
".$result."

"; + } + } + //Do some output + if (($i+1) % 5 == 0) { + echo "."; + if (($i+1) % 100 == 0) { + echo "
"; + } + backup_flush(300); + } + } + } + + return $status; + } + //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for //some texts in the module function glossary_restore_wiki2markdown ($restore) { diff --git a/mod/label/restorelib.php b/mod/label/restorelib.php index a6888d7f919..38d06609690 100644 --- a/mod/label/restorelib.php +++ b/mod/label/restorelib.php @@ -61,6 +61,41 @@ return $status; } + function label_decode_content_links_caller($restore) { + global $CFG; + $status = true; + + if ($labels = get_records_sql ("SELECT l.id, l.content + FROM {$CFG->prefix}label l + WHERE l.course = $restore->course_id")) { + $i = 0; //Counter to send some output to the browser to avoid timeouts + foreach ($labels as $label) { + //Increment counter + $i++; + $content = $label->content; + $result = restore_decode_content_links_worker($content,$restore); + + if ($result != $content) { + //Update record + $label->content = addslashes($result); + $status = update_record("label", $label); + if ($CFG->debug>7) { + echo "

".$content."
changed to
".$result."

"; + } + } + //Do some output + if (($i+1) % 5 == 0) { + echo "."; + if (($i+1) % 100 == 0) { + echo "
"; + } + backup_flush(300); + } + } + } + return $status; + } + //This function returns a log record with all the necessay transformations //done. It's used by restore_log_module() to restore modules log. function label_restore_logs($restore,$log) { diff --git a/mod/lesson/backuplib.php b/mod/lesson/backuplib.php index 317ad30f82c..457d9e144a2 100644 --- a/mod/lesson/backuplib.php +++ b/mod/lesson/backuplib.php @@ -419,7 +419,24 @@ return $info; } + //Return a content encoded to support interactivities linking. Every module + //should have its own. They are called automatically from the backup procedure. + function lesson_encode_content_links ($content,$preferences) { + global $CFG; + + $base = preg_quote($CFG->wwwroot,"/"); + + //Link to the list of lessons + $buscar="/(".$base."\/mod\/lesson\/index.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@LESSONINDEX*$2@$',$content); + + //Link to lesson view by moduleid + $buscar="/(".$base."\/mod\/lesson\/view.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@LESSONVIEWBYID*$2@$',$result); + + return $result; + } // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE diff --git a/mod/lesson/restorelib.php b/mod/lesson/restorelib.php index e407ecd4700..d832f497b30 100644 --- a/mod/lesson/restorelib.php +++ b/mod/lesson/restorelib.php @@ -635,7 +635,114 @@ return $status; } - + + //Return a content decoded to support interactivities linking. Every module + //should have its own. They are called automatically from + //lesson_decode_content_links_caller() function in each module + //in the restore process + function lesson_decode_content_links ($content,$restore) { + + global $CFG; + + $result = $content; + + //Link to the list of lessons + + $searchstring='/\$@(LESSONINDEX)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$content,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course id) + $rec = backup_getid($restore->backup_unique_code,"course",$old_id); + //Personalize the searchstring + $searchstring='/\$@(LESSONINDEX)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/lesson/index.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/lesson/index.php?id='.$old_id,$result); + } + } + } + + //Link to lesson view by moduleid + + $searchstring='/\$@(LESSONVIEWBYID)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$result,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course_modules id) + $rec = backup_getid($restore->backup_unique_code,"course_modules",$old_id); + //Personalize the searchstring + $searchstring='/\$@(LESSONVIEWBYID)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/lesson/view.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/lesson/view.php?id='.$old_id,$result); + } + } + } + + return $result; + } + + //This function makes all the necessary calls to xxxx_decode_content_links() + //function in each module, passing them the desired contents to be decoded + //from backup format to destination site/course in order to mantain inter-activities + //working in the backup/restore process. It's called from restore_decode_content_links() + //function in restore process + function lesson_decode_content_links_caller($restore) { + global $CFG; + $status = true; + + //Process every lesson PAGE in the course + if ($pages = get_records_sql ("SELECT p.id, p.contents + FROM {$CFG->prefix}lesson_pages p, + {$CFG->prefix}lesson l + WHERE l.course = $restore->course_id AND + p.lessonid = l.id")) { + //Iterate over each page->message + $i = 0; //Counter to send some output to the browser to avoid timeouts + foreach ($pages as $page) { + //Increment counter + $i++; + $content = $page->contents; + $result = restore_decode_content_links_worker($content,$restore); + if ($result != $content) { + //Update record + $page->contents = addslashes($result); + $status = update_record("lesson_pages",$page); + if ($CFG->debug>7) { + echo "

".$content."
changed to
".$result."

"; + } + } + //Do some output + if (($i+1) % 5 == 0) { + echo "."; + if (($i+1) % 100 == 0) { + echo "
"; + } + backup_flush(300); + } + } + } + + return $status; + } + //This function returns a log record with all the necessay transformations //done. It's used by restore_log_module() to restore modules log. function lesson_restore_logs($restore,$log) { diff --git a/mod/quiz/backuplib.php b/mod/quiz/backuplib.php index 28b92831230..ba7a2b0f4d8 100644 --- a/mod/quiz/backuplib.php +++ b/mod/quiz/backuplib.php @@ -997,6 +997,24 @@ return $info; } + //Return a content encoded to support interactivities linking. Every module + //should have its own. They are called automatically from the backup procedure. + function quiz_encode_content_links ($content,$preferences) { + + global $CFG; + + $base = preg_quote($CFG->wwwroot,"/"); + + //Link to the list of quizs + $buscar="/(".$base."\/mod\/quiz\/index.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@QUIZINDEX*$2@$',$content); + + //Link to quiz view by moduleid + $buscar="/(".$base."\/mod\/quiz\/view.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@QUIZVIEWBYID*$2@$',$result); + + return $result; + } // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE diff --git a/mod/quiz/restorelib.php b/mod/quiz/restorelib.php index 890dbfacecd..49131c1570a 100644 --- a/mod/quiz/restorelib.php +++ b/mod/quiz/restorelib.php @@ -1861,6 +1861,110 @@ return $status; } + //Return a content decoded to support interactivities linking. Every module + //should have its own. They are called automatically from + //quiz_decode_content_links_caller() function in each module + //in the restore process + function quiz_decode_content_links ($content,$restore) { + + global $CFG; + + $result = $content; + + //Link to the list of quizs + + $searchstring='/\$@(QUIZINDEX)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$content,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course id) + $rec = backup_getid($restore->backup_unique_code,"course",$old_id); + //Personalize the searchstring + $searchstring='/\$@(QUIZINDEX)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/quiz/index.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/quiz/index.php?id='.$old_id,$result); + } + } + } + + //Link to quiz view by moduleid + + $searchstring='/\$@(QUIZVIEWBYID)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$result,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course_modules id) + $rec = backup_getid($restore->backup_unique_code,"course_modules",$old_id); + //Personalize the searchstring + $searchstring='/\$@(QUIZVIEWBYID)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/quiz/view.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/quiz/view.php?id='.$old_id,$result); + } + } + } + + return $result; + } + + //This function makes all the necessary calls to xxxx_decode_content_links() + //function in each module, passing them the desired contents to be decoded + //from backup format to destination site/course in order to mantain inter-activities + //working in the backup/restore process. It's called from restore_decode_content_links() + //function in restore process + function quiz_decode_content_links_caller($restore) { + global $CFG; + $status = true; + + if ($quizs = get_records_sql ("SELECT q.id, q.intro + FROM {$CFG->prefix}quiz q + WHERE q.course = $restore->course_id")) { + //Iterate over each quiz->intro + $i = 0; //Counter to send some output to the browser to avoid timeouts + foreach ($quizs as $quiz) { + //Increment counter + $i++; + $content = $quiz->intro; + $result = restore_decode_content_links_worker($content,$restore); + if ($result != $content) { + //Update record + $quiz->intro = addslashes($result); + $status = update_record("quiz",$quiz); + if ($CFG->debug>7) { + echo "

".$content."
changed to
".$result."

"; + } + } + //Do some output + if (($i+1) % 5 == 0) { + echo "."; + if (($i+1) % 100 == 0) { + echo "
"; + } + backup_flush(300); + } + } + } + + return $status; + } + //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for //some texts in the module function quiz_restore_wiki2markdown ($restore) { diff --git a/mod/resource/restorelib.php b/mod/resource/restorelib.php index 6ccdc6b25c6..1275d56b3ff 100644 --- a/mod/resource/restorelib.php +++ b/mod/resource/restorelib.php @@ -169,232 +169,42 @@ //working in the backup/restore process. It's called from restore_decode_content_links() //function in restore process function resource_decode_content_links_caller($restore) { - global $CFG; - $status = true; - echo ""; return $status; } diff --git a/mod/scorm/backuplib.php b/mod/scorm/backuplib.php index 2b2da29a665..4d857572c61 100755 --- a/mod/scorm/backuplib.php +++ b/mod/scorm/backuplib.php @@ -190,6 +190,24 @@ } + //Return a content encoded to support interactivities linking. Every module + //should have its own. They are called automatically from the backup procedure. + function scorm_encode_content_links ($content,$preferences) { + + global $CFG; + + $base = preg_quote($CFG->wwwroot,"/"); + + //Link to the list of scorms + $buscar="/(".$base."\/mod\/scorm\/index.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@SCORMINDEX*$2@$',$content); + + //Link to scorm view by moduleid + $buscar="/(".$base."\/mod\/scorm\/view.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@SCORMVIEWBYID*$2@$',$result); + + return $result; + } // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE diff --git a/mod/scorm/restorelib.php b/mod/scorm/restorelib.php index 513675151b5..bb9ee53e193 100755 --- a/mod/scorm/restorelib.php +++ b/mod/scorm/restorelib.php @@ -353,6 +353,110 @@ return $status; } + //Return a content decoded to support interactivities linking. Every module + //should have its own. They are called automatically from + //scorm_decode_content_links_caller() function in each module + //in the restore process + function scorm_decode_content_links ($content,$restore) { + + global $CFG; + + $result = $content; + + //Link to the list of scorms + + $searchstring='/\$@(SCORMINDEX)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$content,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course id) + $rec = backup_getid($restore->backup_unique_code,"course",$old_id); + //Personalize the searchstring + $searchstring='/\$@(SCORMINDEX)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/scorm/index.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/scorm/index.php?id='.$old_id,$result); + } + } + } + + //Link to scorm view by moduleid + + $searchstring='/\$@(SCORMVIEWBYID)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$result,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course_modules id) + $rec = backup_getid($restore->backup_unique_code,"course_modules",$old_id); + //Personalize the searchstring + $searchstring='/\$@(SCORMVIEWBYID)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/scorm/view.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/scorm/view.php?id='.$old_id,$result); + } + } + } + + return $result; + } + + //This function makes all the necessary calls to xxxx_decode_content_links() + //function in each module, passing them the desired contents to be decoded + //from backup format to destination site/course in order to mantain inter-activities + //working in the backup/restore process. It's called from restore_decode_content_links() + //function in restore process + function scorm_decode_content_links_caller($restore) { + global $CFG; + $status = true; + + if ($scorms = get_records_sql ("SELECT s.id, s.summary + FROM {$CFG->prefix}scorm s + WHERE s.course = $restore->course_id")) { + + $i = 0; //Counter to send some output to the browser to avoid timeouts + foreach ($scorms as $scorm) { + //Increment counter + $i++; + $content = $scorm->summary; + $result = restore_decode_content_links_worker($content,$restore); + + if ($result != $content) { + //Update record + $scorm->summary = addslashes($result); + $status = update_record("scorm",$scorm); + if ($CFG->debug>7) { + echo "

".$content."
changed to
".$result."

"; + } + } + //Do some output + if (($i+1) % 5 == 0) { + echo "."; + if (($i+1) % 100 == 0) { + echo "
"; + } + backup_flush(300); + } + } + } + return $status; + } + //This function returns a log record with all the necessay transformations //done. It's used by restore_log_module() to restore modules log. function scorm_restore_logs($restore,$log) { diff --git a/mod/survey/backuplib.php b/mod/survey/backuplib.php index 78423af1342..7d6bf369716 100644 --- a/mod/survey/backuplib.php +++ b/mod/survey/backuplib.php @@ -142,10 +142,24 @@ return $info; } + //Return a content encoded to support interactivities linking. Every module + //should have its own. They are called automatically from the backup procedure. + function servey_encode_content_links ($content,$preferences) { + global $CFG; + $base = preg_quote($CFG->wwwroot,"/"); + //Link to the list of serveys + $buscar="/(".$base."\/mod\/servey\/index.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@SURVEYINDEX*$2@$',$content); + //Link to servey view by moduleid + $buscar="/(".$base."\/mod\/servey\/view.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@SURVEYVIEWBYID*$2@$',$result); + + return $result; + } // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE diff --git a/mod/survey/restorelib.php b/mod/survey/restorelib.php index 086b0c27265..85f945f46cc 100644 --- a/mod/survey/restorelib.php +++ b/mod/survey/restorelib.php @@ -194,6 +194,110 @@ return $status; } + //Return a content decoded to support interactivities linking. Every module + //should have its own. They are called automatically from + //servey_decode_content_links_caller() function in each module + //in the restore process + function servey_decode_content_links ($content,$restore) { + + global $CFG; + + $result = $content; + + //Link to the list of serveys + + $searchstring='/\$@(SURVEYINDEX)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$content,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course id) + $rec = backup_getid($restore->backup_unique_code,"course",$old_id); + //Personalize the searchstring + $searchstring='/\$@(SURVEYINDEX)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/servey/index.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/servey/index.php?id='.$old_id,$result); + } + } + } + + //Link to servey view by moduleid + + $searchstring='/\$@(SURVEYVIEWBYID)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$result,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course_modules id) + $rec = backup_getid($restore->backup_unique_code,"course_modules",$old_id); + //Personalize the searchstring + $searchstring='/\$@(SURVEYVIEWBYID)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/servey/view.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/servey/view.php?id='.$old_id,$result); + } + } + } + + return $result; + } + + //This function makes all the necessary calls to xxxx_decode_content_links() + //function in each module, passing them the desired contents to be decoded + //from backup format to destination site/course in order to mantain inter-activities + //working in the backup/restore process. It's called from restore_decode_content_links() + //function in restore process + function survey_decode_content_links_caller($restore) { + global $CFG; + $status = true; + + if ($surveys = get_records_sql ("SELECT s.id, s.intro + FROM {$CFG->prefix}survey s + WHERE s.course = $restore->course_id")) { + //Iterate over each survey->intro + $i = 0; //Counter to send some output to the browser to avoid timeouts + foreach ($surveys as $survey) { + //Increment counter + $i++; + $content = $survey->intro; + $result = restore_decode_content_links_worker($content,$restore); + if ($result != $content) { + //Update record + $survey->intro = addslashes($result); + $status = update_record("survey",$survey); + if ($CFG->debug>7) { + echo "

".$content."
changed to
".$result."

"; + } + } + //Do some output + if (($i+1) % 5 == 0) { + echo "."; + if (($i+1) % 100 == 0) { + echo "
"; + } + backup_flush(300); + } + } + } + + return $status; + } + //This function returns a log record with all the necessay transformations //done. It's used by restore_log_module() to restore modules log. function survey_restore_logs($restore,$log) { diff --git a/mod/wiki/backuplib.php b/mod/wiki/backuplib.php index f90a25659db..093d3e0c882 100644 --- a/mod/wiki/backuplib.php +++ b/mod/wiki/backuplib.php @@ -170,4 +170,23 @@ } + //Return a content encoded to support interactivities linking. Every module + //should have its own. They are called automatically from the backup procedure. + function wiki_encode_content_links ($content,$preferences) { + + global $CFG; + + $base = preg_quote($CFG->wwwroot,"/"); + + //Link to the list of wikis + $buscar="/(".$base."\/mod\/wiki\/index.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@WIKIINDEX*$2@$',$content); + + //Link to wiki view by moduleid + $buscar="/(".$base."\/mod\/wiki\/view.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@WIKIVIEWBYID*$2@$',$result); + + return $result; + } + ?> diff --git a/mod/wiki/restorelib.php b/mod/wiki/restorelib.php index 9c8d2616b19..6daf00ce496 100644 --- a/mod/wiki/restorelib.php +++ b/mod/wiki/restorelib.php @@ -259,4 +259,141 @@ return $status; } + + //Return a content decoded to support interactivities linking. Every module + //should have its own. They are called automatically from + //wiki_decode_content_links_caller() function in each module + //in the restore process + function wiki_decode_content_links ($content,$restore) { + + global $CFG; + + $result = $content; + + //Link to the list of wikis + + $searchstring='/\$@(WIKIINDEX)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$content,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course id) + $rec = backup_getid($restore->backup_unique_code,"course",$old_id); + //Personalize the searchstring + $searchstring='/\$@(WIKIINDEX)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/wiki/index.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/wiki/index.php?id='.$old_id,$result); + } + } + } + + //Link to wiki view by moduleid + + $searchstring='/\$@(WIKIVIEWBYID)\*([0-9]+)@\$/'; + //We look for it + preg_match_all($searchstring,$result,$foundset); + //If found, then we are going to look for its new id (in backup tables) + if ($foundset[0]) { + //print_object($foundset); //Debug + //Iterate over foundset[2]. They are the old_ids + foreach($foundset[2] as $old_id) { + //We get the needed variables here (course_modules id) + $rec = backup_getid($restore->backup_unique_code,"course_modules",$old_id); + //Personalize the searchstring + $searchstring='/\$@(WIKIVIEWBYID)\*('.$old_id.')@\$/'; + //If it is a link to this course, update the link to its new location + if($rec->new_id) { + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/wiki/view.php?id='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/wiki/view.php?id='.$old_id,$result); + } + } + } + + return $result; + } + + //This function makes all the necessary calls to xxxx_decode_content_links() + //function in each module, passing them the desired contents to be decoded + //from backup format to destination site/course in order to mantain inter-activities + //working in the backup/restore process. It's called from restore_decode_content_links() + //function in restore process + function wiki_decode_content_links_caller($restore) { + global $CFG; + $status = true; + + //Process every wiki PAGE in the course + if ($pages = get_records_sql ("SELECT p.id, p.content + FROM {$CFG->prefix}wiki_pages p, + {$CFG->prefix}wiki w + WHERE w.course = $restore->course_id AND + p.wiki = w.id")) { + //Iterate over each post->message + $i = 0; //Counter to send some output to the browser to avoid timeouts + foreach ($pages as $page) { + //Increment counter + $i++; + $content = $page->definition; + $result = restore_decode_content_links_worker($content,$restore); + if ($result != $content) { + //Update record + $page->content = addslashes($result); + $status = update_record("wiki_pages",$page); + if ($CFG->debug>7) { + echo "

".$content."
changed to
".$result."

"; + } + } + //Do some output + if (($i+1) % 5 == 0) { + echo "."; + if (($i+1) % 100 == 0) { + echo "
"; + } + backup_flush(300); + } + } + } + + //Process every wiki (summary) in the course + if ($wikis = get_records_sql ("SELECT w.id, w.summary + FROM {$CFG->prefix}wiki w + WHERE w.course = $restore->course_id")) { + //Iterate over each wiki->summary + $i = 0; //Counter to send some output to the browser to avoid timeouts + foreach ($wikis as $wiki) { + //Increment counter + $i++; + $content = $wiki->summary; + $result = restore_decode_content_links_worker($content,$restore); + if ($result != $content) { + //Update record + $wiki->summary = addslashes($result); + $status = update_record("wiki",$wiki); + if ($CFG->debug>7) { + echo "

".$content."
changed to
".$result."

"; + } + } + //Do some output + if (($i+1) % 5 == 0) { + echo "."; + if (($i+1) % 100 == 0) { + echo "
"; + } + backup_flush(300); + } + } + } + + return $status; + } ?>