Fixed a minor mistake for xmldb instruction.
[moodle.git] / mod / feedback / db / upgrade.php
CommitLineData
c70ad9f7 1<?php //$Id$
2
3// This file keeps track of upgrades to
4// the feedback module
5//
6// Sometimes, changes between versions involve
7// alterations to database structures and other
8// major things that may break installations.
9//
10// The upgrade function in this file will attempt
11// to perform all the necessary actions to upgrade
12// your older installtion to the current version.
13//
14// If there's something it cannot do itself, it
15// will tell you what you need to do.
16//
17// The commands in here will all be database-neutral,
18// using the functions defined in lib/ddllib.php
19
20function xmldb_feedback_upgrade($oldversion=0) {
21
f33e1ed4 22 global $CFG, $THEME, $DB;
23
24 $dbman = $DB->get_manager();
c70ad9f7 25
26 $result = true;
27
28 if ($result && $oldversion < 2007012310) {
29
30 //create a new table feedback_completedtmp and the field-definition
a8cb94f6 31 $table = new xmldb_table('feedback_completedtmp');
c70ad9f7 32
a8cb94f6 33 $field = new xmldb_field('id');
c70ad9f7 34 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null, null, null);
35 $table->addField($field);
36
a8cb94f6 37 $field = new xmldb_field('feedback');
c70ad9f7 38 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
39 $table->addField($field);
40
a8cb94f6 41 $field = new xmldb_field('userid');
c70ad9f7 42 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
43 $table->addField($field);
44
a8cb94f6 45 $field = new xmldb_field('guestid');
c70ad9f7 46 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, false, null, null, '', null);
47 $table->addField($field);
48
a8cb94f6 49 $field = new xmldb_field('timemodified');
c70ad9f7 50 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
51 $table->addField($field);
52
a8cb94f6 53 $key = new xmldb_key('PRIMARY');
c70ad9f7 54 $key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
55 $table->addKey($key);
56
a8cb94f6 57 $key = new xmldb_key('feedback');
c70ad9f7 58 $key->setAttributes(XMLDB_KEY_FOREIGN, array('feedback'), 'feedback', 'id');
59 $table->addKey($key);
60
f33e1ed4 61 $result = $result && $dbman->create_table($table);
c70ad9f7 62 ////////////////////////////////////////////////////////////
63 ////////////////////////////////////////////////////////////
64 //create a new table feedback_valuetmp and the field-definition
a8cb94f6 65 $table = new xmldb_table('feedback_valuetmp');
c70ad9f7 66
a8cb94f6 67 $field = new xmldb_field('id');
c70ad9f7 68 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null, null, null);
69 $table->addField($field);
70
a8cb94f6 71 $field = new xmldb_field('course_id');
c70ad9f7 72 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
73 $table->addField($field);
74
a8cb94f6 75 $field = new xmldb_field('item');
c70ad9f7 76 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
77 $table->addField($field);
78
a8cb94f6 79 $field = new xmldb_field('completed');
c70ad9f7 80 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
81 $table->addField($field);
82
a8cb94f6 83 $field = new xmldb_field('tmp_completed');
c70ad9f7 84 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
85 $table->addField($field);
86
a8cb94f6 87 $field = new xmldb_field('value');
c70ad9f7 88 $field->setAttributes(XMLDB_TYPE_TEXT, null, null, null, false, null, null, '', null);
89 $table->addField($field);
90
a8cb94f6 91 $key = new xmldb_key('PRIMARY');
c70ad9f7 92 $key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
93 $table->addKey($key);
94
a8cb94f6 95 $key = new xmldb_key('feedback');
c70ad9f7 96 $key->setAttributes(XMLDB_KEY_FOREIGN, array('item'), 'feedback_item', 'id');
97 $table->addKey($key);
98
f33e1ed4 99 $result = $result && $dbman->create_table($table);
c70ad9f7 100 ////////////////////////////////////////////////////////////
101 }
102
103 if ($result && $oldversion < 2007050504) {
104
105 /// Define field random_response to be added to feedback_completed
a8cb94f6 106 $table = new xmldb_table('feedback_completed');
107 $field = new xmldb_field('random_response');
c70ad9f7 108 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
109 /// Launch add field1
f33e1ed4 110 $result = $result && $dbman->add_field($table, $field);
c70ad9f7 111
112 /// Define field anonymous_response to be added to feedback_completed
a8cb94f6 113 $table = new xmldb_table('feedback_completed');
114 $field = new xmldb_field('anonymous_response');
c70ad9f7 115 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
116 /// Launch add field2
f33e1ed4 117 $result = $result && $dbman->add_field($table, $field);
c70ad9f7 118
119 /// Define field random_response to be added to feedback_completed
a8cb94f6 120 $table = new xmldb_table('feedback_completedtmp');
121 $field = new xmldb_field('random_response');
c70ad9f7 122 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
123 /// Launch add field1
f33e1ed4 124 $result = $result && $dbman->add_field($table, $field);
c70ad9f7 125
126 /// Define field anonymous_response to be added to feedback_completed
a8cb94f6 127 $table = new xmldb_table('feedback_completedtmp');
128 $field = new xmldb_field('anonymous_response');
c70ad9f7 129 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
130 /// Launch add field2
f33e1ed4 131 $result = $result && $dbman->add_field($table, $field);
c70ad9f7 132
133 ////////////////////////////////////////////////////////////
134 }
135
136 if ($result && $oldversion < 2007102600) {
137 // public is a reserved word on Oracle
138
a8cb94f6 139 $table = new xmldb_table('feedback_template');
140 $field = new xmldb_field('ispublic');
f33e1ed4 141 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
142 if (!$dbman->field_exists($table, $field)) {
143 $result = $result && $dbman->add_field($table, $field);
c70ad9f7 144 }
145 }
146
6ee09cfe 147 if ($result && $oldversion < 2008042400) { //New version in version.php
f33e1ed4 148 if ($all_nonanonymous_feedbacks = $DB->get_records('feedback', 'anonymous', 2)) {
149 $update_sql = 'UPDATE {feedback_completed} SET anonymous_response = 2 WHERE feedback = ';
6ee09cfe 150 foreach ($all_nonanonymous_feedbacks as $fb) {
f33e1ed4 151 $result = $result && $DB->execute($update_sql.$fb->id);
6ee09cfe 152 }
153 }
154 }
155
156 if ($result && $oldversion < 2008042401) { //New version in version.php
f33e1ed4 157 if ($result) {
158 $concat_radio = $DB->sql_concat("'r>>>>>'",'presentation');
159 $concat_check = $DB->sql_concat("'d>>>>>'",'presentation');
160 $concat_dropdown = $DB->sql_concat("'c>>>>>'",'presentation');
64da83c6 161
f33e1ed4 162 $update_sql1 = "UPDATE {feedback_item} SET presentation = ".$concat_radio." WHERE typ IN('radio','radiorated')";
163 $update_sql2 = "UPDATE {feedback_item} SET presentation = ".$concat_dropdown." WHERE typ IN('dropdown','dropdownrated')";
164 $update_sql3 = "UPDATE {feedback_item} SET presentation = ".$concat_check." WHERE typ = 'check'";
64da83c6 165
f33e1ed4 166 $result = $result && $DB->execute($update_sql1);
167 $result = $result && $DB->execute($update_sql2);
168 $result = $result && $BB->execute($update_sql3);
6ee09cfe 169 }
f33e1ed4 170 if ($result) {
171 $update_sql1 = "UPDATE {feedback_item} SET typ = 'multichoice' WHERE typ IN('radio','check','dropdown')";
172 $update_sql2 = "UPDATE {feedback_item} SET typ = 'multichoicerated' WHERE typ IN('radiorated','dropdownrated')";
173 $result = $result && $DB->execute($update_sql1);
174 $result = $result && $DB->execute($update_sql2);
6ee09cfe 175 }
176 }
177
a78b88e7 178 if ($result && $oldversion < 2008042801) {
62a0ae10 179 $new_log_display = new object();
180 $new_log_display->module = 'feedback';
181 $new_log_display->action = 'startcomplete';
182 $new_log_display->mtable = 'feedback';
183 $new_log_display->field = 'name';
f33e1ed4 184 $result = $result && $DB->insert_record('log_display', $new_log_display);
62a0ae10 185
186 $new_log_display = clone($new_log_display);
187 $new_log_display->action = 'submit';
f33e1ed4 188 $result = $result && $DB->insert_record('log_display', $new_log_display);
62a0ae10 189
190 $new_log_display = clone($new_log_display);
191 $new_log_display->action = 'delete';
f33e1ed4 192 $result = $result && $DB->insert_record('log_display', $new_log_display);
62a0ae10 193
194 $new_log_display = clone($new_log_display);
195 $new_log_display->action = 'view';
f33e1ed4 196 $result = $result && $DB->insert_record('log_display', $new_log_display);
62a0ae10 197
198 $new_log_display = clone($new_log_display);
199 $new_log_display->action = 'view all';
200 $new_log_display->mtable = 'course';
201 $new_log_display->field = 'shortname';
f33e1ed4 202 $result = $result && $DB->insert_record('log_display', $new_log_display);
a78b88e7 203 }
c70ad9f7 204
efc59167 205 if ($result && $oldversion < 2008042900) {
206 /// Define field autonumbering to be added to feedback
a8cb94f6 207 $table = new xmldb_table('feedback');
208 $field = new xmldb_field('autonumbering');
efc59167 209 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'multiple_submit');
210 /// Launch add field2
f33e1ed4 211 $result = $result && $dbman->add_field($table, $field);
efc59167 212 }
c184660d 213
214 if ($result && $oldversion < 2008050104) {
215 /// Define field site_after_submit to be added to feedback
a8cb94f6 216 $table = new xmldb_table('feedback');
217 $field = new xmldb_field('site_after_submit');
c184660d 218 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, false, null, null, '', 'autonumbering');
219 /// Launch add field2
f33e1ed4 220 $result = $result && $dbman->add_field($table, $field);
c184660d 221 }
239ba4ee 222
223 if ($result && $oldversion < 2008050105) {
224 //field count is not more needed
a8cb94f6 225 $table = new xmldb_table('feedback_tracking');
226 $field = new xmldb_field('count');
239ba4ee 227 $result = $result && $dbman->drop_field($table, $field);
228 }
c70ad9f7 229 return $result;
230}
231
232?>