From 499a5f2929a22668d0c03c08ea17858d7d730a71 Mon Sep 17 00:00:00 2001 From: David Szkiba Date: Thu, 21 Nov 2024 13:27:23 +0100 Subject: [PATCH] Fix if no old context exists --- classes/catquiz.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/classes/catquiz.php b/classes/catquiz.php index a62cbc50f..c2a2aa359 100644 --- a/classes/catquiz.php +++ b/classes/catquiz.php @@ -2649,9 +2649,13 @@ private static function get_unfinished_question_states() { * @param int $oldcontextid The ID of the context to move items from * @return void */ - public function move_items_to_new_context(int $newcontextid, int $oldcontextid): void { + public function move_items_to_new_context(int $newcontextid, ?int $oldcontextid): void { global $DB; + if (!$oldcontextid) { + return; + } + $oldactiveparams = []; $oldparams = $DB->get_records('local_catquiz_itemparams', ['contextid' => $oldcontextid]); foreach ($oldparams as $op) { @@ -2687,6 +2691,7 @@ public function move_items_to_new_context(int $newcontextid, int $oldcontextid): $DB->update_record('local_catquiz_itemparams', $ip); } else { // Otherwise: Should we copy the param from the previous context? + unset($copiedparam->id); $copiedparam = $oldactiveparams[$item->activeparamid]; $copiedparam->contextid = $newcontextid; $now = time();