Now workshop are working under the new system to relink. Bug 3678.

(http://moodle.org/bugs/bug.php?op=show&bugid=3678)

Merged from MOODLE_15_STABLE
This commit is contained in:
stronk7 2005-07-04 22:25:10 +00:00
parent 95bfd2078b
commit a9c80fec8e
2 changed files with 119 additions and 0 deletions

View File

@ -396,10 +396,24 @@
return $info;
}
//Return a content encoded to support interactivities linking. Every module
//should have its own. They are called automatically from the backup procedure.
function workshop_encode_content_links ($content,$preferences) {
global $CFG;
$base = preg_quote($CFG->wwwroot,"/");
//Link to the list of workshops
$buscar="/(".$base."\/mod\/workshop\/index.php\?id\=)([0-9]+)/";
$result= preg_replace($buscar,'$@WORKSHOPINDEX*$2@$',$content);
//Link to workshop view by moduleid
$buscar="/(".$base."\/mod\/workshop\/view.php\?id\=)([0-9]+)/";
$result= preg_replace($buscar,'$@WORKSHOPVIEWBYID*$2@$',$result);
return $result;
}
// INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE

View File

@ -645,6 +645,111 @@
return $status;
}
//Return a content decoded to support interactivities linking. Every module
//should have its own. They are called automatically from
//workshop_decode_content_links_caller() function in each module
//in the restore process
function workshop_decode_content_links ($content,$restore) {
global $CFG;
$result = $content;
//Link to the list of workshops
$searchstring='/\$@(WORKSHOPINDEX)\*([0-9]+)@\$/';
//We look for it
preg_match_all($searchstring,$content,$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 id)
$rec = backup_getid($restore->backup_unique_code,"course",$old_id);
//Personalize the searchstring
$searchstring='/\$@(WORKSHOPINDEX)\*('.$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/workshop/index.php?id='.$rec->new_id,$result);
} else {
//It's a foreign link so leave it as original
$result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/workshop/index.php?id='.$old_id,$result);
}
}
}
//Link to workshop view by moduleid
$searchstring='/\$@(WORKSHOPVIEWBYID)\*([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,"course_modules",$old_id);
//Personalize the searchstring
$searchstring='/\$@(WORKSHOPVIEWBYID)\*('.$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/workshop/view.php?id='.$rec->new_id,$result);
} else {
//It's a foreign link so leave it as original
$result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/workshop/view.php?id='.$old_id,$result);
}
}
}
return $result;
}
//This function makes all the necessary calls to xxxx_decode_content_links()
//function in each module, passing them the desired contents to be decoded
//from backup format to destination site/course in order to mantain inter-activities
//working in the backup/restore process. It's called from restore_decode_content_links()
//function in restore process
function workshop_decode_content_links_caller($restore) {
global $CFG;
$status = true;
//Process every WORKSHOP (description) in the course
if ($workshops = get_records_sql ("SELECT w.id, w.description
FROM {$CFG->prefix}workshop w
WHERE w.course = $restore->course_id")) {
//Iterate over each workshop->description
$i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($workshops as $workshop) {
//Increment counter
$i++;
$content = $workshop->description;
$result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) {
//Update record
$workshop->description = addslashes($result);
$status = update_record("workshop",$workshop);
if ($CFG->debug>7) {
echo "<br /><hr />".$content."<br />changed to</br>".$result."<hr /><br />";
}
}
//Do some output
if (($i+1) % 5 == 0) {
echo ".";
if (($i+1) % 100 == 0) {
echo "<br />";
}
backup_flush(300);
}
}
}
return $status;
}
//This function returns a log record with all the necessay transformations
//done. It's used by restore_log_module() to restore modules log.
function workshop_restore_logs($restore,$log) {