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 !!
This commit is contained in:
stronk7
2004-04-01 23:31:56 +00:00
parent b6eddad2c4
commit 01f50e060e
4 changed files with 53 additions and 3 deletions
+26
View File
@@ -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<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) {
+1 -1
View File
@@ -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
+24
View File
@@ -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<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) {
+2 -2
View File
@@ -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