From e2134c5ddcbf4db593d8270d4505d8743c7178c6 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Fri, 9 May 2008 15:50:44 +0000 Subject: [PATCH] Following the fixes for MDL-14750 and MDL-10899, do a database upgrade that fixes any bogus values in the parent or category columns of multianswer questions' subquestions. --- question/type/multianswer/db/upgrade.php | 27 ++++++++++++++++++++++++ question/type/multianswer/version.php | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/question/type/multianswer/db/upgrade.php b/question/type/multianswer/db/upgrade.php index 7156a8744b..60238976db 100644 --- a/question/type/multianswer/db/upgrade.php +++ b/question/type/multianswer/db/upgrade.php @@ -32,7 +32,34 @@ function xmldb_qtype_multianswer_upgrade($oldversion=0) { /// $result = result of "/lib/ddllib.php" function calls /// } + if ($result && $oldversion < 2008050800) { + question_multianswer_fix_subquestion_parents_and_categories(); + } + return $result; } +/** + * Due to MDL-14750, subquestions of multianswer questions restored from backup will + * have the wrong parent, and due to MDL-10899 subquestions of multianswer questions + * that have been moved between categories will be in the wrong category, This code fixes these up. + */ +function question_multianswer_fix_subquestion_parents_and_categories() { + global $CFG; + + $result = true; + $rs = get_recordset_sql('SELECT q.id, q.category, qma.sequence FROM ' . $CFG->prefix . + 'question q JOIN ' . $CFG->prefix . 'question_multianswer qma ON q.id = qma.question'); + if ($rs) { + while ($q = rs_fetch_next_record($rs)) { + $result = $result && execute_sql('UPDATE ' . $CFG->prefix . 'question' . + ' SET parent = ' . $q->id . ', category = ' . $q->category . + ' WHERE id IN (' . $q->sequence . ') AND parent <> 0'); + } + rs_close($rs); + } else { + $result = false; + } + return $result; +} ?> diff --git a/question/type/multianswer/version.php b/question/type/multianswer/version.php index c39730578d..6d0f10af81 100644 --- a/question/type/multianswer/version.php +++ b/question/type/multianswer/version.php @@ -1,6 +1,6 @@ version = 2006032200; -$plugin->requires = 2007101000; +$plugin->version = 2008050800; +$plugin->requires = 2007101509; ?> -- 2.39.5