From ac21fa9a1c94d2f7adc2aa8f383b41de42c17a1c Mon Sep 17 00:00:00 2001 From: Safat Date: Fri, 9 Dec 2022 13:44:48 +1100 Subject: [PATCH] MDL-76509 core: Upgrade error resolve for slot tags --- lib/db/upgrade.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index f07db5c2196..6486be29f3c 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2332,10 +2332,16 @@ privatefiles,moodle|/user/files.php'; $runinsert = function (int $lastslot, array $tagstrings) use ($DB) { $conditiondata = $DB->get_field('question_set_references', 'filtercondition', ['itemid' => $lastslot, 'component' => 'mod_quiz', 'questionarea' => 'slot']); - $condition = json_decode($conditiondata); - $condition->tags = $tagstrings; - $DB->set_field('question_set_references', 'filtercondition', json_encode($condition), - ['itemid' => $lastslot, 'component' => 'mod_quiz', 'questionarea' => 'slot']); + + // It is possible to have leftover tags in the database, without a corresponding + // slot, because of an old bugs (e.g. MDL-76193). Therefore, if the slot is not found, + // we can safely discard these tags. + if (!empty($conditiondata)) { + $condition = json_decode($conditiondata); + $condition->tags = $tagstrings; + $DB->set_field('question_set_references', 'filtercondition', json_encode($condition), + ['itemid' => $lastslot, 'component' => 'mod_quiz', 'questionarea' => 'slot']); + } }; foreach ($slottags as $tag) {