From 976456a6f13fcd823029f252aa6bf70a816d054e Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Thu, 11 Dec 2025 11:19:09 +0000 Subject: [PATCH] MDL-86798 questions: Check original context is on the same site When checking if the original context exists during a restore, we need to check that we're looking at the context on the same site, not one on a different site that happens to have the same ID. --- backup/moodle2/restore_stepslib.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 645d206dd10..daa0cb6cad7 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -5555,7 +5555,11 @@ class restore_move_module_questions_categories extends restore_execution_step { // but if that context still exists on the site and the user has access then point question references // to the originals. $originalcontext = context::instance_by_id($contextid, IGNORE_MISSING); - if ($originalcontext && has_capability('mod/qbank:view', $originalcontext)) { + if ( + $this->task->is_samesite() + && $originalcontext + && has_capability('mod/qbank:view', $originalcontext) + ) { $originalquestions = get_questions_category(question_get_top_category($contextid), false); $targetcoursecontext = context_course::instance($this->get_courseid()); foreach ($originalquestions as $originalquestion) {