Permalink
Browse files

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 !!
  • Loading branch information...
1 parent b6eddad commit 01f50e060e59e45b8cdb41af1f764593eced9476 stronk7 committed Apr 1, 2004
Showing with 53 additions and 3 deletions.
  1. +26 −0 backup/backuplib.php
  2. +1 −1 backup/lib.php
  3. +24 −0 backup/restorelib.php
  4. +2 −2 backup/version.php
View
@@ -426,6 +426,8 @@ function end_tag($tag,$level=0,$endline=true) {
//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 @@ function backup_module($bf,$preferences,$module) {
}
+ //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<hr>".$content." \nchanged to \n".$result."<hr>\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) {
View
@@ -481,7 +481,7 @@ function backup_getid ($backup_unique_code, $table, $old_id) {
//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
View
@@ -1034,6 +1034,30 @@ function restore_create_events($restore,$xml_file) {
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<hr>".$content." \nchanged to \n".$result."<hr>\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) {
View
@@ -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

0 comments on commit 01f50e0

Please sign in to comment.