]> git.mjollnir.org Git - moodle.git/commitdiff
moodle16cleanup: mod/quiz uniqueid does not exists, taking upgrade script
authormartinlanghoff <martinlanghoff>
Wed, 17 May 2006 06:56:14 +0000 (06:56 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 17 May 2006 06:56:14 +0000 (06:56 +0000)
from mysql.php ver 2005070202. dropping some unused tables during the
transition from quiz to question lib

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

index 0338567c8cf1066637fa2bd00a5a1d2613923d61..d3e8b38cf67ee1a8fc1ccd094e2369532a0eead0 100644 (file)
@@ -1002,7 +1002,8 @@ function quiz_upgrade($oldversion) {
     }
 
     if ($oldversion < 2006021400) {
-        modify_database('','CREATE UNIQUE INDEX prefix_quiz_attempts_uniqueid_uk ON prefix_quiz_attempts (uniqueid);');
+        // modify_database('','CREATE UNIQUE INDEX prefix_quiz_attempts_uniqueid_uk ON prefix_quiz_attempts (uniqueid);');
+        // this index will not be created since uniqueid was not added, proper upgrade will be on 2006042801
     }
 
     if ($oldversion < 2006021501) {
@@ -1206,7 +1207,7 @@ function quiz_upgrade($oldversion) {
         }
     }
 
-    if ($oldversion < 2006051300) {
+    if ($oldversion < 2006051300) {  // this block also exec'ed by 2006042801 on MOODLE_16_STABLE
         // The newgraded field must always point to a valid state
         modify_database("","UPDATE prefix_question_sessions SET newgraded = newest where newgraded = '0'");
 
@@ -1221,6 +1222,28 @@ function quiz_upgrade($oldversion) {
                                    FROM prefix_quiz_attempts;");
     }
 
+    if ($oldversion < 2006051700) { // this block also exec'd by 2006042802 on MOODLE_16_STABLE
+
+        notice("The next set of upgrade operations may report an 
+                error if you are upgrading from v1.6. 
+                This error mesage is normal, and can be ignored.");
+        // this block is taken from mysql.php 2005070202
+        // add new unique id to prepare the way for lesson module to have its own attempts table
+        table_column('quiz_attempts', '', 'uniqueid', 'integer', '10', 'unsigned', '0', 'not null', 'id');
+        // initially we can use the id as the unique id because no other modules use attempts yet.
+        execute_sql("UPDATE {$CFG->prefix}quiz_attempts SET uniqueid = id", false);
+        // we set $CFG->attemptuniqueid to the next available id
+        $record = get_record_sql("SELECT nextval('{$CFG->prefix}quiz_attempts_id_seq')");
+        set_config('attemptuniqueid', empty($record->nextid) ? 1 : $record->nextid);
+        // the above will be a race condition, see bug 5468
+        modify_database('','CREATE UNIQUE INDEX prefix_quiz_attempts_uniqueid_uk ON prefix_quiz_attempts (uniqueid);');
+
+        // dropping unused tables
+        execute_sql('DROP TABLE '.$CFG->prefix.'question_essay_states');
+        execute_sql('DROP TABLE '.$CFG->prefix.'question_essay');
+        execute_sql('DROP TABLE '.$CFG->prefix.'quiz_attemptonlast_datasets');
+    }
+
     return true;
 }
 
index 37b52957598010edae61e5f4d74a65b94b92e44d..597b3c8ab3af935aea4a07764404fa8c1ce5b4e1 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2006051300;   // The (date) version of this module
+$module->version  = 2006051700;   // The (date) version of this module
 $module->requires = 2006022400;   // Requires this Moodle version
 $module->cron     = 0;            // How often should cron check this module (seconds)?