From 0081e95baf3f961cc3f12afc87e7ef350be5056b Mon Sep 17 00:00:00 2001 From: Paola Maneggia Date: Mon, 20 Jan 2025 18:49:42 +0100 Subject: [PATCH] MDL-84264 backup: encode and decode urls for the new course section page --- backup/moodle2/backup_course_task.class.php | 1 + backup/moodle2/restore_course_task.class.php | 1 + backup/util/helper/tests/backup_encode_content_test.php | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/backup/moodle2/backup_course_task.class.php b/backup/moodle2/backup_course_task.class.php index 784b7eeac88..d28e054c9f4 100644 --- a/backup/moodle2/backup_course_task.class.php +++ b/backup/moodle2/backup_course_task.class.php @@ -161,6 +161,7 @@ class backup_course_task extends backup_task { // 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. $content = self::encode_links_helper($content, 'COURSEVIEWBYID', '/course/view.php?id='); + $content = self::encode_links_helper($content, 'COURSESECTIONBYID', '/course/section.php?id='); // A few other key course links. $content = self::encode_links_helper($content, 'GRADEINDEXBYID', '/grade/index.php?id='); diff --git a/backup/moodle2/restore_course_task.class.php b/backup/moodle2/restore_course_task.class.php index b34987e0879..c890fd48d48 100644 --- a/backup/moodle2/restore_course_task.class.php +++ b/backup/moodle2/restore_course_task.class.php @@ -160,6 +160,7 @@ class restore_course_task extends restore_task { // 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. $rules[] = new restore_decode_rule('COURSEVIEWBYID', '/course/view.php?id=$1', 'course'); + $rules[] = new restore_decode_rule('COURSESECTIONBYID', '/course/section.php?id=$1', 'course_section'); // A few other key course links. $rules[] = new restore_decode_rule('GRADEINDEXBYID', '/grade/index.php?id=$1', 'course'); diff --git a/backup/util/helper/tests/backup_encode_content_test.php b/backup/util/helper/tests/backup_encode_content_test.php index 2a5bebe0813..d03b83a0035 100644 --- a/backup/util/helper/tests/backup_encode_content_test.php +++ b/backup/util/helper/tests/backup_encode_content_test.php @@ -52,6 +52,7 @@ final class backup_encode_content_test extends \basic_testcase { $encoded = backup_course_task::encode_content_links( $httproot . '/course/view.php?id=123, ' . $httpsroot . '/course/view.php?id=123, ' . + $httpsroot . '/course/section.php?id=123, ' . $httpsroot . '/grade/index.php?id=123, ' . $httpsroot . '/grade/report/index.php?id=123, ' . $httpsroot . '/badges/view.php?type=2&id=123, ' . @@ -59,7 +60,8 @@ final class backup_encode_content_test extends \basic_testcase { $httpsroot . '/pluginfile.php/123 and ' . urlencode($httpsroot . '/pluginfile.php/123') . '.' ); - $this->assertEquals('$@COURSEVIEWBYID*123@$, $@COURSEVIEWBYID*123@$, $@GRADEINDEXBYID*123@$, ' . + $this->assertEquals('$@COURSEVIEWBYID*123@$, $@COURSEVIEWBYID*123@$, ' . + '$@COURSESECTIONBYID*123@$, $@GRADEINDEXBYID*123@$, ' . '$@GRADEREPORTINDEXBYID*123@$, $@BADGESVIEWBYID*123@$, $@USERINDEXVIEWBYID*123@$, ' . '$@PLUGINFILEBYCONTEXT*123@$ and $@PLUGINFILEBYCONTEXTURLENCODED*123@$.', $encoded); @@ -68,6 +70,7 @@ final class backup_encode_content_test extends \basic_testcase { $encoded = backup_course_task::encode_content_links( $httproot . '/course/view.php?id=123, ' . $httpsroot . '/course/view.php?id=123, ' . + $httproot . '/course/section.php?id=123, ' . $httproot . '/grade/index.php?id=123, ' . $httproot . '/grade/report/index.php?id=123, ' . $httproot . '/badges/view.php?type=2&id=123, ' . @@ -75,7 +78,8 @@ final class backup_encode_content_test extends \basic_testcase { $httproot . '/pluginfile.php/123 and ' . urlencode($httproot . '/pluginfile.php/123') . '.' ); - $this->assertEquals('$@COURSEVIEWBYID*123@$, $@COURSEVIEWBYID*123@$, $@GRADEINDEXBYID*123@$, ' . + $this->assertEquals('$@COURSEVIEWBYID*123@$, $@COURSEVIEWBYID*123@$, ' . + '$@COURSESECTIONBYID*123@$, $@GRADEINDEXBYID*123@$, ' . '$@GRADEREPORTINDEXBYID*123@$, $@BADGESVIEWBYID*123@$, $@USERINDEXVIEWBYID*123@$, ' . '$@PLUGINFILEBYCONTEXT*123@$ and $@PLUGINFILEBYCONTEXTURLENCODED*123@$.', $encoded); $CFG->wwwroot = $oldroot;