3 function choice_upgrade($oldversion) {
7 // This function does anything necessary to upgrade
8 // older versions to match current functionality
10 if ($oldversion < 2002090800) {
11 execute_sql(" ALTER TABLE `choice` CHANGE `answer1` `answer1` VARCHAR( 255 )");
12 execute_sql(" ALTER TABLE `choice` CHANGE `answer2` `answer2` VARCHAR( 255 )");
14 if ($oldversion < 2002102400) {
15 execute_sql(" ALTER TABLE `choice` ADD `answer3` varchar(255) NOT NULL AFTER `answer2`");
16 execute_sql(" ALTER TABLE `choice` ADD `answer4` varchar(255) NOT NULL AFTER `answer3`");
17 execute_sql(" ALTER TABLE `choice` ADD `answer5` varchar(255) NOT NULL AFTER `answer4`");
18 execute_sql(" ALTER TABLE `choice` ADD `answer6` varchar(255) NOT NULL AFTER `answer5`");
20 if ($oldversion < 2002122300) {
21 execute_sql("ALTER TABLE `choice_answers` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
23 if ($oldversion < 2003010100) {
24 execute_sql(" ALTER TABLE `choice` ADD `format` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `text` ");
25 execute_sql(" ALTER TABLE `choice` ADD `publish` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `answer6` ");
28 if ($oldversion < 2004010100) {
29 table_column("choice", "", "showunanswered", "integer", "4", "unsigned", "0", "", "publish");
31 if ($oldversion < 2004021700) {
32 modify_database("", "INSERT INTO prefix_log_display VALUES ('choice', 'choose', 'choice', 'name');");
33 modify_database("", "INSERT INTO prefix_log_display VALUES ('choice', 'choose again', 'choice', 'name');");
35 if ($oldversion < 2004070100) {
36 table_column("choice", "", "timeclose", "integer", "10", "unsigned", "0", "", "showunanswered");
37 table_column("choice", "", "timeopen", "integer", "10", "unsigned", "0", "", "showunanswered");
39 if ($oldversion < 2004070101) {
40 table_column("choice", "", "release", "integer", "2", "unsigned", "0", "", "publish");
41 table_column("choice", "", "allowupdate", "integer", "2", "unsigned", "0", "", "release");
43 if ($oldversion < 2004070102) {
44 modify_database("", "UPDATE prefix_choice SET allowupdate = '1' WHERE publish = 0;");
45 modify_database("", "UPDATE prefix_choice SET release = '1' WHERE publish > 0;");
46 modify_database("", "UPDATE prefix_choice SET publish = publish - 1 WHERE publish > 0;");
49 if ($oldversion < 2004111200){ // drop first to avoid conflicts when upgrading from 1.4+
50 execute_sql("ALTER TABLE {$CFG->prefix}choice DROP INDEX course;",false);
51 execute_sql("ALTER TABLE {$CFG->prefix}choice_answers DROP INDEX choice;",false);
52 execute_sql("ALTER TABLE {$CFG->prefix}choice_answers DROP INDEX userid;",false);
54 modify_database('','ALTER TABLE prefix_choice ADD INDEX course (course);');
55 modify_database('','ALTER TABLE prefix_choice_answers ADD INDEX choice (choice);');
56 modify_database('','ALTER TABLE prefix_choice_answers ADD INDEX userid (userid);');
59 if ($oldversion < 2005033001){
60 if (execute_sql("CREATE TABLE {$CFG->prefix}choice_options (
61 `id` int(10) unsigned NOT NULL auto_increment,
62 `choiceid` int(10) unsigned NOT NULL default '0',
64 `timemodified` int(10) NOT NULL default '0',
67 KEY choiceid (choiceid)
70 table_column('choice_answers', 'choice', 'choiceid', 'integer', '10', 'unsigned', 0, 'not null');
71 table_column('choice_answers', 'answer', 'optionid', 'integer', '10', 'unsigned', 0, 'not null');
73 table_column('choice', '', 'display', 'integer', '4', 'unsigned', 0, 'not null', 'release');
76 /// move old answers from choice to choice_options
78 if ($choices = get_records('choice')) {
79 foreach ($choices as $choice) {
80 for ($i=1; $i<=6; $i++
) { // We used to have six columns
81 $option = new stdClass
;
82 $option->text
= addslashes($choice->{'answer'.$i});
83 if ($option->text
) { /// Don't bother with blank options
84 $option->choiceid
= $choice->id
;
85 $option->timemodified
= $choice->timemodified
;
86 if ($option->id
= insert_record('choice_options', $option)) {
87 /// Update all the user answers to fit the new value
88 execute_sql("UPDATE {$CFG->prefix}choice_answers
89 SET optionid='$option->id'
90 WHERE choiceid='$choice->id'
100 modify_database('','ALTER TABLE prefix_choice DROP `answer1`;');
101 modify_database('','ALTER TABLE prefix_choice DROP `answer2`;');
102 modify_database('','ALTER TABLE prefix_choice DROP `answer3`;');
103 modify_database('','ALTER TABLE prefix_choice DROP `answer4`;');
104 modify_database('','ALTER TABLE prefix_choice DROP `answer5`;');
105 modify_database('','ALTER TABLE prefix_choice DROP `answer6`;');
108 notify('SERIOUS PROBLEM OCCURRED WHILE UPGRADING A TABLE - you may have to manually upgrade your tables ... see mod/choice/db/mysql.php');
113 if ($oldversion < 2005041100) { // replace wiki-like with markdown
114 include_once( "$CFG->dirroot/lib/wiki_to_markdown.php" );
115 $wtm = new WikiToMarkdown();
116 $wtm->update( 'choice','text','format' );
118 if ($oldversion < 2005041500) { //new limit feature
119 table_column('choice', '', 'limitanswers', 'TINYINT', '2', 'unsigned', 0, 'not null', 'showunanswered');
120 table_column('choice_options', '', 'maxanswers', 'INTEGER', '10', 'unsigned', 0, 'null', 'text');