diff --git a/backup/moodle2/backup_course_task.class.php b/backup/moodle2/backup_course_task.class.php index 10003100144..09abf4d7f8e 100644 --- a/backup/moodle2/backup_course_task.class.php +++ b/backup/moodle2/backup_course_task.class.php @@ -103,6 +103,23 @@ class backup_course_task extends backup_task { $this->built = true; } + /** + * Code the transformations to perform in the course in + * order to get transportable (encoded) links + */ + static public function encode_content_links($content) { + global $CFG; + + $base = preg_quote($CFG->wwwroot,"/"); + + // Link to the course main page (it also covers "&topic=xx" and "&week=xx" + // because they don't become transformed (section number) in backup/restore + $search = '/(' . $base . '\/course\/view.php\?id\=)([0-9]+)/'; + $content= preg_replace($search, '$@COURSEVIEWBYID*$2@$', $content); + + return $content; + } + // Protected API starts here /** diff --git a/backup/moodle2/backup_xml_transformer.class.php b/backup/moodle2/backup_xml_transformer.class.php index 081e53de714..c847b1f3e62 100644 --- a/backup/moodle2/backup_xml_transformer.class.php +++ b/backup/moodle2/backup_xml_transformer.class.php @@ -110,7 +110,10 @@ class backup_xml_transformer extends xml_contenttransformer { private function register_link_encoders() { $encoders = array(); - // First of all, add the module ones. Each module supporting moodle2 backups MUST have it + // Add the course encoder + $encoders['backup_course_task'] = 'encode_content_links'; + + // Add the module ones. Each module supporting moodle2 backups MUST have it $mods = get_plugin_list('mod'); foreach ($mods as $mod => $moddir) { if (plugin_supports('mod', $mod, FEATURE_BACKUP_MOODLE2)) { @@ -118,7 +121,7 @@ class backup_xml_transformer extends xml_contenttransformer { } } - // Add the block encodes + // Add the block encoders $blocks = get_plugin_list('block'); foreach ($blocks as $block => $blockdir) { if (class_exists('backup_' . $block . '_block_task')) {