From 53f32cbd8ad629ba12beb153e4b5de76ce141aa5 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Mon, 17 Oct 2011 01:47:16 +0200 Subject: [PATCH] MDL-29626 backup - fix restore of links to course page to behave like other links --- backup/restorelib.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/backup/restorelib.php b/backup/restorelib.php index 84f5f2a23dd..6cf48e19496 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -209,10 +209,29 @@ define('RESTORE_GROUPS_GROUPINGS', 3); // Links to course $searchstring = '/\$@(COURSEVIEWBYID)\*([0-9]+)@\$/'; - $replacestring= $CFG->wwwroot . '/course/view.php?id=' . $restore->course_id; - $result = preg_replace($searchstring, $replacestring, $content); + // 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]) { + // 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 = '/\$@(COURSEVIEWBYID)\*('.$old_id.')@\$/'; + // If it is a link to itself, replace it + if (!empty($rec->new_id)) { + $replacestring = $CFG->wwwroot . '/course/view.php?id=' . $rec->new_id; + // It s a link to another course, keep it unmodified + } else { + $replacestring = $restore->original_wwwroot . '/course/view.php?id=' . $old_id; + } + // Perform the replacement + $content = preg_replace($searchstring, $replacestring, $content); + } + } - return $result; + return $content; } //This function is called from all xxxx_decode_content_links_caller(), -- 2.11.4.GIT