]> git.mjollnir.org Git - moodle.git/commitdiff
Fix "data truncated errors" by setting set NULL values in int field to 0 before chang...
authorgbateson <gbateson>
Thu, 27 Apr 2006 08:45:34 +0000 (08:45 +0000)
committergbateson <gbateson>
Thu, 27 Apr 2006 08:45:34 +0000 (08:45 +0000)
mod/hotpot/db/mysql.php
mod/hotpot/db/update_to_v2.php
mod/hotpot/version.php

index 23fe22d6c4055ff202f11e97d48b9e888fbb04c6..746d3e37aa1f0dc3cdfb7dd577f9c3fb75f12de9 100644 (file)
@@ -27,32 +27,14 @@ function hotpot_upgrade($oldversion) {
                $ok = $ok && hotpot_update_to_v2_1_16();\r
        }\r
 \r
-\r
-    if ($oldversion < 2006042600) {\r
-        table_column('hotpot_attempts','starttime','starttime','int','10','unsigned','0','not null');\r
-        table_column('hotpot_attempts','endtime','endtime','int','10','unsigned','0','not null');\r
-        table_column('hotpot_attempts','score','score','int','6','unsigned','0','not null');\r
-        table_column('hotpot_attempts','penalties','penalties','int','6','unsigned','0','not null');\r
-        table_column('hotpot_attempts','timestart','timestart','int','10','unsigned','0','not null');\r
-        table_column('hotpot_attempts','timefinish','timefinish','int','10','unsigned','0','not null');\r
-        table_column('hotpot_attempts','clickreportid','clickreportid','int','10','unsigned','0','not null');\r
-        \r
-        execute_sql("ALTER TABLE {$CFG->prefix}hotpot_questions CHANGE type type tinyint(4) unsigned NOT NULL default '0'");\r
-\r
-        table_column('hotpot_questions','text','text','int','10','unsigned','0','not null');\r
-        \r
-        \r
-        execute_sql("ALTER TABLE {$CFG->prefix}hotpot_responses CHANGE weighting weighting smallint(8) unsigned NOT NULL default '0'");\r
-        execute_sql("ALTER TABLE {$CFG->prefix}hotpot_responses CHANGE score score smallint(8) unsigned NOT NULL default '0'");\r
-        execute_sql("ALTER TABLE {$CFG->prefix}hotpot_responses CHANGE hints hints smallint(6) unsigned NOT NULL default '0'");\r
-        execute_sql("ALTER TABLE {$CFG->prefix}hotpot_responses CHANGE clues clues smallint(6) unsigned NOT NULL default '0'");\r
-        execute_sql("ALTER TABLE {$CFG->prefix}hotpot_responses CHANGE checks checks smallint(6) unsigned NOT NULL default '0'");\r
-\r
-    }\r
+       // update to HotPot v2.1.17\r
+       if ($oldversion < 2006042601) {\r
+               $ok = $ok && hotpot_get_update_to_v2();\r
+               $ok = $ok && hotpot_update_to_v2_1_17();\r
+       }\r
        \r
        return $ok;\r
 }\r
-\r
 function hotpot_get_update_to_v2() {\r
        global $CFG;\r
        $filepath = "$CFG->dirroot/mod/hotpot/db/update_to_v2.php";\r
index c337548e29acfde2a24ef7b497e2fc6b68ab481b..f0eb1ced3a01d055d3625c1583cfef52be4c1447 100644 (file)
@@ -1,4 +1,36 @@
 <?PHP\r
+function hotpot_update_to_v2_1_17() {\r
+       global $CFG;\r
+       $ok = true;\r
+\r
+       $ok = $ok && hotpot_denull_int_field('hotpot_attempts', 'starttime', '10');\r
+       $ok = $ok && hotpot_denull_int_field('hotpot_attempts', 'endtime', '10');\r
+       $ok = $ok && hotpot_denull_int_field('hotpot_attempts', 'score', '6');\r
+       $ok = $ok && hotpot_denull_int_field('hotpot_attempts', 'penalties',  '6');\r
+       $ok = $ok && hotpot_denull_int_field('hotpot_attempts', 'timestart', '10');\r
+       $ok = $ok && hotpot_denull_int_field('hotpot_attempts', 'timefinish', '10');\r
+       $ok = $ok && hotpot_denull_int_field('hotpot_attempts', 'clickreportid', '10');\r
+\r
+       $ok = $ok && hotpot_denull_int_field('hotpot_questions', 'type', '4');\r
+       $ok = $ok && hotpot_denull_int_field('hotpot_questions', 'text', '10');\r
+\r
+       $ok = $ok && hotpot_denull_int_field('hotpot_responses', 'weighting', '8');\r
+       $ok = $ok && hotpot_denull_int_field('hotpot_responses', 'score', '8');\r
+       $ok = $ok && hotpot_denull_int_field('hotpot_responses', 'hints', '6');\r
+       $ok = $ok && hotpot_denull_int_field('hotpot_responses', 'clues', '6');\r
+       $ok = $ok && hotpot_denull_int_field('hotpot_responses', 'checks', '6');\r
+\r
+       return $ok;\r
+}\r
+function hotpot_denull_int_field($table, $field, $size) {\r
+       global $CFG;\r
+       $ok = true;\r
+\r
+       $ok = $ok && execute_sql("UPDATE {$CFG->prefix}$table SET $field=0 WHERE $field IS NULL");\r
+       $ok = $ok && hotpot_db_update_field_type($table, $field, $field, 'INTEGER', $size, 'UNSIGNED', 'NOT NULL', 0);\r
+\r
+       return $ok;\r
+}\r
 function hotpot_update_to_v2_1_16() {\r
        global $CFG;\r
        $ok = true;\r
index dd2f8610187b5c41410091dd79f54124460db2e7..bb1814f2ace5acc7c623f0dc425ebd7d88080a7d 100644 (file)
@@ -3,7 +3,7 @@
 ///  Code fragment to define the version of hotpot
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
-$module->version  = 2006042600;  // release date of this version (see note below)
+$module->version  = 2006042601;  // release date of this version (see note below)
 $module->release  = 'v2.1.16';    // human-friendly version name (used in mod/hotpot/lib.php)
 $module->cron     = 0;           // period for cron to check this module (secs)
 // interpretation of YYYYMMDDXY version numbers