Fix typo.
[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
31 $table = new XMLDBTable('feedback_completedtmp');
32
33 $field = new XMLDBField('id');
34 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null, null, null);
35 $table->addField($field);
36
37 $field = new XMLDBField('feedback');
38 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
39 $table->addField($field);
40
41 $field = new XMLDBField('userid');
42 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
43 $table->addField($field);
44
45 $field = new XMLDBField('guestid');
46 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, false, null, null, '', null);
47 $table->addField($field);
48
49 $field = new XMLDBField('timemodified');
50 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
51 $table->addField($field);
52
53 $key = new XMLDBKey('PRIMARY');
54 $key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
55 $table->addKey($key);
56
57 $key = new XMLDBKey('feedback');
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
65 $table = new XMLDBTable('feedback_valuetmp');
66
67 $field = new XMLDBField('id');
68 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null, null, null);
69 $table->addField($field);
70
71 $field = new XMLDBField('course_id');
72 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
73 $table->addField($field);
74
75 $field = new XMLDBField('item');
76 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
77 $table->addField($field);
78
79 $field = new XMLDBField('completed');
80 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
81 $table->addField($field);
82
83 $field = new XMLDBField('tmp_completed');
84 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
85 $table->addField($field);
86
87 $field = new XMLDBField('value');
88 $field->setAttributes(XMLDB_TYPE_TEXT, null, null, null, false, null, null, '', null);
89 $table->addField($field);
90
91 $key = new XMLDBKey('PRIMARY');
92 $key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
93 $table->addKey($key);
94
95 $key = new XMLDBKey('feedback');
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
106 $table = new XMLDBTable('feedback_completed');
107 $field = new XMLDBField('random_response');
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
113 $table = new XMLDBTable('feedback_completed');
114 $field = new XMLDBField('anonymous_response');
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
120 $table = new XMLDBTable('feedback_completedtmp');
121 $field = new XMLDBField('random_response');
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
127 $table = new XMLDBTable('feedback_completedtmp');
128 $field = new XMLDBField('anonymous_response');
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
139 $table = new XMLDBTable('feedback_template');
140 $field = new XMLDBField('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
207 $table = new XMLDBTable('feedback');
208 $field = new XMLDBField('autonumbering');
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
216 $table = new XMLDBTable('feedback');
217 $field = new XMLDBField('site_after_submit');
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 }
c70ad9f7 222 return $result;
223}
224
225?>