]> git.mjollnir.org Git - moodle.git/commitdiff
First attempt to encode/decode some absolute path parts
authorstronk7 <stronk7>
Thu, 1 Apr 2004 23:31:56 +0000 (23:31 +0000)
committerstronk7 <stronk7>
Thu, 1 Apr 2004 23:31:56 +0000 (23:31 +0000)
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 !!

backup/backuplib.php
backup/lib.php
backup/restorelib.php
backup/version.php

index 33f072615ad216837257b98a5b0a5016b8341ca5..145e896967ae359ee69ba4e5492f8459c975b610 100644 (file)
     
     //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) {
         
     }
 
+    //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) {
index 75c6a8cffedbeeaf854441876f26c24324925457..8a8fdb173f1351c7fb7158c7660b401b54ad7fc7 100644 (file)
     //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 
index f0e19e83f229609ca7808e3dbcd9dc2606519b07..05348033f4327a051abfcdc758bd08bfc2382639 100644 (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) {
index ab67c528a02dbf40db2cb664b7d2e6b851c13301..8978af3f6dd346d04d812e921accb0d5a2171da7 100644 (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