]> git.mjollnir.org Git - moodle.git/commitdiff
Now resource/view.php?r=XXX links are recoded properly in backup/restore. MDL-9450
authorstronk7 <stronk7>
Sun, 22 Apr 2007 22:07:03 +0000 (22:07 +0000)
committerstronk7 <stronk7>
Sun, 22 Apr 2007 22:07:03 +0000 (22:07 +0000)
Merged from MOODLE_18_STABLE

mod/resource/backuplib.php
mod/resource/restorelib.php

index 14d8e288e05b5edbddcc9a466ac387ddf849e584..d7866e677b82df86d94a608c8cf7e8826a689493 100644 (file)
         $buscar="/(".$base."\/mod\/resource\/view.php\?id\=)([0-9]+)/";
         $result= preg_replace($buscar,'$@RESOURCEVIEWBYID*$2@$',$result);
 
+        //Link to resource view by resourceid
+        $buscar="/(".$base."\/mod\/resource\/view.php\?r\=)([0-9]+)/";
+        $result= preg_replace($buscar,'$@RESOURCEVIEWBYR*$2@$',$result);
+
         return $result;
     }
 
index 8cd63342bf12a10e670f49bf57a6db7a96b00bc4..21cabb71071ed1bc15c3f459cf15cb95ed777676 100644 (file)
             }
         }
 
+        //Link to resource view by resourceid
+
+        $searchstring='/\$@(RESOURCEVIEWBYR)\*([0-9]+)@\$/';
+        //We look for it
+        preg_match_all($searchstring,$result,$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,"resource",$old_id);
+                //Personalize the searchstring
+                $searchstring='/\$@(RESOURCEVIEWBYR)\*('.$old_id.')@\$/';
+                //If it is a link to this course, update the link to its new location
+                if($rec->new_id) {
+                    //Now replace it
+                    $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/resource/view.php?r='.$rec->new_id,$result);
+                } else {
+                    //It's a foreign link so leave it as original
+                    $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/resource/view.php?r='.$old_id,$result);
+                }
+            }
+        }
+
         return $result;
     }