MDL-10107 Fixed the definition of message providers ... it now works through files...
[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,
b1f93b15 18// using the methods of database_manager class
c70ad9f7 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');
69b80cc2 34 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null, null, null);
c70ad9f7 35 $table->addField($field);
36
a8cb94f6 37 $field = new xmldb_field('feedback');
69b80cc2 38 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
c70ad9f7 39 $table->addField($field);
40
a8cb94f6 41 $field = new xmldb_field('userid');
69b80cc2 42 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
c70ad9f7 43 $table->addField($field);
44
a8cb94f6 45 $field = new xmldb_field('guestid');
69b80cc2 46 $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, null, false, null, null, '', null);
c70ad9f7 47 $table->addField($field);
48
a8cb94f6 49 $field = new xmldb_field('timemodified');
69b80cc2 50 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
c70ad9f7 51 $table->addField($field);
52
a8cb94f6 53 $key = new xmldb_key('PRIMARY');
69b80cc2 54 $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'));
c70ad9f7 55 $table->addKey($key);
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');
69b80cc2 68 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null, null, null);
c70ad9f7 69 $table->addField($field);
70
a8cb94f6 71 $field = new xmldb_field('course_id');
69b80cc2 72 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
c70ad9f7 73 $table->addField($field);
74
a8cb94f6 75 $field = new xmldb_field('item');
69b80cc2 76 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
c70ad9f7 77 $table->addField($field);
78
a8cb94f6 79 $field = new xmldb_field('completed');
69b80cc2 80 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
c70ad9f7 81 $table->addField($field);
82
a8cb94f6 83 $field = new xmldb_field('tmp_completed');
69b80cc2 84 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
c70ad9f7 85 $table->addField($field);
86
a8cb94f6 87 $field = new xmldb_field('value');
69b80cc2 88 $field->set_attributes(XMLDB_TYPE_TEXT, null, null, null, false, null, null, '', null);
c70ad9f7 89 $table->addField($field);
90
a8cb94f6 91 $key = new xmldb_key('PRIMARY');
69b80cc2 92 $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'));
c70ad9f7 93 $table->addKey($key);
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 ////////////////////////////////////////////////////////////
04264aed 101 upgrade_mod_savepoint($result, 2007012310, 'feedback');
c70ad9f7 102 }
103
104 if ($result && $oldversion < 2007050504) {
105
106 /// Define field random_response to be added to feedback_completed
a8cb94f6 107 $table = new xmldb_table('feedback_completed');
69b80cc2 108 $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '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');
69b80cc2 114 $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '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');
69b80cc2 120 $field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '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');
69b80cc2 126 $field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
c70ad9f7 127 /// Launch add field2
eee5d9bb 128 $dbman->add_field($table, $field);
c70ad9f7 129
130 ////////////////////////////////////////////////////////////
04264aed 131 upgrade_mod_savepoint($result, 2007050504, 'feedback');
c70ad9f7 132 }
133
134 if ($result && $oldversion < 2007102600) {
135 // public is a reserved word on Oracle
136
a8cb94f6 137 $table = new xmldb_table('feedback_template');
69b80cc2 138 $field = new xmldb_field('ispublic', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
f33e1ed4 139 if (!$dbman->field_exists($table, $field)) {
eee5d9bb 140 $dbman->add_field($table, $field);
c70ad9f7 141 }
04264aed 142 upgrade_mod_savepoint($result, 2007102600, 'feedback');
c70ad9f7 143 }
144
6ee09cfe 145 if ($result && $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) {
f33e1ed4 149 $result = $result && $DB->execute($update_sql.$fb->id);
6ee09cfe 150 }
151 }
04264aed 152 upgrade_mod_savepoint($result, 2008042400, 'feedback');
6ee09cfe 153 }
154
155 if ($result && $oldversion < 2008042401) { //New version in version.php
f33e1ed4 156 if ($result) {
157 $concat_radio = $DB->sql_concat("'r>>>>>'",'presentation');
bfc59a67 158 $concat_check = $DB->sql_concat("'c>>>>>'",'presentation');
159 $concat_dropdown = $DB->sql_concat("'d>>>>>'",'presentation');
64da83c6 160
f33e1ed4 161 $update_sql1 = "UPDATE {feedback_item} SET presentation = ".$concat_radio." WHERE typ IN('radio','radiorated')";
162 $update_sql2 = "UPDATE {feedback_item} SET presentation = ".$concat_dropdown." WHERE typ IN('dropdown','dropdownrated')";
163 $update_sql3 = "UPDATE {feedback_item} SET presentation = ".$concat_check." WHERE typ = 'check'";
64da83c6 164
f33e1ed4 165 $result = $result && $DB->execute($update_sql1);
166 $result = $result && $DB->execute($update_sql2);
8b54b5cd 167 $result = $result && $DB->execute($update_sql3);
6ee09cfe 168 }
f33e1ed4 169 if ($result) {
170 $update_sql1 = "UPDATE {feedback_item} SET typ = 'multichoice' WHERE typ IN('radio','check','dropdown')";
171 $update_sql2 = "UPDATE {feedback_item} SET typ = 'multichoicerated' WHERE typ IN('radiorated','dropdownrated')";
172 $result = $result && $DB->execute($update_sql1);
173 $result = $result && $DB->execute($update_sql2);
6ee09cfe 174 }
04264aed 175 upgrade_mod_savepoint($result, 2008042401, 'feedback');
6ee09cfe 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);
04264aed 203
204 upgrade_mod_savepoint($result, 2008042801, 'feedback');
a78b88e7 205 }
c70ad9f7 206
efc59167 207 if ($result && $oldversion < 2008042900) {
208 /// Define field autonumbering to be added to feedback
a8cb94f6 209 $table = new xmldb_table('feedback');
69b80cc2 210 $field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'multiple_submit');
efc59167 211 /// Launch add field2
eee5d9bb 212 $dbman->add_field($table, $field);
04264aed 213
214 upgrade_mod_savepoint($result, 2008042900, 'feedback');
efc59167 215 }
c184660d 216
217 if ($result && $oldversion < 2008050104) {
218 /// Define field site_after_submit to be added to feedback
a8cb94f6 219 $table = new xmldb_table('feedback');
69b80cc2 220 $field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255', null, null, false, null, null, '', 'autonumbering');
c184660d 221 /// Launch add field2
eee5d9bb 222 $dbman->add_field($table, $field);
04264aed 223
224 upgrade_mod_savepoint($result, 2008050104, 'feedback');
c184660d 225 }
239ba4ee 226
227 if ($result && $oldversion < 2008050105) {
228 //field count is not more needed
a8cb94f6 229 $table = new xmldb_table('feedback_tracking');
230 $field = new xmldb_field('count');
eee5d9bb 231 $dbman->drop_field($table, $field);
04264aed 232
233 upgrade_mod_savepoint($result, 2008050105, 'feedback');
239ba4ee 234 }
3b120e46 235
c70ad9f7 236 return $result;
237}
238
239?>