Skip to content

Commit

Permalink
Ensure links of the form /mod/quiz/view.php?q=332 are backed up and r…
Browse files Browse the repository at this point in the history
…estored correctly.
  • Loading branch information
tjhunt committed Dec 21, 2007
1 parent 91374f3 commit 8cfd7fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions mod/quiz/backuplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,10 @@ function quiz_encode_content_links ($content,$preferences) {
$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;
}

Expand Down
25 changes: 24 additions & 1 deletion mod/quiz/restorelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,6 @@ function quiz_decode_content_links ($content,$restore) {
}

//Link to quiz view by moduleid

$searchstring='/\$@(QUIZVIEWBYID)\*([0-9]+)@\$/';
//We look for it
preg_match_all($searchstring,$result,$foundset);
Expand All @@ -526,6 +525,30 @@ function quiz_decode_content_links ($content,$restore) {
}
}

//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;
}

Expand Down

0 comments on commit 8cfd7fa

Please sign in to comment.