3 // THIS FILE IS DEPRECATED! PLEASE DO NOT MAKE CHANGES TO IT!
5 // IT IS USED ONLY FOR UPGRADES FROM BEFORE MOODLE 1.7, ALL
6 // LATER CHANGES SHOULD USE upgrade.php IN THIS DIRECTORY.
8 function choice_upgrade($oldversion) {
12 // This function does anything necessary to upgrade
13 // older versions to match current functionality
15 if ($oldversion < 2002090800) {
16 execute_sql(" ALTER TABLE `choice` CHANGE `answer1` `answer1` VARCHAR( 255 )");
17 execute_sql(" ALTER TABLE `choice` CHANGE `answer2` `answer2` VARCHAR( 255 )");
19 if ($oldversion < 2002102400) {
20 execute_sql(" ALTER TABLE `choice` ADD `answer3` varchar(255) NOT NULL AFTER `answer2`");
21 execute_sql(" ALTER TABLE `choice` ADD `answer4` varchar(255) NOT NULL AFTER `answer3`");
22 execute_sql(" ALTER TABLE `choice` ADD `answer5` varchar(255) NOT NULL AFTER `answer4`");
23 execute_sql(" ALTER TABLE `choice` ADD `answer6` varchar(255) NOT NULL AFTER `answer5`");
25 if ($oldversion < 2002122300) {
26 execute_sql("ALTER TABLE `choice_answers` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
28 if ($oldversion < 2003010100) {
29 execute_sql(" ALTER TABLE `choice` ADD `format` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `text` ");
30 execute_sql(" ALTER TABLE `choice` ADD `publish` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `answer6` ");
33 if ($oldversion < 2004010100) {
34 table_column("choice", "", "showunanswered", "integer", "4", "unsigned", "0", "", "publish");
36 if ($oldversion < 2004021700) {
37 modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('choice', 'choose', 'choice', 'name');");
38 modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('choice', 'choose again', 'choice', 'name');");
40 if ($oldversion < 2004070100) {
41 table_column("choice", "", "timeclose", "integer", "10", "unsigned", "0", "", "showunanswered");
42 table_column("choice", "", "timeopen", "integer", "10", "unsigned", "0", "", "showunanswered");
44 if ($oldversion < 2004070101) {
45 table_column("choice", "", "release", "integer", "2", "unsigned", "0", "", "publish");
46 table_column("choice", "", "allowupdate", "integer", "2", "unsigned", "0", "", "release");
48 if ($oldversion < 2004070102) {
49 modify_database("", "UPDATE prefix_choice SET allowupdate = '1' WHERE publish = 0;");
50 modify_database("", "UPDATE prefix_choice SET release = '1' WHERE publish > 0;");
51 modify_database("", "UPDATE prefix_choice SET publish = publish - 1 WHERE publish > 0;");
54 if ($oldversion < 2004111200){ // drop first to avoid conflicts when upgrading from 1.4+
55 execute_sql("ALTER TABLE {$CFG->prefix}choice DROP INDEX course;",false);
56 execute_sql("ALTER TABLE {$CFG->prefix}choice_answers DROP INDEX choice;",false);
57 execute_sql("ALTER TABLE {$CFG->prefix}choice_answers DROP INDEX userid;",false);
59 modify_database('','ALTER TABLE prefix_choice ADD INDEX course (course);');
60 modify_database('','ALTER TABLE prefix_choice_answers ADD INDEX choice (choice);');
61 modify_database('','ALTER TABLE prefix_choice_answers ADD INDEX userid (userid);');
64 if ($oldversion < 2005033001){
65 if (execute_sql("CREATE TABLE {$CFG->prefix}choice_options (
66 `id` int(10) unsigned NOT NULL auto_increment,
67 `choiceid` int(10) unsigned NOT NULL default '0',
69 `timemodified` int(10) NOT NULL default '0',
72 KEY choiceid (choiceid)
75 table_column('choice_answers', 'choice', 'choiceid', 'integer', '10', 'unsigned', 0, 'not null');
76 table_column('choice_answers', 'answer', 'optionid', 'integer', '10', 'unsigned', 0, 'not null');
78 table_column('choice', '', 'display', 'integer', '4', 'unsigned', 0, 'not null', 'release');
81 /// move old answers from choice to choice_options
83 if ($choices = get_records('choice')) {
84 foreach ($choices as $choice) {
85 for ($i=1; $i<=6; $i++
) { // We used to have six columns
86 $option = new stdClass
;
87 $option->text
= addslashes($choice->{'answer'.$i});
88 if ($option->text
) { /// Don't bother with blank options
89 $option->choiceid
= $choice->id
;
90 $option->timemodified
= $choice->timemodified
;
91 if ($option->id
= insert_record('choice_options', $option)) {
92 /// Update all the user answers to fit the new value
93 execute_sql("UPDATE {$CFG->prefix}choice_answers
94 SET optionid='$option->id'
95 WHERE choiceid='$choice->id'
105 modify_database('','ALTER TABLE prefix_choice DROP `answer1`;');
106 modify_database('','ALTER TABLE prefix_choice DROP `answer2`;');
107 modify_database('','ALTER TABLE prefix_choice DROP `answer3`;');
108 modify_database('','ALTER TABLE prefix_choice DROP `answer4`;');
109 modify_database('','ALTER TABLE prefix_choice DROP `answer5`;');
110 modify_database('','ALTER TABLE prefix_choice DROP `answer6`;');
113 notify('SERIOUS PROBLEM OCCURRED WHILE UPGRADING A TABLE - you may have to manually upgrade your tables ... see mod/choice/db/mysql.php');
118 if ($oldversion < 2005041100) { // replace wiki-like with markdown
119 include_once( "$CFG->dirroot/lib/wiki_to_markdown.php" );
120 $wtm = new WikiToMarkdown();
121 $wtm->update( 'choice','text','format' );
123 if ($oldversion < 2005041500) { //new limit feature
124 table_column('choice', '', 'limitanswers', 'TINYINT', '2', 'unsigned', 0, 'not null', 'showunanswered');
125 table_column('choice_options', '', 'maxanswers', 'INTEGER', '10', 'unsigned', 0, 'null', 'text');
127 if ($oldversion < 2006020900) { //rename release column to showanswers - Release is now reserved word in mySql
128 table_column('choice', '`release`', 'showresults', 'TINYINT', '2', 'unsigned', 0, 'not null');
131 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.