Incorrect variable name used for parameter.
[moodle-linuxchix.git] / mod / choice / db / postgres7.php
blob07952bab9cba422db7433369c6290fd259fa9902
1 <?php // $Id$
3 function choice_upgrade($oldversion) {
5 global $CFG;
7 // This function does anything necessary to upgrade
8 // older versions to match current functionality
10 if ($oldversion < 2003010100) {
11 execute_sql(" ALTER TABLE `choice` ADD `format` INTEGER DEFAULT '0' NOT NULL AFTER `text` ");
12 execute_sql(" ALTER TABLE `choice` ADD `publish` INTEGER DEFAULT '0' NOT NULL AFTER `answer6` ");
14 if ($oldversion < 2004010100) {
15 table_column("choice", "", "showunanswered", "integer", "4", "unsigned", "0", "", "publish");
17 if ($oldversion < 2004021700) {
18 modify_database("", "INSERT INTO prefix_log_display VALUES ('choice', 'choose', 'choice', 'name');");
19 modify_database("", "INSERT INTO prefix_log_display VALUES ('choice', 'choose again', 'choice', 'name');");
21 if ($oldversion < 2004070100) {
22 table_column("choice", "", "timeclose", "integer", "10", "unsigned", "0", "", "showunanswered");
23 table_column("choice", "", "timeopen", "integer", "10", "unsigned", "0", "", "showunanswered");
25 if ($oldversion < 2004070101) {
26 table_column("choice", "", "release", "integer", "2", "unsigned", "0", "", "publish");
27 table_column("choice", "", "allowupdate", "integer", "2", "unsigned", "0", "", "release");
29 if ($oldversion < 2004070102) {
30 modify_database("", "UPDATE prefix_choice SET allowupdate = '1' WHERE publish = 0;");
31 modify_database("", "UPDATE prefix_choice SET release = '1' WHERE publish > 0;");
32 modify_database("", "UPDATE prefix_choice SET publish = publish - 1 WHERE publish > 0;");
35 if ($oldversion < 2004111200) { // drop first to avoid conflicts when upgrading from 1.4+
36 execute_sql("DROP INDEX {$CFG->prefix}choice_course_idx;",false);
37 execute_sql("DROP INDEX {$CFG->prefix}choice_answers_choice_idx;",false);
38 execute_sql("DROP INDEX {$CFG->prefix}choice_answers_userid_idx;",false);
40 modify_database('','CREATE INDEX prefix_choice_course_idx ON prefix_choice (course);');
41 modify_database('','CREATE INDEX prefix_choice_answers_choice_idx ON prefix_choice_answers (choice);');
42 modify_database('','CREATE INDEX prefix_choice_answers_userid_idx ON prefix_choice_answers (userid);');
44 if ($oldversion < 2005033000){
45 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');") ) {
46 execute_sql("CREATE INDEX {$CFG->prefix}choice_options_choice_idx ON {$CFG->prefix}choice_options (choiceid);");
48 table_column('choice_answers', 'choice', 'choiceid', 'integer', '10', 'unsigned', 0, 'not null');
49 table_column('choice_answers', 'answer', 'optionid', 'integer', '10', 'unsigned', 0, 'not null');
50 table_column('choice', '', 'display', 'integer', '4', 'unsigned', 0, 'not null', 'release');
52 // move old answers from choice to choice_options
53 if ($choices = get_records('choice')) {
54 foreach ($choices as $choice) {
55 for ($i=1; $i<=6; $i++) { // We used to have six columns
56 $option = new stdClass;
57 $option->text = addslashes($choice->{'answer'.$i});
58 if ($option->text) { /// Don't bother with blank options
59 $option->choiceid = $choice->id;
60 $option->timemodified = $choice->timemodified;
61 if ($option->id = insert_record('choice_options', $option)) {
62 /// Update all the user answers to fit the new value
63 execute_sql("UPDATE {$CFG->prefix}choice_answers
64 SET optionid={$option->id}
65 WHERE choiceid={$choice->id}
66 AND optionid={$i}");
73 // drop old fields
74 modify_database('','ALTER TABLE prefix_choice DROP answer1;');
75 modify_database('','ALTER TABLE prefix_choice DROP answer2;');
76 modify_database('','ALTER TABLE prefix_choice DROP answer3;');
77 modify_database('','ALTER TABLE prefix_choice DROP answer4;');
78 modify_database('','ALTER TABLE prefix_choice DROP answer5;');
79 modify_database('','ALTER TABLE prefix_choice DROP answer6;');
84 if ($oldversion < 2005041100) { // replace wiki-like with markdown
85 include_once( "$CFG->dirroot/lib/wiki_to_markdown.php" );
86 $wtm = new WikiToMarkdown();
87 $wtm->update( 'choice','text','format' );
89 if ($oldversion < 2005041500) { //new limit feature
90 table_column('choice', '', 'limitanswers', 'INTEGER', '2', 'unsigned', 0, 'not null', 'showunanswered');
91 table_column('choice_options', '', 'maxanswers', 'INTEGER', '10', 'unsigned', 0, 'null', 'text');
93 return true;