From: tjhunt Date: Fri, 21 Dec 2007 15:38:36 +0000 (+0000) Subject: Ensure links of the form /mod/quiz/view.php?q=332 are backed up and restored correctly. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=8cfd7faf10ff09cda6e66820ecdab85ca9e2dc86;p=moodle.git Ensure links of the form /mod/quiz/view.php?q=332 are backed up and restored correctly. --- diff --git a/mod/quiz/backuplib.php b/mod/quiz/backuplib.php index adf32597f2..fe289d3393 100644 --- a/mod/quiz/backuplib.php +++ b/mod/quiz/backuplib.php @@ -584,6 +584,10 @@ $buscar="/(".$base."\/mod\/quiz\/view.php\?id\=)([0-9]+)/"; $result= preg_replace($buscar,'$@QUIZVIEWBYID*$2@$',$result); + //Link to quiz view by quizid + $buscar="/(".$base."\/mod\/quiz\/view.php\?q\=)([0-9]+)/"; + $result= preg_replace($buscar,'$@QUIZVIEWBYQ*$2@$',$result); + return $result; } diff --git a/mod/quiz/restorelib.php b/mod/quiz/restorelib.php index 80cf0c3708..758e2b2b18 100644 --- a/mod/quiz/restorelib.php +++ b/mod/quiz/restorelib.php @@ -502,7 +502,6 @@ } //Link to quiz view by moduleid - $searchstring='/\$@(QUIZVIEWBYID)\*([0-9]+)@\$/'; //We look for it preg_match_all($searchstring,$result,$foundset); @@ -526,6 +525,30 @@ } } + //Link to quiz view by quizid + $searchstring='/\$@(QUIZVIEWBYQ)\*([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 (course_modules id) + $rec = backup_getid($restore->backup_unique_code,'quiz',$old_id); + //Personalize the searchstring + $searchstring='/\$@(QUIZVIEWBYQ)\*('.$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/quiz/view.php?q='.$rec->new_id,$result); + } else { + //It's a foreign link so leave it as original + $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/quiz/view.php?q='.$old_id,$result); + } + } + } + return $result; }