From 994fbaabc98d7143f9db1028c9e39df6817f45ba Mon Sep 17 00:00:00 2001 From: tjhunt Date: Wed, 7 May 2008 13:34:54 +0000 Subject: [PATCH] MDL-14727 - Do a database update to fix random questions with the wrong parent (there may be some of these floating around in people's databases becuase of MDL-5482.) --- lib/db/upgrade.php | 7 +++++++ question/upgrade.php | 15 +++++++++++++++ version.php | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index f89268996c..985975d52e 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -61,6 +61,13 @@ function xmldb_main_upgrade($oldversion=0) { upgrade_main_savepoint($result, 2008050200); } + if ($result && $oldversion < 2008050700) { + /// Fix minor problem caused by MDL-5482. + require_once($CFG->dirroot . '/question/upgrade.php'); + $result = $result && question_fix_random_question_parents(); + upgrade_main_savepoint($result, 2008050700); + } + return $result; } diff --git a/question/upgrade.php b/question/upgrade.php index 9d50d8aefe..f9a049cd9c 100644 --- a/question/upgrade.php +++ b/question/upgrade.php @@ -331,4 +331,19 @@ function question_upgrade_context_etc(){ return $result; } + +/** + * In Moodle, all random questions should have question.parent set to be the same + * as question.id. One effect of MDL-5482 is that this will not be true for questions that + * were backed up then restored. The probably does not cause many problems, except occasionally, + * if the bogus question.parent happens to point to a multianswer question type, or when you + * try to do a subsequent backup. Anyway, these question.parent values should be fixed, and + * that is what this update does. + */ +function question_fix_random_question_parents() { + global $CFG; + return execute_sql('UPDATE ' . $CFG->prefix . 'question SET parent = id ' . + "WHERE qtype = 'random' AND parent <> id"); +} + ?> diff --git a/version.php b/version.php index 3304e1e0f9..8df006e784 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2008050200; // YYYYMMDD = date of the last version bump + $version = 2008050700; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20080507)'; // Human-friendly version name -- 2.39.5