From 81c2aa8051006417b19ca04a8f17a67b69023538 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Thu, 27 Apr 2006 22:56:25 +0000 Subject: [PATCH] Checking one table and one column that, uder some servers didn't get correctly upgraded. Bug 5321. PG need testing! (http://moodle.org/bugs/bug.php?op=show&bugid=5321) --- mod/quiz/db/mysql.php | 16 ++++++++++++++++ mod/quiz/db/postgres7.php | 18 ++++++++++++++++++ mod/quiz/version.php | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/mod/quiz/db/mysql.php b/mod/quiz/db/mysql.php index a88c2f7f42..ac46c56e08 100644 --- a/mod/quiz/db/mysql.php +++ b/mod/quiz/db/mysql.php @@ -1019,6 +1019,22 @@ function quiz_upgrade($oldversion) { table_column('question', 'version', 'version', 'varchar', 255); } + if ($oldversion < 2006042800) { + // Check we have some un-renamed tables (verified in some servers) + if ($tables = $db->MetaTables('TABLES')) { + if (in_array($CFG->prefix.'quiz_randommatch', $tables) && + !in_array($CFG->prefix.'question_randomsamatch', $tables)) { + modify_database ("", "ALTER TABLE prefix_quiz_randommatch RENAME prefix_question_randomsamatch "); + } + // Check for one possible missing field in one table + if ($columns = $db->MetaColumnNames($CFG->prefix.'question_randomsamatch')) { + if (!in_array('shuffleanswers', $columns)) { + table_column('question_randomsamatch', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'choose'); + } + } + } + } + return true; } diff --git a/mod/quiz/db/postgres7.php b/mod/quiz/db/postgres7.php index a0ea972f22..5b3e37f165 100644 --- a/mod/quiz/db/postgres7.php +++ b/mod/quiz/db/postgres7.php @@ -1188,6 +1188,24 @@ function quiz_upgrade($oldversion) { table_column('question', 'version', 'version', 'varchar', 255); } + if ($oldversion < 2006042800) { + // Check we have some un-renamed tables (verified in some servers) + if ($tables = $db->MetaTables('TABLES')) { + if (in_array($CFG->prefix.'quiz_randommatch', $tables) && + !in_array($CFG->prefix.'question_randomsamatch', $tables)) { + modify_database ("", "ALTER TABLE prefix_quiz_randommatch RENAME prefix_question_randomsamatch "); + modify_database ("", "ALTER TABLE prefix_quiz_randommatch_id_seq RENAME prefix_question_randomsamatch_id_seq "); + execute_sql('ALTER TABLE '.$CFG->prefix.'question_randomsamatch ALTER COLUMN id SET DEFAULT nextval(\''.$CFG->prefix.'question_randomsamatch_id_seq\')',false); + } + // Check for one possible missing field in one table + if ($columns = $db->MetaColumnNames($CFG->prefix.'question_randomsamatch')) { + if (!in_array('shuffleanswers', $columns)) { + table_column('question_randomsamatch', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'choose'); + } + } + } + } + return true; } diff --git a/mod/quiz/version.php b/mod/quiz/version.php index da7a2881e4..abdfb06f0a 100644 --- a/mod/quiz/version.php +++ b/mod/quiz/version.php @@ -5,7 +5,7 @@ // This fragment is called by moodle_needs_upgrading() and /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2006041001; // The (date) version of this module +$module->version = 2006042800; // The (date) version of this module $module->requires = 2006022400; // Requires this Moodle version $module->cron = 0; // How often should cron check this module (seconds)? -- 2.39.5