]> git.mjollnir.org Git - moodle.git/commitdiff
Added some bug-fixing code from Eloy Lafuente that fixes a quiz problem.
authormoodler <moodler>
Tue, 11 Nov 2003 16:13:57 +0000 (16:13 +0000)
committermoodler <moodler>
Tue, 11 Nov 2003 16:13:57 +0000 (16:13 +0000)
What happens is that adding random questions used to set the timestamps
of these questions to the same value.  This is fine in normal operation,
but it stuffs up the backup of that course, overwriting the question.
When the course is restored, the missing questions cause quizzes to
have lots of red notices like "Question not found".

Anyhow, this patch should safely fix older installations that may have
these duplicate questions lying around.

THANKS ELOY!

mod/quiz/db/mysql.php
mod/quiz/db/postgres7.php
mod/quiz/version.php
version.php

index 6729c197803e18b530104aaf88ab49f9f5292a7a..4a09717559441d613292677bcb33dcf9877ecdc6 100644 (file)
@@ -159,6 +159,28 @@ function quiz_upgrade($oldversion) {
         }
     }
 
+    if ($oldversion < 2003111100) {
+        $duplicates = get_records_sql("SELECT stamp as id,count(*) as cuenta
+                                       FROM {$CFG->prefix}quiz_questions
+                                       GROUP BY stamp
+                                       HAVING count(*)>1");
+
+        if ($duplicates) {
+            notify("You have some quiz questions with duplicate stamps IDs.  Cleaning these up.");
+            foreach ($duplicates as $duplicate) {
+                $questions = get_records("quiz_questions","stamp",$duplicate->id);
+                $add = 1;
+                foreach ($questions as $question) {
+                    echo "Changing question id $question->id stamp to ".$duplicate->id.$add."<br>";
+                    set_field("quiz_questions","stamp",$duplicate->id.$add,"id",$question->id);
+                    $add++;
+                }
+            } 
+        } else {
+            notify("Checked your quiz questions for stamp duplication errors, but no problems were found.", "green");
+        }
+    }
+
     return true;
 }
 
index 13ca997b411dc314b48ec717d2c2ab337c25993b..6997247cd0857f588c8fc99e7fe6f27e46a5fdac 100644 (file)
@@ -114,6 +114,28 @@ function quiz_upgrade($oldversion) {
         }
     }
 
+    if ($oldversion < 2003111100) {
+        $duplicates = get_records_sql("SELECT stamp as id,count(*) as cuenta
+                                       FROM {$CFG->prefix}quiz_questions
+                                       GROUP BY stamp
+                                       HAVING count(*)>1");
+
+        if ($duplicates) {
+            notify("You have some quiz questions with duplicate stamps IDs.  Cleaning these up.");
+            foreach ($duplicates as $duplicate) {
+                $questions = get_records("quiz_questions","stamp",$duplicate->id);
+                $add = 1;
+                foreach ($questions as $question) {
+                    echo "Changing question id $question->id stamp to ".$duplicate->id.$add."<br>";
+                    set_field("quiz_questions","stamp",$duplicate->id.$add,"id",$question->id);
+                    $add++;
+                }
+            } 
+        } else {
+            notify("Checked your quiz questions for stamp duplication errors, but no problems were found.", "green");
+        }
+    }
+
     return true;
 }
 
index c3d5ec9e1c67fea8dfdbeb55b727e2d9b3665399..353d0cc356d195fd11108d93185d76a6efa6e535 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2003082700;   // The (date) version of this module
+$module->version  = 2003111100;   // The (date) version of this module
 $module->cron     = 0;            // How often should cron check this module (seconds)?
 
 ?>
index c2a12eb3f8cb2d033ea132892efab311a5007918..a9137aac782a70429115ebb5a038e3297126824f 100644 (file)
@@ -5,7 +5,7 @@
 // database to determine whether upgrades should
 // be performed (see lib/db/*.php)
 
-$version = 2003110400;   // The current version is a date (YYYYMMDDXX)
+$version = 2003111100;   // The current version is a date (YYYYMMDDXX)
 
 $release = "1.2 development";   // User-friendly version number