]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14727 - Do a database update to fix random questions with the wrong parent (there...
authortjhunt <tjhunt>
Wed, 7 May 2008 13:34:54 +0000 (13:34 +0000)
committertjhunt <tjhunt>
Wed, 7 May 2008 13:34:54 +0000 (13:34 +0000)
lib/db/upgrade.php
question/upgrade.php
version.php

index f89268996c39985e8931cc759eac328921dcfc84..985975d52ec1788ca031ec400489850bece2cb45 100644 (file)
@@ -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;
 }
 
index 9d50d8aefe6d918f6ca110cbc648599544a0451f..f9a049cd9c9a92532ace187fd6acfd57d9f56560 100644 (file)
@@ -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");
+}
+
 ?>
index 3304e1e0f9019db26f4d6c6d06473edb82d4002f..8df006e784dd8dba080d6d5871cd86647da8babc 100644 (file)
@@ -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