Skip to content

Commit

Permalink
Now resource/view.php?r=XXX links are recoded properly in backup/rest…
Browse files Browse the repository at this point in the history
…ore. MDL-9450
  • Loading branch information
stronk7 committed Apr 22, 2007
1 parent 67ca523 commit d09757d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mod/resource/backuplib.php
Expand Up @@ -113,6 +113,10 @@ function resource_encode_content_links ($content,$preferences) {
$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;
}

Expand Down
25 changes: 25 additions & 0 deletions mod/resource/restorelib.php
Expand Up @@ -167,6 +167,31 @@ function resource_decode_content_links ($content,$restore) {
}
}

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

Expand Down

0 comments on commit d09757d

Please sign in to comment.