MDL-14823 - changed $feedbackid to $feedback->id in function feedback_set_events()
[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
22 global $CFG, $THEME, $db;
23
24 $result = true;
25
26 if ($result && $oldversion < 2007012310) {
27
28 //create a new table feedback_completedtmp and the field-definition
29 $table = new XMLDBTable('feedback_completedtmp');
30
31 $field = new XMLDBField('id');
32 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null, null, null);
33 $table->addField($field);
34
35 $field = new XMLDBField('feedback');
36 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
37 $table->addField($field);
38
39 $field = new XMLDBField('userid');
40 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
41 $table->addField($field);
42
43 $field = new XMLDBField('guestid');
44 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, false, null, null, '', null);
45 $table->addField($field);
46
47 $field = new XMLDBField('timemodified');
48 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
49 $table->addField($field);
50
51 $key = new XMLDBKey('PRIMARY');
52 $key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
53 $table->addKey($key);
54
55 $key = new XMLDBKey('feedback');
56 $key->setAttributes(XMLDB_KEY_FOREIGN, array('feedback'), 'feedback', 'id');
57 $table->addKey($key);
58
59 $result = $result && create_table($table);
60 ////////////////////////////////////////////////////////////
61 ////////////////////////////////////////////////////////////
62 //create a new table feedback_valuetmp and the field-definition
63 $table = new XMLDBTable('feedback_valuetmp');
64
65 $field = new XMLDBField('id');
66 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, true, null, null, null, null);
67 $table->addField($field);
68
69 $field = new XMLDBField('course_id');
70 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
71 $table->addField($field);
72
73 $field = new XMLDBField('item');
74 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
75 $table->addField($field);
76
77 $field = new XMLDBField('completed');
78 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
79 $table->addField($field);
80
81 $field = new XMLDBField('tmp_completed');
82 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
83 $table->addField($field);
84
85 $field = new XMLDBField('value');
86 $field->setAttributes(XMLDB_TYPE_TEXT, null, null, null, false, null, null, '', null);
87 $table->addField($field);
88
89 $key = new XMLDBKey('PRIMARY');
90 $key->setAttributes(XMLDB_KEY_PRIMARY, array('id'));
91 $table->addKey($key);
92
93 $key = new XMLDBKey('feedback');
94 $key->setAttributes(XMLDB_KEY_FOREIGN, array('item'), 'feedback_item', 'id');
95 $table->addKey($key);
96
97 $result = $result && create_table($table);
98 ////////////////////////////////////////////////////////////
99 }
100
101 if ($result && $oldversion < 2007050504) {
102
103 /// Define field random_response to be added to feedback_completed
104 $table = new XMLDBTable('feedback_completed');
105 $field = new XMLDBField('random_response');
106 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
107 /// Launch add field1
108 $result = $result && add_field($table, $field);
109
110 /// Define field anonymous_response to be added to feedback_completed
111 $table = new XMLDBTable('feedback_completed');
112 $field = new XMLDBField('anonymous_response');
113 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
114 /// Launch add field2
115 $result = $result && add_field($table, $field);
116
117 /// Define field random_response to be added to feedback_completed
118 $table = new XMLDBTable('feedback_completedtmp');
119 $field = new XMLDBField('random_response');
120 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '0', null);
121 /// Launch add field1
122 $result = $result && add_field($table, $field);
123
124 /// Define field anonymous_response to be added to feedback_completed
125 $table = new XMLDBTable('feedback_completedtmp');
126 $field = new XMLDBField('anonymous_response');
127 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, false, null, null, '1', null);
128 /// Launch add field2
129 $result = $result && add_field($table, $field);
130
131 ////////////////////////////////////////////////////////////
132 }
133
134 if ($result && $oldversion < 2007102600) {
135 // public is a reserved word on Oracle
136
137 $table = new XMLDBTable('feedback_template');
138 $field = new XMLDBField('ispublic');
139 if (!field_exists($table, $field)) {
140 $result = $result && table_column('feedback_template', 'public', 'ispublic', 'integer', 1);
141 }
142 }
143
6ee09cfe 144 if ($result && $oldversion < 2008042400) { //New version in version.php
145 if($all_nonanonymous_feedbacks = get_records('feedback', 'anonymous', 2)) {
146 $update_sql = 'UPDATE '.$CFG->prefix.'feedback_completed SET anonymous_response = 2 WHERE feedback = ';
147 foreach ($all_nonanonymous_feedbacks as $fb) {
148 $result = $result && execute_sql($update_sql.$fb->id);
149 }
150 }
151 }
152
153 if ($result && $oldversion < 2008042401) { //New version in version.php
154 if($result) {
64da83c6 155 $concat_radio = sql_concat("'r>>>>>'",'presentation');
156 $concat_check = sql_concat("'d>>>>>'",'presentation');
157 $concat_dropdown = sql_concat("'c>>>>>'",'presentation');
158
159 $update_sql1 = "UPDATE ".$CFG->prefix."feedback_item SET presentation = ".$concat_radio." WHERE typ IN('radio','radiorated')";
160 $update_sql2 = "UPDATE ".$CFG->prefix."feedback_item SET presentation = ".$concat_dropdown." WHERE typ IN('dropdown','dropdownrated')";
161 $update_sql3 = "UPDATE ".$CFG->prefix."feedback_item SET presentation = ".$concat_check." WHERE typ = 'check'";
162
6ee09cfe 163 $result = $result && execute_sql($update_sql1);
164 $result = $result && execute_sql($update_sql2);
165 $result = $result && execute_sql($update_sql3);
166 }
167 if($result) {
168 $update_sql1 = "UPDATE ".$CFG->prefix."feedback_item SET typ = 'multichoice' WHERE typ IN('radio','check','dropdown')";
169 $update_sql2 = "UPDATE ".$CFG->prefix."feedback_item SET typ = 'multichoicerated' WHERE typ IN('radiorated','dropdownrated')";
170 $result = $result && execute_sql($update_sql1);
171 $result = $result && execute_sql($update_sql2);
172 }
173 }
174
a78b88e7 175 if ($result && $oldversion < 2008042801) {
62a0ae10 176 $new_log_display = new object();
177 $new_log_display->module = 'feedback';
178 $new_log_display->action = 'startcomplete';
179 $new_log_display->mtable = 'feedback';
180 $new_log_display->field = 'name';
181 $result = $result && insert_record('log_display', $new_log_display);
182
183 $new_log_display = clone($new_log_display);
184 $new_log_display->action = 'submit';
185 $result = $result && insert_record('log_display', $new_log_display);
186
187 $new_log_display = clone($new_log_display);
188 $new_log_display->action = 'delete';
189 $result = $result && insert_record('log_display', $new_log_display);
190
191 $new_log_display = clone($new_log_display);
192 $new_log_display->action = 'view';
193 $result = $result && insert_record('log_display', $new_log_display);
194
195 $new_log_display = clone($new_log_display);
196 $new_log_display->action = 'view all';
197 $new_log_display->mtable = 'course';
198 $new_log_display->field = 'shortname';
199 $result = $result && insert_record('log_display', $new_log_display);
a78b88e7 200 }
c70ad9f7 201
efc59167 202 if ($result && $oldversion < 2008042900) {
203 /// Define field autonumbering to be added to feedback
204 $table = new XMLDBTable('feedback');
205 $field = new XMLDBField('autonumbering');
206 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'multiple_submit');
207 /// Launch add field2
208 $result = $result && add_field($table, $field);
209 }
c70ad9f7 210 return $result;
211}
212
213?>