diff --git a/mod/data/restorelib.php b/mod/data/restorelib.php
index fcbfe38161d..3ac837bda75 100644
--- a/mod/data/restorelib.php
+++ b/mod/data/restorelib.php
@@ -1,4 +1,4 @@
-backup_unique_code,"course",$old_id);
+ /// Personalize the searchstring
+ $searchstring='/\$@(DATAINDEX)\*('.$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/data/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/data/index.php?id='.$old_id,$result);
+ }
+ }
+ }
+
+/// Link to data view by moduleid
+
+ $searchstring='/\$@(DATAVIEWBYID)\*([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='/\$@(DATAVIEWBYID)\*('.$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/data/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/data/view.php?id='.$old_id,$result);
+ }
+ }
+ }
+
+/// Link to data view by dataid
+
+ $searchstring='/\$@(DATAVIEWBYD)\*([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 (data id)
+ $rec = backup_getid($restore->backup_unique_code,"data",$old_id);
+ /// Personalize the searchstring
+ $searchstring='/\$@(DATAVIEWBYD)\*('.$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/data/view.php?d='.$rec->new_id,$result);
+ } else {
+ /// It's a foreign link so leave it as original
+ $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/data/view.php?d='.$old_id,$result);
+ }
+ }
+ }
+
+/// Link to data record (element)
+
+ $searchstring='/\$@(DATAVIEWRECORD)\*([0-9]+)\*([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] and foundset[3]. They are the old_ids
+ foreach($foundset[2] as $key => $old_id) {
+ $old_id2 = $foundset[3][$key];
+ /// We get the needed variables here (data id and record id)
+ $rec = backup_getid($restore->backup_unique_code,"data",$old_id);
+ $rec2 = backup_getid($restore->backup_unique_code,"data_records",$old_id2);
+ /// Personalize the searchstring
+ $searchstring='/\$@(DATAVIEWRECORD)\*('.$old_id.')\*('.$old_id2.')@\$/';
+ /// If it is a link to this course, update the link to its new location
+ if($rec->new_id && $rec2->new_id) {
+ /// Now replace it
+ $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/data/view.php?d='.$rec->new_id.'&rid='.$rec2->new_id,$result);
+ } else {
+ /// It's a foreign link so leave it as original
+ $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/data/view.php?d='.$old_id.'&rid='.$old_id2,$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
+ *
+ * @param object $restore the preferences used in restore
+ * @return boolean status of the execution
+ */
+function data_decode_content_links_caller($restore) {
+
+ global $CFG;
+ $status = true;
+
+/// Process every DATA (intro) in the course
+ if ($datas = get_records_sql ("SELECT d.id, d.intro
+ FROM {$CFG->prefix}data d
+ WHERE d.course = $restore->course_id")) {
+ /// Iterate over each data->intro
+ $i = 0; //Counter to send some output to the browser to avoid timeouts
+ foreach ($datas as $data) {
+ /// Increment counter
+ $i++;
+ $content = $data->intro;
+ $result = restore_decode_content_links_worker($content,$restore);
+ if ($result != $content) {
+ /// Update record
+ $data->intro = addslashes($result);
+ $status = update_record("data",$data);
+ if (debugging()) {
+ if (!defined('RESTORE_SILENTLY')) {
+ echo '