Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved automatic relinking in backup and restore. Credits go to sko…

…dak.

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)
  • Loading branch information...
commit 69731e2cc5bd43b73758ae66962245fc4a557bc6 1 parent 6cd4abd
stronk7 authored
21 backup/restorelib.php
View
@@ -63,9 +63,6 @@ function restore_refresh_events($restore) {
//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 "<ul>";
@@ -75,15 +72,31 @@ function restore_decode_content_links($restore) {
//Check if the xxxx_decode_content_links_caller exists
$function_name = $name."_decode_content_links_caller";
if (function_exists($function_name)) {
- echo "<li>".get_string ("to")." ".get_string("modulenameplural",$name);
+ echo "<li>".get_string ("from")." ".get_string("modulenameplural",$name);
$status = $function_name($restore);
echo '</li>';
}
}
}
echo "</ul>";
+
+ // 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.
14 mod/assignment/backuplib.php
View
@@ -156,10 +156,24 @@ function assignment_check_backup_mods($course,$user_data=false,$backup_unique_co
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
103 mod/assignment/restorelib.php
View
@@ -232,6 +232,109 @@ function assignment_restore_files ($oldassid, $newassid, $olduserid, $newuserid,
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 "<br /><hr />".$content."<br />changed to<br />".$result."<hr /><br />";
+ }
+ }
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
+ }
+ 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) {
14 mod/chat/backuplib.php
View
@@ -109,10 +109,24 @@ function chat_check_backup_mods($course,$user_data=false,$backup_unique_code) {
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
104 mod/chat/restorelib.php
View
@@ -130,6 +130,110 @@ function chat_messages_restore_mods($old_chat_id, $new_chat_id,$info,$restore) {
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 "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
+ }
+ }
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
+ }
+ 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) {
17 mod/choice/backuplib.php
View
@@ -151,7 +151,24 @@ function choice_check_backup_mods($course,$user_data=false,$backup_unique_code)
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
104 mod/choice/restorelib.php
View
@@ -251,6 +251,110 @@ function choice_answers_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 "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
+ }
+ }
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
+ }
+ 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) {
185 mod/forum/restorelib.php
View
@@ -963,158 +963,71 @@ function forum_decode_content_links ($content,$restore) {
//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 "<ul>";
-
- //FORUM: Decode every POST (message) in the coure
-
- //Check we are restoring forums
- if ($restore->mods['forum']->restore == 1) {
- echo "<li>".get_string("from")." ".get_string("modulenameplural","forum").'</li>';
- //Get all course posts
- if ($posts = get_records_sql ("SELECT p.id, p.message
- FROM {$CFG->prefix}forum_posts p,
- {$CFG->prefix}forum_discussions d
- WHERE d.course = $restore->course_id AND
- p.discussion = d.id")) {
- //Iterate over each post->message
- $i = 0; //Counter to send some output to the browser to avoid timeouts
- foreach ($posts as $post) {
- //Increment counter
- $i++;
- $content = $post->message;
- $result = forum_decode_content_links($content,$restore);
- if ($result != $content) {
- //Update record
- $post->message = addslashes($result);
- $status = update_record("forum_posts",$post);
- if ($CFG->debug>7) {
- echo "<br /><hr />".$content."<br />changed to<br />".$result."<hr /><br />";
- }
- }
- //Do some output
- if (($i+1) % 5 == 0) {
- echo ".";
- if (($i+1) % 100 == 0) {
- echo "<br />";
- }
- backup_flush(300);
+
+ //Process every POST (message) in the course
+ if ($posts = get_records_sql ("SELECT p.id, p.message
+ FROM {$CFG->prefix}forum_posts p,
+ {$CFG->prefix}forum_discussions d
+ WHERE d.course = $restore->course_id AND
+ p.discussion = d.id")) {
+ //Iterate over each post->message
+ $i = 0; //Counter to send some output to the browser to avoid timeouts
+ foreach ($posts as $post) {
+ //Increment counter
+ $i++;
+ $content = $post->message;
+ $result = restore_decode_content_links_worker($content,$restore);
+ if ($result != $content) {
+ //Update record
+ $post->message = addslashes($result);
+ $status = update_record("forum_posts",$post);
+ if ($CFG->debug>7) {
+ echo "<br /><hr />".$content."<br />changed to<br />".$result."<hr /><br />";
}
}
- }
- }
-
- //FORUM: Decode every FORUM (intro) in the coure
-
- //Check we are restoring forums
- if ($restore->mods['forum']->restore == 1) {
- //Get all course forums
- if ($forums = get_records_sql ("SELECT f.id, f.intro
- FROM {$CFG->prefix}forum f
- WHERE f.course = $restore->course_id")) {
- //Iterate over each forum->intro
- $i = 0; //Counter to send some output to the browser to avoid timeouts
- foreach ($forums as $forum) {
- //Increment counter
- $i++;
- $content = $forum->intro;
- $result = forum_decode_content_links($content,$restore);
- if ($result != $content) {
- //Update record
- $forum->intro = addslashes($result);
- $status = update_record("forum",$forum);
- if ($CFG->debug>7) {
- echo "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
- }
- }
- //Do some output
- if (($i+1) % 5 == 0) {
- echo ".";
- if (($i+1) % 100 == 0) {
- echo "<br />";
- }
- backup_flush(300);
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
}
+ backup_flush(300);
}
}
}
- //RESOURCE: Decode every RESOURCE (alltext) in the coure
-
- //Check we are restoring resources
- if ($restore->mods['resource']->restore == 1) {
- echo "<li>".get_string("from")." ".get_string("modulenameplural","resource").'</li>';
- //Get all course resources
- if ($resources = get_records_sql ("SELECT r.id, r.alltext
- FROM {$CFG->prefix}resource r
- WHERE r.course = $restore->course_id")) {
- //Iterate over each resource->alltext
- $i = 0; //Counter to send some output to the browser to avoid timeouts
- foreach ($resources as $resource) {
- //Increment counter
- $i++;
- $content = $resource->alltext;
- $result = forum_decode_content_links($content,$restore);
- if ($result != $content) {
- //Update record
- $resource->alltext = addslashes($result);
- $status = update_record("resource",$resource);
- if ($CFG->debug>7) {
- echo "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
- }
- }
- //Do some output
- if (($i+1) % 5 == 0) {
- echo ".";
- if (($i+1) % 100 == 0) {
- echo "<br />";
- }
- backup_flush(300);
+ //Process every FORUM (intro) in the course
+ if ($forums = get_records_sql ("SELECT f.id, f.intro
+ FROM {$CFG->prefix}forum f
+ WHERE f.course = $restore->course_id")) {
+ //Iterate over each forum->intro
+ $i = 0; //Counter to send some output to the browser to avoid timeouts
+ foreach ($forums as $forum) {
+ //Increment counter
+ $i++;
+ $content = $forum->intro;
+ $result = restore_decode_content_links_worker($content,$restore);
+ if ($result != $content) {
+ //Update record
+ $forum->intro = addslashes($result);
+ $status = update_record("forum",$forum);
+ if ($CFG->debug>7) {
+ echo "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
}
}
- }
- }
-
- //RESOURCE: Decode every RESOURCE (summary) in the coure
-
- //Check we are restoring resources
- if ($restore->mods['resource']->restore == 1) {
- //Get all course resources
- if ($resources = get_records_sql ("SELECT r.id, r.summary
- FROM {$CFG->prefix}resource r
- WHERE r.course = $restore->course_id")) {
- //Iterate over each resource->summary
- $i = 0; //Counter to send some output to the browser to avoid timeouts
- foreach ($resources as $resource) {
- //Increment counter
- $i++;
- $content = $resource->summary;
- $result = forum_decode_content_links($content,$restore);
- if ($result != $content) {
- //Update record
- $resource->summary = addslashes($result);
- $status = update_record("resource",$resource);
- if ($CFG->debug>7) {
- echo "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
- }
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
}
- //Do some output
- if (($i+1) % 5 == 0) {
- echo ".";
- if (($i+1) % 100 == 0) {
- echo "<br />";
- }
- backup_flush(300);
+ backup_flush(300);
}
- }
}
}
- echo "</ul>";
return $status;
}
?>
18 mod/glossary/backuplib.php
View
@@ -335,6 +335,24 @@ function glossary_check_backup_mods($course,$user_data=false,$backup_unique_code
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
137 mod/glossary/restorelib.php
View
@@ -509,6 +509,143 @@ function glossary_restore_files ($oldgloid, $newgloid, $oldentryid, $newentryid,
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 "<br /><hr />".$content."<br />changed to<br />".$result."<hr /><br />";
+ }
+ }
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
+ }
+ 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 "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
+ }
+ }
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
+ }
+ 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) {
35 mod/label/restorelib.php
View
@@ -61,6 +61,41 @@ function label_restore_mods($mod,$restore) {
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 "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
+ }
+ }
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
+ }
+ 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) {
17 mod/lesson/backuplib.php
View
@@ -419,7 +419,24 @@ function lesson_check_backup_mods($course,$user_data=false,$backup_unique_code)
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
109 mod/lesson/restorelib.php
View
@@ -635,7 +635,114 @@ function lesson_default_restore_mods($info, $restore) {
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 "<br /><hr />".$content."<br />changed to<br />".$result."<hr /><br />";
+ }
+ }
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
+ }
+ 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) {
18 mod/quiz/backuplib.php
View
@@ -997,6 +997,24 @@ function quiz_check_backup_mods($course,$user_data=false,$backup_unique_code) {
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
104 mod/quiz/restorelib.php
View
@@ -1861,6 +1861,110 @@ function quiz_grades_restore_mods($quiz_id,$info,$restore) {
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 "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
+ }
+ }
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
+ }
+ 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) {
242 mod/resource/restorelib.php
View
@@ -169,232 +169,42 @@ function resource_decode_content_links ($content,$restore) {
//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 "<ul>";
-
- //ASSIGNMENT: Decode every ASSIGNMENT (description) in the coure
-
- //Check we are restoring assignments
- if ($restore->mods['assignment']->restore == 1) {
- echo "<li>".get_string("from")." ".get_string("modulenameplural","assignment").'</li>';
- //Get all course assignments
- 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 = resource_decode_content_links($content,$restore);
- if ($result != $content) {
- //Update record
- $assignment->description = addslashes($result);
- $status = update_record("assignment",$assignment);
- if ($CFG->debug>7) {
- echo "<br><hr>".$content."<br>changed to</br>".$result."<hr><br>";
- }
- }
- //Do some output
- if (($i+1) % 5 == 0) {
- echo ".";
- if (($i+1) % 100 == 0) {
- echo "<br>";
- }
- backup_flush(300);
- }
- }
- }
- }
-
- //FORUM: Decode every POST (message) in the coure
-
- //Check we are restoring forums
- if ($restore->mods['forum']->restore == 1) {
- echo "<li>".get_string("from")." ".get_string("modulenameplural","forum").'</li>';
- //Get all course posts
- if ($posts = get_records_sql ("SELECT p.id, p.message
- FROM {$CFG->prefix}forum_posts p,
- {$CFG->prefix}forum_discussions d
- WHERE d.course = $restore->course_id AND
- p.discussion = d.id")) {
- //Iterate over each post->message
- $i = 0; //Counter to send some output to the browser to avoid timeouts
- foreach ($posts as $post) {
- //Increment counter
- $i++;
- $content = $post->message;
- $result = resource_decode_content_links($content,$restore);
- if ($result != $content) {
- //Update record
- $post->message = addslashes($result);
- $status = update_record("forum_posts",$post);
- if ($CFG->debug>7) {
- echo "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
- }
- }
- //Do some output
- if (($i+1) % 5 == 0) {
- echo ".";
- if (($i+1) % 100 == 0) {
- echo "<br />";
- }
- backup_flush(300);
- }
- }
- }
- }
-
- //FORUM: Decode every FORUM (intro) in the coure
-
- //Check we are restoring forums
- if ($restore->mods['forum']->restore == 1) {
- //Get all course forums
- if ($forums = get_records_sql ("SELECT f.id, f.intro
- FROM {$CFG->prefix}forum f
- WHERE f.course = $restore->course_id")) {
- //Iterate over each forum->intro
- $i = 0; //Counter to send some output to the browser to avoid timeouts
- foreach ($forums as $forum) {
- //Increment counter
- $i++;
- $content = $forum->intro;
- $result = resource_decode_content_links($content,$restore);
- if ($result != $content) {
- //Update record
- $forum->intro = addslashes($result);
- $status = update_record("forum",$forum);
- if ($CFG->debug>7) {
- echo "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
- }
- }
- //Do some output
- if (($i+1) % 5 == 0) {
- echo ".";
- if (($i+1) % 100 == 0) {
- echo "<br />";
- }
- backup_flush(300);
- }
- }
- }
- }
-
- //LESSON: Decode every LESSON PAGE (contents) in the coure
-
- //Check we are restoring lessons
- if ($restore->mods['lesson']->restore == 1) {
- echo "<li>".get_string("from")." ".get_string("modulenameplural","lesson").'</li>';
- //Get all course lesson pages
- if ($pages = get_records_sql ("SELECT p.id, p.contents
- FROM {$CFG->prefix}lesson l,
- {$CFG->prefix}lesson_pages p
- WHERE l.course = $restore->course_id AND
- p.lessonid = l.id")) {
- //Iterate over each lesson page
- $i = 0; //Counter to send some output to the browser to avoid timeouts
- foreach ($pages as $page) {
- //Increment counter
- $i++;
- $content = $page->contents;
- $result = resource_decode_content_links($content,$restore);
- if ($result != $content) {
- //Update record
- $page->contents = addslashes($result);
- $status = update_record("lesson_pages",$page);
- if ($CFG->debug>7) {
- echo "<br><hr>".$content."<br>changed to</br>".$result."<hr><br>";
- }
- }
- //Do some output
- if (($i+1) % 5 == 0) {
- echo ".";
- if (($i+1) % 100 == 0) {
- echo "<br>";
- }
- backup_flush(300);
- }
- }
- }
- }
-
- //RESOURCE: Decode every RESOURCE (alltext) in the coure
+ if ($resources = get_records_sql ("SELECT r.id, r.alltext, r.summary
+ FROM {$CFG->prefix}resource r
+ WHERE r.course = $restore->course_id")) {
- //Check we are restoring resources
- if ($restore->mods['resource']->restore == 1) {
- echo "<li>".get_string("from")." ".get_string("modulenameplural","resource").'</li>';
- //Get all course resources
- if ($resources = get_records_sql ("SELECT r.id, r.alltext
- FROM {$CFG->prefix}resource r
- WHERE r.course = $restore->course_id")) {
- //Iterate over each resource->alltext
- $i = 0; //Counter to send some output to the browser to avoid timeouts
- foreach ($resources as $resource) {
- //Increment counter
- $i++;
- $content = $resource->alltext;
- $result = resource_decode_content_links($content,$restore);
- if ($result != $content) {
- //Update record
- $resource->alltext = addslashes($result);
- $status = update_record("resource",$resource);
- if ($CFG->debug>7) {
- echo "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
- }
- }
- //Do some output
- if (($i+1) % 5 == 0) {
- echo ".";
- if (($i+1) % 100 == 0) {
- echo "<br />";
- }
- backup_flush(300);
+ $i = 0; //Counter to send some output to the browser to avoid timeouts
+ foreach ($resources as $resource) {
+ //Increment counter
+ $i++;
+ $content1 = $resource->alltext;
+ $content2 = $resource->summary;
+ $result1 = restore_decode_content_links_worker($content1,$restore);
+ $result2 = restore_decode_content_links_worker($content2,$restore);
+
+ if ($result1 != $content1 || $result2 != $content2) {
+ //Update record
+ $resource->alltext = addslashes($result1);
+ $resource->summary = addslashes($result2);
+ $status = update_record("resource",$resource);
+ if ($CFG->debug>7) {
+ echo "<br /><hr />".$content1."<br />changed to</br>".$result1."<hr /><br />";
+ echo "<br /><hr />".$content2."<br />changed to</br>".$result2."<hr /><br />";
}
}
- }
- }
-
- //RESOURCE: Decode every RESOURCE (summary) in the coure
-
- //Check we are restoring resources
- if ($restore->mods['resource']->restore == 1) {
- //Get all course resources
- if ($resources = get_records_sql ("SELECT r.id, r.summary
- FROM {$CFG->prefix}resource r
- WHERE r.course = $restore->course_id")) {
- //Iterate over each resource->summary
- $i = 0; //Counter to send some output to the browser to avoid timeouts
- foreach ($resources as $resource) {
- //Increment counter
- $i++;
- $content = $resource->summary;
- $result = resource_decode_content_links($content,$restore);
- if ($result != $content) {
- //Update record
- $resource->summary = addslashes($result);
- $status = update_record("resource",$resource);
- if ($CFG->debug>7) {
- echo "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
- }
- }
- //Do some output
- if (($i+1) % 5 == 0) {
- echo ".";
- if (($i+1) % 100 == 0) {
- echo "<br />";
- }
- backup_flush(300);
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
}
+ backup_flush(300);
}
}
}
-
- echo "</ul>";
return $status;
}
18 mod/scorm/backuplib.php
View
@@ -190,6 +190,24 @@ function backup_scorm_files($bf,$preferences) {
}
+ //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
104 mod/scorm/restorelib.php
View
@@ -353,6 +353,110 @@ function scorm_restore_files ($package, $restore) {
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 "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
+ }
+ }
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
+ }
+ 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) {
14 mod/survey/backuplib.php
View
@@ -142,10 +142,24 @@ function survey_check_backup_mods($course,$user_data=false,$backup_unique_code)
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
104 mod/survey/restorelib.php
View
@@ -194,6 +194,110 @@ function survey_analysis_restore_mods($survey_id,$info,$restore) {
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 "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
+ }
+ }
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
+ }
+ 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) {
19 mod/wiki/backuplib.php
View
@@ -170,4 +170,23 @@ function backup_wiki_files($bf,$preferences) {
}
+ //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;
+ }
+
?>
137 mod/wiki/restorelib.php
View
@@ -259,4 +259,141 @@ function wiki_restore_files ($oldwikiid, $newwikiid, $oldentryid, $newentryid, $
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 "<br /><hr />".$content."<br />changed to<br />".$result."<hr /><br />";
+ }
+ }
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
+ }
+ 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 "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
+ }
+ }
+ //Do some output
+ if (($i+1) % 5 == 0) {
+ echo ".";
+ if (($i+1) % 100 == 0) {
+ echo "<br />";
+ }
+ backup_flush(300);
+ }
+ }
+ }
+
+ return $status;
+ }
?>
Please sign in to comment.
Something went wrong with that request. Please try again.