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 < 2003010100) {
16 execute_sql(" ALTER TABLE `choice` ADD `format` INTEGER DEFAULT '0' NOT NULL AFTER `text` ");
17 execute_sql(" ALTER TABLE `choice` ADD `publish` INTEGER DEFAULT '0' NOT NULL AFTER `answer6` ");
19 if ($oldversion < 2004010100) {
20 table_column("choice", "", "showunanswered", "integer", "4", "unsigned", "0", "", "publish");
22 if ($oldversion < 2004021700) {
23 modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('choice', 'choose', 'choice', 'name');");
24 modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('choice', 'choose again', 'choice', 'name');");
26 if ($oldversion < 2004070100) {
27 table_column("choice", "", "timeclose", "integer", "10", "unsigned", "0", "", "showunanswered");
28 table_column("choice", "", "timeopen", "integer", "10", "unsigned", "0", "", "showunanswered");
30 if ($oldversion < 2004070101) {
31 table_column("choice", "", "release", "integer", "2", "unsigned", "0", "", "publish");
32 table_column("choice", "", "allowupdate", "integer", "2", "unsigned", "0", "", "release");
34 if ($oldversion < 2004070102) {
35 modify_database("", "UPDATE prefix_choice SET allowupdate = '1' WHERE publish = 0;");
36 modify_database("", "UPDATE prefix_choice SET release = '1' WHERE publish > 0;");
37 modify_database("", "UPDATE prefix_choice SET publish = publish - 1 WHERE publish > 0;");
40 if ($oldversion < 2004111200) { // drop first to avoid conflicts when upgrading from 1.4+
41 execute_sql("DROP INDEX {$CFG->prefix}choice_course_idx;",false);
42 execute_sql("DROP INDEX {$CFG->prefix}choice_answers_choice_idx;",false);
43 execute_sql("DROP INDEX {$CFG->prefix}choice_answers_userid_idx;",false);
45 modify_database('','CREATE INDEX prefix_choice_course_idx ON prefix_choice (course);');
46 modify_database('','CREATE INDEX prefix_choice_answers_choice_idx ON prefix_choice_answers (choice);');
47 modify_database('','CREATE INDEX prefix_choice_answers_userid_idx ON prefix_choice_answers (userid);');
49 if ($oldversion < 2005033000){
50 if (execute_sql("CREATE TABLE {$CFG->prefix}choice_options (id SERIAL PRIMARY KEY, choiceid integer NOT NULL default '0', text TEXT, timemodified integer NOT NULL default '0');") ) {
51 execute_sql("CREATE INDEX {$CFG->prefix}choice_options_choice_idx ON {$CFG->prefix}choice_options (choiceid);");
53 table_column('choice_answers', 'choice', 'choiceid', 'integer', '10', 'unsigned', 0, 'not null');
54 table_column('choice_answers', 'answer', 'optionid', 'integer', '10', 'unsigned', 0, 'not null');
55 table_column('choice', '', 'display', 'integer', '4', 'unsigned', 0, 'not null', 'release');
57 // move old answers from choice to choice_options
58 if ($choices = get_records('choice')) {
59 foreach ($choices as $choice) {
60 for ($i=1; $i<=6; $i++
) { // We used to have six columns
61 $option = new stdClass
;
62 $option->text
= addslashes($choice->{'answer'.$i});
63 if ($option->text
) { /// Don't bother with blank options
64 $option->choiceid
= $choice->id
;
65 $option->timemodified
= $choice->timemodified
;
66 if ($option->id
= insert_record('choice_options', $option)) {
67 /// Update all the user answers to fit the new value
68 execute_sql("UPDATE {$CFG->prefix}choice_answers
69 SET optionid={$option->id}
70 WHERE choiceid={$choice->id}
79 modify_database('','ALTER TABLE prefix_choice DROP answer1;');
80 modify_database('','ALTER TABLE prefix_choice DROP answer2;');
81 modify_database('','ALTER TABLE prefix_choice DROP answer3;');
82 modify_database('','ALTER TABLE prefix_choice DROP answer4;');
83 modify_database('','ALTER TABLE prefix_choice DROP answer5;');
84 modify_database('','ALTER TABLE prefix_choice DROP answer6;');
89 if ($oldversion < 2005041100) { // replace wiki-like with markdown
90 include_once( "$CFG->dirroot/lib/wiki_to_markdown.php" );
91 $wtm = new WikiToMarkdown();
92 $wtm->update( 'choice','text','format' );
94 if ($oldversion < 2005041500) { //new limit feature
95 table_column('choice', '', 'limitanswers', 'INTEGER', '2', 'unsigned', 0, 'not null', 'showunanswered');
96 table_column('choice_options', '', 'maxanswers', 'INTEGER', '10', 'unsigned', 0, 'null', 'text');
99 if ($oldversion < 2005041501) { // Mass cleanup of bad upgrade scripts
100 modify_database('','CREATE INDEX prefix_choice_answers_choice_idx ON prefix_choice_answers (choiceid)');
101 notify('The above error can be ignored if the index already exists, its possible that it was cleaned up already before running this upgrade');
102 modify_database('','ALTER TABLE prefix_choice ALTER display SET NOT NULL');
103 modify_database('','ALTER TABLE prefix_choice ALTER limitanswers SET NOT NULL');
104 modify_database('','ALTER TABLE prefix_choice_answers ALTER choiceid SET NOT NULL');
105 modify_database('','ALTER TABLE prefix_choice_answers ALTER optionid SET NOT NULL');
107 if ($oldversion < 2006020900) { //rename release column to showanswers - Release is now reserved word in mySql
108 table_column('choice', 'release', 'showresults', 'TINYINT', '2', 'unsigned', 0, 'not null');
111 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.