Improved automatic relinking in backup and restore. Credits go to skodak.
Complete refactoring of the system that was really awful (my fault!). Now everything is in its place and working like a charm, making things really easier to be implemented and amplied. Bug 3678 (http://moodle.org/bugs/bug.php?op=show&bugid=3678) (http://moodle.org/mod/forum/discuss.php?d=26530)
This commit is contained in:
@@ -232,6 +232,109 @@
|
||||
return $status;
|
||||
}
|
||||
|
||||
//Return a content decoded to support interactivities linking. Every module
|
||||
//should have its own. They are called automatically from
|
||||
//assignment_decode_content_links_caller() function in each module
|
||||
//in the restore process
|
||||
function assignment_decode_content_links ($content,$restore) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$result = $content;
|
||||
|
||||
//Link to the list of assignments
|
||||
|
||||
$searchstring='/\$@(ASSIGNMENTINDEX)\*([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='/\$@(ASSIGNMENTINDEX)\*('.$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/assignment/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/assignment/index.php?id='.$old_id,$result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Link to assignment view by moduleid
|
||||
|
||||
$searchstring='/\$@(ASSIGNMENTVIEWBYID)\*([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='/\$@(ASSIGNMENTVIEWBYID)\*('.$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/assignment/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/assignment/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 assignment_decode_content_links_caller($restore) {
|
||||
global $CFG;
|
||||
$status = true;
|
||||
|
||||
if ($assignments = get_records_sql ("SELECT a.id, a.description
|
||||
FROM {$CFG->prefix}assignment a
|
||||
WHERE a.course = $restore->course_id")) {
|
||||
//Iterate over each assignment->description
|
||||
$i = 0; //Counter to send some output to the browser to avoid timeouts
|
||||
foreach ($assignments as $assignment) {
|
||||
//Increment counter
|
||||
$i++;
|
||||
$content = $assignment->description;
|
||||
$result = restore_decode_content_links_worker($content,$restore);
|
||||
if ($result != $content) {
|
||||
//Update record
|
||||
$assignment->description = addslashes($result);
|
||||
$status = update_record("assignment",$assignment);
|
||||
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 converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
|
||||
//some texts in the module
|
||||
function assignment_restore_wiki2markdown ($restore) {
|
||||
|
||||
Reference in New Issue
Block a user