MDL-23628 removed more log_display upgrade leftovers
[moodle.git] / mod / feedback / db / upgrade.php
CommitLineData
1adbd2c3 1<?php
c70ad9f7 2
9b7d912b 3// This file keeps track of upgrades to
c70ad9f7 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
2e0406a5 12// your older installation to the current version.
c70ad9f7 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,
b1f93b15 18// using the methods of database_manager class
775f811a 19//
20// Please do not forget to use upgrade_set_timeout()
21// before any action that may take longer time to finish.
c70ad9f7 22
775f811a 23function xmldb_feedback_upgrade($oldversion) {
24 global $CFG, $DB;
f33e1ed4 25
26 $dbman = $DB->get_manager();
c70ad9f7 27
a4cdd6d2 28 if ($oldversion < 2007012310) {
c70ad9f7 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');
2a88f626 34 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null);
c70ad9f7 35 $table->addField($field);
9b7d912b 36
a8cb94f6 37 $field = new xmldb_field('feedback');
2a88f626 38 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
c70ad9f7 39 $table->addField($field);
9b7d912b 40
a8cb94f6 41 $field = new xmldb_field('userid');
2a88f626 42 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
c70ad9f7 43 $table->addField($field);
44
a8cb94f6 45 $field = new xmldb_field('guestid');
2a88f626 46 $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, null, false, '', null);
c70ad9f7 47 $table->addField($field);
48
a8cb94f6 49 $field = new xmldb_field('timemodified');
2a88f626 50 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
c70ad9f7 51 $table->addField($field);
9b7d912b 52
a8cb94f6 53 $key = new xmldb_key('PRIMARY');
69b80cc2 54 $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'));
c70ad9f7 55 $table->addKey($key);
9b7d912b 56
a8cb94f6 57 $key = new xmldb_key('feedback');
69b80cc2 58 $key->set_attributes(XMLDB_KEY_FOREIGN, array('feedback'), 'feedback', 'id');
c70ad9f7 59 $table->addKey($key);
60
eee5d9bb 61 $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');
2a88f626 68 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null);
c70ad9f7 69 $table->addField($field);
9b7d912b 70
a8cb94f6 71 $field = new xmldb_field('course_id');
2a88f626 72 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
c70ad9f7 73 $table->addField($field);
9b7d912b 74
a8cb94f6 75 $field = new xmldb_field('item');
2a88f626 76 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
c70ad9f7 77 $table->addField($field);
9b7d912b 78
a8cb94f6 79 $field = new xmldb_field('completed');
2a88f626 80 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
c70ad9f7 81 $table->addField($field);
9b7d912b 82
a8cb94f6 83 $field = new xmldb_field('tmp_completed');
2a88f626 84 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
c70ad9f7 85 $table->addField($field);
86
a8cb94f6 87 $field = new xmldb_field('value');
2a88f626 88 $field->set_attributes(XMLDB_TYPE_TEXT, null, null, null, false, '', null);
c70ad9f7 89 $table->addField($field);
9b7d912b 90
a8cb94f6 91 $key = new xmldb_key('PRIMARY');
69b80cc2 92 $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'));
c70ad9f7 93 $table->addKey($key);
9b7d912b 94
a8cb94f6 95 $key = new xmldb_key('feedback');
69b80cc2 96 $key->set_attributes(XMLDB_KEY_FOREIGN, array('item'), 'feedback_item', 'id');
c70ad9f7 97 $table->addKey($key);
98
eee5d9bb 99 $dbman->create_table($table);
c70ad9f7 100 ////////////////////////////////////////////////////////////
a4cdd6d2 101 upgrade_mod_savepoint(true, 2007012310, 'feedback');
c70ad9f7 102 }
103
a4cdd6d2 104 if ($oldversion < 2007050504) {
c70ad9f7 105
106 /// Define field random_response to be added to feedback_completed
a8cb94f6 107 $table = new xmldb_table('feedback_completed');
2a88f626 108 $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
c70ad9f7 109 /// Launch add field1
eee5d9bb 110 $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');
2a88f626 114 $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
c70ad9f7 115 /// Launch add field2
eee5d9bb 116 $dbman->add_field($table, $field);
c70ad9f7 117
118 /// Define field random_response to be added to feedback_completed
a8cb94f6 119 $table = new xmldb_table('feedback_completedtmp');
2a88f626 120 $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
c70ad9f7 121 /// Launch add field1
eee5d9bb 122 $dbman->add_field($table, $field);
c70ad9f7 123
124 /// Define field anonymous_response to be added to feedback_completed
a8cb94f6 125 $table = new xmldb_table('feedback_completedtmp');
2a88f626 126 $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
c70ad9f7 127 /// Launch add field2
eee5d9bb 128 $dbman->add_field($table, $field);
c70ad9f7 129
130 ////////////////////////////////////////////////////////////
a4cdd6d2 131 upgrade_mod_savepoint(true, 2007050504, 'feedback');
c70ad9f7 132 }
133
a4cdd6d2 134 if ($oldversion < 2007102600) {
c70ad9f7 135 // public is a reserved word on Oracle
136
a8cb94f6 137 $table = new xmldb_table('feedback_template');
2a88f626 138 $field = new xmldb_field('ispublic', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
f33e1ed4 139 if (!$dbman->field_exists($table, $field)) {
eee5d9bb 140 $dbman->add_field($table, $field);
c70ad9f7 141 }
a4cdd6d2 142 upgrade_mod_savepoint(true, 2007102600, 'feedback');
c70ad9f7 143 }
144
a4cdd6d2 145 if ($oldversion < 2008042400) { //New version in version.php
f33e1ed4 146 if ($all_nonanonymous_feedbacks = $DB->get_records('feedback', 'anonymous', 2)) {
147 $update_sql = 'UPDATE {feedback_completed} SET anonymous_response = 2 WHERE feedback = ';
6ee09cfe 148 foreach ($all_nonanonymous_feedbacks as $fb) {
a4cdd6d2 149 $DB->execute($update_sql.$fb->id);
6ee09cfe 150 }
151 }
a4cdd6d2 152 upgrade_mod_savepoint(true, 2008042400, 'feedback');
6ee09cfe 153 }
154
a4cdd6d2
PS
155 if ($oldversion < 2008042401) { //New version in version.php
156 $concat_radio = $DB->sql_concat("'r>>>>>'",'presentation');
157 $concat_check = $DB->sql_concat("'c>>>>>'",'presentation');
158 $concat_dropdown = $DB->sql_concat("'d>>>>>'",'presentation');
9b7d912b 159
a4cdd6d2
PS
160 $update_sql1 = "UPDATE {feedback_item} SET presentation = ".$concat_radio." WHERE typ IN('radio','radiorated')";
161 $update_sql2 = "UPDATE {feedback_item} SET presentation = ".$concat_dropdown." WHERE typ IN('dropdown','dropdownrated')";
162 $update_sql3 = "UPDATE {feedback_item} SET presentation = ".$concat_check." WHERE typ = 'check'";
9b7d912b 163
a4cdd6d2
PS
164 $DB->execute($update_sql1);
165 $DB->execute($update_sql2);
166 $DB->execute($update_sql3);
167
168 $update_sql1 = "UPDATE {feedback_item} SET typ = 'multichoice' WHERE typ IN('radio','check','dropdown')";
169 $update_sql2 = "UPDATE {feedback_item} SET typ = 'multichoicerated' WHERE typ IN('radiorated','dropdownrated')";
170 $DB->execute($update_sql1);
171 $DB->execute($update_sql2);
172
173 upgrade_mod_savepoint(true, 2008042401, 'feedback');
6ee09cfe 174 }
175
a4cdd6d2 176 if ($oldversion < 2008042900) {
efc59167 177 /// Define field autonumbering to be added to feedback
a8cb94f6 178 $table = new xmldb_table('feedback');
2a88f626 179 $field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'multiple_submit');
efc59167 180 /// Launch add field2
eee5d9bb 181 $dbman->add_field($table, $field);
04264aed 182
a4cdd6d2 183 upgrade_mod_savepoint(true, 2008042900, 'feedback');
efc59167 184 }
c184660d 185
a4cdd6d2 186 if ($oldversion < 2008050104) {
c184660d 187 /// Define field site_after_submit to be added to feedback
a8cb94f6 188 $table = new xmldb_table('feedback');
2a88f626 189 $field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'autonumbering');
c184660d 190 /// Launch add field2
eee5d9bb 191 $dbman->add_field($table, $field);
04264aed 192
a4cdd6d2 193 upgrade_mod_savepoint(true, 2008050104, 'feedback');
c184660d 194 }
2b3d3353 195
a4cdd6d2 196 if ($oldversion < 2008050105) {
239ba4ee 197 //field count is not more needed
a8cb94f6 198 $table = new xmldb_table('feedback_tracking');
199 $field = new xmldb_field('count');
eee5d9bb 200 $dbman->drop_field($table, $field);
04264aed 201
a4cdd6d2 202 upgrade_mod_savepoint(true, 2008050105, 'feedback');
239ba4ee 203 }
2b3d3353 204
a4cdd6d2 205 if ($oldversion < 2008073002) {
2b3d3353 206 $update_sql = "UPDATE {feedback_item} SET presentation = '-|-' WHERE " . $DB->sql_compare_text('presentation') . " = '0|0' AND typ = 'numeric'";
a4cdd6d2 207 $DB->execute($update_sql);
2b3d3353 208
a4cdd6d2 209 upgrade_mod_savepoint(true, 2008073002, 'feedback');
b7a47958 210 }
2b3d3353 211
a4cdd6d2 212 if ($oldversion < 2009031301) {
b7a47958 213 /// Define field label to be added to feedback_item
214 $table = new xmldb_table('feedback_item');
2a88f626 215 $field = new xmldb_field('label', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'name');
b7a47958 216 /// Launch add field2
217 $dbman->add_field($table, $field);
218
a4cdd6d2 219 upgrade_mod_savepoint(true, 2009031301, 'feedback');
226ef9c0 220 }
63b02567 221
a4cdd6d2 222 if ($oldversion < 2009042000) {
63b02567 223
224 /// Rename field summary on table feedback to intro
225 $table = new xmldb_table('feedback');
2a88f626 226 $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'name');
63b02567 227
228 /// Launch rename field summary
229 $dbman->rename_field($table, $field, 'intro');
230
231 /// feedback savepoint reached
a4cdd6d2 232 upgrade_mod_savepoint(true, 2009042000, 'feedback');
63b02567 233 }
234
a4cdd6d2 235 if ($oldversion < 2009042001) {
63b02567 236
237 /// Define field introformat to be added to feedback
238 $table = new xmldb_table('feedback');
2a88f626 239 $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
63b02567 240
d0bcf735 241 /// Launch add field introformat
242 $dbman->add_field($table, $field);
63b02567 243
244 /// feedback savepoint reached
a4cdd6d2 245 upgrade_mod_savepoint(true, 2009042001, 'feedback');
63b02567 246 }
247
a4cdd6d2 248 if ($oldversion < 2009112000) {
9f42276c
SH
249 /// Define field page_after_submitformat to be added to feedback
250 $table = new xmldb_table('feedback');
251 $field = new xmldb_field('page_after_submitformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'page_after_submit');
252
253 if (!$dbman->field_exists($table, $field)) {
254 // Launch add field page_after_submitformat
255 $dbman->add_field($table, $field);
256 }
257
258 // feedback savepoint reached
a4cdd6d2 259 upgrade_mod_savepoint(true, 2009112000, 'feedback');
9f42276c
SH
260 }
261
a4cdd6d2 262 if ($oldversion < 2010051101) {
79473294
AG
263 /// Define field options to be added to feedback_item
264 $table = new xmldb_table('feedback_item');
265 $field = new xmldb_field('options', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'required');
266 /// Launch add field
267 $dbman->add_field($table, $field);
268
a4cdd6d2 269 upgrade_mod_savepoint(true, 2010051101, 'feedback');
79473294
AG
270 }
271
a4cdd6d2 272 if ($oldversion < 2010051600) {
73043833
AG
273 /// Define field options to be added to feedback_item
274 $table = new xmldb_table('feedback_item');
275 $field = new xmldb_field('dependitem', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'required');
276 /// Launch add field
277 $dbman->add_field($table, $field);
278
a4cdd6d2 279 upgrade_mod_savepoint(true, 2010051600, 'feedback');
73043833
AG
280 }
281
a4cdd6d2 282 if ($oldversion < 2010051601) {
73043833
AG
283 /// Define field options to be added to feedback_item
284 $table = new xmldb_table('feedback_item');
285 $field = new xmldb_field('dependvalue', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'dependitem');
286 /// Launch add field
287 $dbman->add_field($table, $field);
288
a4cdd6d2 289 upgrade_mod_savepoint(true, 2010051601, 'feedback');
73043833
AG
290 }
291
a4cdd6d2 292 return true;
c70ad9f7 293}
294
1adbd2c3 295