From: stronk7 Date: Thu, 1 Apr 2004 23:31:56 +0000 (+0000) Subject: First attempt to encode/decode some absolute path parts X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=01f50e060e59e45b8cdb41af1f764593eced9476;p=moodle.git First attempt to encode/decode some absolute path parts in the backup/restore process in order to have every call to file.php working in destination courses. Specially useful to contents created with th HTML editor because it uses this type of URLs to images, smiles... NOTE: This make 1.3 backups not restorable in 1.2 systems !! --- diff --git a/backup/backuplib.php b/backup/backuplib.php index 33f072615a..145e896967 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -426,6 +426,8 @@ //Return the start tag, the contents and the end tag function full_tag($tag,$level=0,$endline=true,$content,$to_utf=true) { + //Here we encode absolute links + $content = backup_encode_absolute_links($content); $st = start_tag($tag,$level,$endline); $co=""; if ($to_utf) { @@ -1107,6 +1109,30 @@ } + //This function encode things to make backup multi-site fully functional + //It does this conversions: + // - $CFG->wwwroot -----------------------------> $@WWWROOT@$ + // - /file.php/$courseid -----------------------> /file.php/$@COURSEID@$ + // + function backup_encode_absolute_links($content) { + + global $CFG,$preferences; + + $search = array ($CFG->wwwroot, + "/file.php/".$preferences->backup_course); + + $replace = array ("$@WWWROOT@$", + "/file.php/$@COURSEID@$"); + + $result = str_replace($search,$replace,$content); + + //if ($result != $content) { //Debug + // echo "\n
".$content." \nchanged to \n".$result."
\n"; //Debug + //} //Debug + + return $result; + } + //This function copies all the needed files under the "users" directory to the "user_files" //directory under temp/backup function backup_copy_user_files ($preferences) { diff --git a/backup/lib.php b/backup/lib.php index 75c6a8cffe..8a8fdb173f 100644 --- a/backup/lib.php +++ b/backup/lib.php @@ -481,7 +481,7 @@ //This function is used to add slashes and decode from UTF-8 //It's used intensivelly when restoring modules and saving them in db function backup_todb ($data) { - return addslashes(utf8_decode($data)); + return restore_decode_absolute_links(addslashes(utf8_decode($data))); } //This function is used to check that every necessary function to diff --git a/backup/restorelib.php b/backup/restorelib.php index f0e19e83f2..05348033f4 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -1034,6 +1034,30 @@ return $status; } + //This function decode things to make restore multi-site fully functional + //It does this conversions: + // - $@WWWROOT@$ -------------------------------> $CFG->wwwroot + // - $@COURSEID@$ ------------------------------> $courseid + // + function restore_decode_absolute_links($content) { + + global $CFG,$restore; + + $search = array ("$@WWWROOT@$", + "$@COURSEID@$"); + + $replace = array ($CFG->wwwroot, + $restore->course_id); + + $result = str_replace($search,$replace,$content); + + //if ($result != $content) { //Debug + // echo "\n
".$content." \nchanged to \n".$result."
\n"; //Debug + //} //Debug + + return $result; + } + //This function restores the userfiles from the temp (user_files) directory to the //dataroot/users directory function restore_user_files($restore) { diff --git a/backup/version.php b/backup/version.php index ab67c528a0..8978af3f6d 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 = 2004032500; // The current version is a date (YYYYMMDDXX) +$backup_version = 2004040100; // The current version is a date (YYYYMMDDXX) -$backup_release = "1.2.1"; // User-friendly version number +$backup_release = "1.3 development"; // User-friendly version number