From: stronk7 Date: Sat, 24 Apr 2004 00:40:45 +0000 (+0000) Subject: First version of inter-activities mantained in backup/restore. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=56eea82e085e7c45b157fd1eb454892d9400ebc6;p=moodle.git First version of inter-activities mantained in backup/restore. All the conversion to some pseudo-codes are done at backup time. In the restore process, every link is decoded to new ids. For now, this is supported: - In backup: -all links to forums are encoded. - In restore: - all links to forums are decoded. - from forums (post->message). - from resources (resource->alltext). The process requires a backup made with the same version (because it has to be properly encoded at backup time). Old backups will work without conversions at all. Only tested with some little courses. It would be perfect to have some "big" course to test it. Please, test and feedback, ciao :-) --- diff --git a/backup/STATUS.txt b/backup/STATUS.txt index d0110d9a1f..6af982b3ce 100644 --- a/backup/STATUS.txt +++ b/backup/STATUS.txt @@ -126,7 +126,9 @@ Backup Details: - Modify the backup frontend..............................NOT EXISTS - Modify the backup of course_sections and course_modules.NOT EXISTS - Modify every module backuplib to work properly..........NOT EXISTS - + - Encode every possible internal link........................IN PROGRESS + - Links to forums.........................................DONE + - Links to resources......................................NOT EXISTS Restore Details: =============== - Delete old entries at restore start........................DONE @@ -243,6 +245,11 @@ Restore Details: - From database...........................................DONE - From filesystem.........................................DONE - Upload backup files........................................DONE + - Decode every possible internal link........................IN PROGRESS + - Links to forums.........................................IN PROGRESS + - From forums (post->message)..........................DONE + - From resources (resource->alltext)...................DONE + - Links to resources......................................NOT EXISTS ========== ========== ========== =========== =========== =========== === diff --git a/backup/backuplib.php b/backup/backuplib.php index eccc3513f2..6f42d620c0 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -1114,11 +1114,13 @@ //It does this conversions: // - $CFG->wwwroot -----------------------------> $@WWWROOT@$ // - /file.php/$courseid -----------------------> /file.php/$@COURSEID@$ + // - Links to forums everywhere (DB) are encoded. // function backup_encode_absolute_links($content) { global $CFG,$preferences; + //Now we encode calls to file.php or wwwroot $search = array ($CFG->wwwroot, "/file.php/".$preferences->backup_course); @@ -1127,9 +1129,17 @@ $result = str_replace($search,$replace,$content); - //if ($result != $content) { //Debug - // echo "\n
".$content." \nchanged to \n".$result."
\n"; //Debug - //} //Debug + foreach ($preferences->mods as $name => $info) { + //Check if the xxxx_encode_content_links exists + $function_name = $name."_encode_content_links"; + if (function_exists($function_name)) { + $result = $function_name($result,$preferences); + } + } + + if ($result != $content && $CFG->debug>7) { //Debug + echo "

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

"; //Debug + } //Debug return $result; } diff --git a/backup/restore_execute.html b/backup/restore_execute.html index a0306e79e6..eb25617aaf 100644 --- a/backup/restore_execute.html +++ b/backup/restore_execute.html @@ -275,6 +275,14 @@ } } + //Now, if all is OK, adjust inter-activity links + if ($status) { + echo "
  • ".get_string("decodinginternallinks"); + if (!$status = restore_decode_content_links($restore)) { + notify("Could not refresh events for activities!"); + } + } + //Now if all is OK, update: // - course modinfo field // - categories table diff --git a/backup/restorelib.php b/backup/restorelib.php index 54f51e587e..6893af36bd 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -77,6 +77,33 @@ return $status; } + //This function makes all the necessary calls to xxxx_decode_content_links_caller() + //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 + function restore_decode_content_links($restore) { + + global $CFG; + + $status = true; + + echo ""; + + return $status; + } + //This function read the xml file and store it data from the info zone in an object function restore_read_xml_info ($xml_file) { @@ -1077,11 +1104,15 @@ //It does this conversions: // - $@WWWROOT@$ -------------------------------> $CFG->wwwroot // - $@COURSEID@$ ------------------------------> $courseid - // + // + //Note: Inter-activities linking is being implemented as a final + //step in the restore execution, because we need to have it + //finished to know all the oldid, newid equivaleces function restore_decode_absolute_links($content) { global $CFG,$restore; - + + //Now decode wwwroot and file.php calls $search = array ("$@WWWROOT@$", "$@COURSEID@$"); @@ -1090,9 +1121,9 @@ $result = str_replace($search,$replace,$content); - //if ($result != $content) { //Debug - // echo "\n
    ".$content." \nchanged to \n".$result."
    \n"; //Debug - //} //Debug + if ($result != $content && $CFG->debug>7) { //Debug + echo "

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

    "; //Debug + } //Debug return $result; } diff --git a/backup/version.php b/backup/version.php index 9a207b5a82..10ff8b23e2 100644 --- a/backup/version.php +++ b/backup/version.php @@ -5,6 +5,6 @@ // database (backup_version) to determine whether upgrades should // be performed (see db/backup_*.php) -$backup_version = 2004042100; // The current version is a date (YYYYMMDDXX) +$backup_version = 2004042400; // The current version is a date (YYYYMMDDXX) $backup_release = "1.3 development"; // User-friendly version number diff --git a/mod/forum/backuplib.php b/mod/forum/backuplib.php index 3186425876..44a79ec757 100644 --- a/mod/forum/backuplib.php +++ b/mod/forum/backuplib.php @@ -284,10 +284,37 @@ 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 forum_encode_content_links ($content,$preferences) { + $base = '\$@WWWROOT@\$'; + //Link to the list of forums + $buscar="/(".$base."\/mod\/forum\/index.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@FORUMINDEX*$2@$',$content); + //Link to forum view by moduleid + $buscar="/(".$base."\/mod\/forum\/view.php\?id\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@FORUMVIEWBYID*$2@$',$result); + //Link to forum view by forumid + $buscar="/(".$base."\/mod\/forum\/view.php\?f\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@FORUMVIEWBYF*$2@$',$result); + //Link to forum discussion with parent syntax + $buscar="/(".$base."\/mod\/forum\/discuss.php\?d\=)([0-9]+)\&parent\=([0-9]+)/"; + $result= preg_replace($buscar,'$@FORUMDISCUSSIONVIEWPARENT*$2*$3@$',$result); + + //Link to forum discussion with relative syntax + $buscar="/(".$base."\/mod\/forum\/discuss.php\?d\=)([0-9]+)\#([0-9]+)/"; + $result= preg_replace($buscar,'$@FORUMDISCUSSIONVIEWINSIDE*$2*$3@$',$result); + + //Link to forum discussion by discussionid + $buscar="/(".$base."\/mod\/forum\/discuss.php\?d\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@FORUMDISCUSSIONVIEW*$2@$',$result); + + return $result; + } // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE diff --git a/mod/forum/restorelib.php b/mod/forum/restorelib.php index e1c9086c1b..e530408f5d 100644 --- a/mod/forum/restorelib.php +++ b/mod/forum/restorelib.php @@ -659,4 +659,231 @@ } return $status; } + + //Return a content decoded to support interactivities linking. Every module + //should have its own. They are called automatically from + //forum_decode_content_links_caller() function in each module + //in the restore process + function forum_decode_content_links ($content,$restore) { + + global $CFG; + + $result = $content; + + //Link to the list of forums + + $searchstring='/\$@(FORUMINDEX)\*([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 + //We get the needed variables here + $courseid = $restore->course_id; + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/forum/index.php?id='.$courseid,$result); + } + + //Link to forum view by moduleid + + $searchstring='/\$@(FORUMVIEWBYID)\*([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_modules id) + $rec = backup_getid($restore->backup_unique_code,"course_modules",$old_id); + if($rec->new_id) { + //Personalize the searchstring + $searchstring='/\$@(FORUMVIEWBYID)\*('.$old_id.')@\$/'; + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/forum/view.php?id='.$rec->new_id,$result); + } + } + } + + //Link to forum view by forumid + + $searchstring='/\$@(FORUMVIEWBYF)\*([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 (forum id) + $rec = backup_getid($restore->backup_unique_code,"forum",$old_id); + if($rec->new_id) { + //Personalize the searchstring + $searchstring='/\$@(FORUMVIEWBYF)\*('.$old_id.')@\$/'; + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/forum/view.php?f='.$rec->new_id,$result); + } + } + } + + //Link to forum discussion by discussionid + + $searchstring='/\$@(FORUMDISCUSSIONVIEW)\*([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 (discussion id) + $rec = backup_getid($restore->backup_unique_code,"forum_discussions",$old_id); + if($rec->new_id) { + //Personalize the searchstring + $searchstring='/\$@(FORUMDISCUSSIONVIEW)\*('.$old_id.')@\$/'; + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/forum/discuss.php?d='.$rec->new_id,$result); + } + } + } + + //Link to forum discussion with parent syntax + + $searchstring='/\$@(FORUMDISCUSSIONVIEWPARENT)\*([0-9]+)\*([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] and foundset[3]. They are the old_ids + foreach($foundset[2] as $key => $old_id) { + $old_id2 = $foundset[3][$key]; + //We get the needed variables here (discussion id and post id) + $rec = backup_getid($restore->backup_unique_code,"forum_discussions",$old_id); + $rec2 = backup_getid($restore->backup_unique_code,"forum_posts",$old_id2); + if($rec->new_id && $rec2->new_id) { + //Personalize the searchstring + $searchstring='/\$@(FORUMDISCUSSIONVIEWPARENT)\*('.$old_id.')\*('.$old_id2.')@\$/'; + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/forum/discuss.php?d='.$rec->new_id.'&parent='.$rec2->new_id,$result); + } + } + } + + //Link to forum discussion with relative syntax + + $searchstring='/\$@(FORUMDISCUSSIONVIEWINSIDE)\*([0-9]+)\*([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] and foundset[3]. They are the old_ids + foreach($foundset[2] as $key => $old_id) { + $old_id2 = $foundset[3][$key]; + //We get the needed variables here (discussion id and post id) + $rec = backup_getid($restore->backup_unique_code,"forum_discussions",$old_id); + $rec2 = backup_getid($restore->backup_unique_code,"forum_posts",$old_id2); + if($rec->new_id && $rec2->new_id) { + //Personalize the searchstring + $searchstring='/\$@(FORUMDISCUSSIONVIEWINSIDE)\*('.$old_id.')\*('.$old_id2.')@\$/'; + //Now replace it + $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/forum/discuss.php?d='.$rec->new_id.'#'.$rec2->new_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 forum_decode_content_links_caller($restore) { + + global $CFG; + + $status = true; + + echo ""; + return $status; + } ?>