4e423cbf |
1 | <?PHP //$Id$ |
2 | |
3 | // This file keeps track of upgrades to Moodle. |
4 | // |
5 | // Sometimes, changes between versions involve |
6 | // alterations to database structures and other |
7 | // major things that may break installations. |
8 | // |
9 | // The upgrade function in this file will attempt |
10 | // to perform all the necessary actions to upgrade |
11 | // your older installtion to the current version. |
12 | // |
13 | // If there's something it cannot do itself, it |
14 | // will tell you what you need to do. |
15 | // |
16 | // The commands in here will all be database-neutral, |
b1f93b15 |
17 | // using the methods of database_manager class |
775f811a |
18 | // |
19 | // Please do not forget to use upgrade_set_timeout() |
20 | // before any action that may take longer time to finish. |
4e423cbf |
21 | |
775f811a |
22 | function xmldb_main_upgrade($oldversion) { |
f33e1ed4 |
23 | global $CFG, $THEME, $USER, $DB; |
4e423cbf |
24 | |
25 | $result = true; |
26 | |
46d318bc |
27 | $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes |
f33e1ed4 |
28 | |
1ea260d8 |
29 | //////////////////////////////////////// |
30 | ///upgrade supported only from 1.9.x /// |
31 | //////////////////////////////////////// |
da4aa3e4 |
32 | |
a1f27717 |
33 | if ($result && $oldversion < 2008030700) { |
775f811a |
34 | upgrade_set_timeout(60*20); // this may take a while |
a1f27717 |
35 | |
36 | /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters |
a8cb94f6 |
37 | $table = new xmldb_table('grade_letters'); |
69b80cc2 |
38 | $index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary')); |
a1f27717 |
39 | |
40 | /// Launch drop index contextid-lowerboundary |
eee5d9bb |
41 | $dbman->drop_index($table, $index); |
a1f27717 |
42 | |
a1f27717 |
43 | /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters |
a8cb94f6 |
44 | $table = new xmldb_table('grade_letters'); |
69b80cc2 |
45 | $index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter')); |
a1f27717 |
46 | |
47 | /// Launch add index contextid-lowerboundary-letter |
eee5d9bb |
48 | $dbman->add_index($table, $index); |
a1f27717 |
49 | |
50 | /// Main savepoint reached |
0f77b186 |
51 | upgrade_main_savepoint($result, 2008030700); |
52 | } |
a1f27717 |
53 | |
1ea260d8 |
54 | if ($result && $oldversion < 2008050100) { |
55 | // Update courses that used weekscss to weeks |
a8cb94f6 |
56 | $result = $DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss')); |
1ea260d8 |
57 | upgrade_main_savepoint($result, 2008050100); |
58 | } |
59 | |
0b51c247 |
60 | if ($result && $oldversion < 2008050200) { |
61 | // remove unused config options |
62 | unset_config('statsrolesupgraded'); |
63 | upgrade_main_savepoint($result, 2008050200); |
64 | } |
65 | |
994fbaab |
66 | if ($result && $oldversion < 2008050700) { |
775f811a |
67 | upgrade_set_timeout(60*20); // this may take a while |
68 | |
994fbaab |
69 | /// Fix minor problem caused by MDL-5482. |
70 | require_once($CFG->dirroot . '/question/upgrade.php'); |
71 | $result = $result && question_fix_random_question_parents(); |
72 | upgrade_main_savepoint($result, 2008050700); |
73 | } |
74 | |
ab37dc60 |
75 | if ($result && $oldversion < 2008051200) { |
76 | // if guest role used as default user role unset it and force admin to choose new setting |
77 | if (!empty($CFG->defaultuserroleid)) { |
910dd4dd |
78 | if ($role = $DB->get_record('role', array('id'=>$CFG->defaultuserroleid))) { |
ab37dc60 |
79 | if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) { |
80 | if (isset($guestroles[$role->id])) { |
81 | set_config('defaultuserroleid', null); |
82 | notify('Guest role removed from "Default role for all users" setting, please select another role.', 'notifysuccess'); |
83 | } |
84 | } |
85 | } else { |
86 | set_config('defaultuserroleid', null); |
87 | } |
88 | } |
89 | } |
90 | |
8b9cfac4 |
91 | if ($result && $oldversion < 2008051201) { |
92 | notify('Increasing size of user idnumber field, this may take a while...', 'notifysuccess'); |
775f811a |
93 | upgrade_set_timeout(60*20); // this may take a while |
8b9cfac4 |
94 | |
469dcbcc |
95 | /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859 |
96 | if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') { |
eee5d9bb |
97 | $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL"); |
469dcbcc |
98 | } |
99 | |
8b9cfac4 |
100 | /// Define index idnumber (not unique) to be dropped form user |
a8cb94f6 |
101 | $table = new xmldb_table('user'); |
69b80cc2 |
102 | $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber')); |
8b9cfac4 |
103 | |
104 | /// Launch drop index idnumber |
f33e1ed4 |
105 | if ($dbman->index_exists($table, $index)) { |
eee5d9bb |
106 | $dbman->drop_index($table, $index); |
8b9cfac4 |
107 | } |
108 | |
109 | /// Changing precision of field idnumber on table user to (255) |
a8cb94f6 |
110 | $table = new xmldb_table('user'); |
69b80cc2 |
111 | $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'password'); |
8b9cfac4 |
112 | |
113 | /// Launch change of precision for field idnumber |
eee5d9bb |
114 | $dbman->change_field_precision($table, $field); |
8b9cfac4 |
115 | |
116 | /// Launch add index idnumber again |
69b80cc2 |
117 | $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber')); |
eee5d9bb |
118 | $dbman->add_index($table, $index); |
8b9cfac4 |
119 | |
120 | /// Main savepoint reached |
121 | upgrade_main_savepoint($result, 2008051201); |
122 | } |
123 | |
7ade55ad |
124 | if ($result && $oldversion < 2008051202) { |
910dd4dd |
125 | $log_action = new object(); |
7ade55ad |
126 | $log_action->module = 'course'; |
127 | $log_action->action = 'unenrol'; |
128 | $log_action->mtable = 'course'; |
129 | $log_action->field = 'fullname'; |
910dd4dd |
130 | if (!$DB->record_exists('log_display', array('action'=>'unenrol', 'module'=>'course'))) { |
131 | $result = $result && $DB->insert_record('log_display', $log_action); |
7ade55ad |
132 | } |
133 | upgrade_main_savepoint($result, 2008051202); |
134 | } |
135 | |
fa162144 |
136 | if ($result && $oldversion < 2008051203) { |
137 | $table = new xmldb_table('mnet_enrol_course'); |
138 | $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', true, true, null, false, false, 0); |
eee5d9bb |
139 | $dbman->change_field_precision($table, $field); |
fa162144 |
140 | upgrade_main_savepoint($result, 2008051203); |
141 | } |
142 | |
38fb8190 |
143 | if ($result && $oldversion < 2008063001) { |
775f811a |
144 | upgrade_set_timeout(60*20); // this may take a while |
145 | |
38fb8190 |
146 | // table to be modified |
147 | $table = new xmldb_table('tag_instance'); |
148 | // add field |
149 | $field = new xmldb_field('tiuserid'); |
150 | if (!$dbman->field_exists($table, $field)) { |
151 | $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0, 'itemid'); |
152 | $dbman->add_field($table, $field); |
153 | } |
154 | // modify index |
155 | $index = new xmldb_index('itemtype-itemid-tagid'); |
156 | $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid')); |
157 | $dbman->drop_index($table, $index); |
158 | $index = new xmldb_index('itemtype-itemid-tagid-tiuserid'); |
159 | $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid')); |
160 | $dbman->add_index($table, $index); |
161 | |
162 | /// Main savepoint reached |
163 | upgrade_main_savepoint($result, 2008063001); |
164 | } |
38fb8190 |
165 | |
a036d7f3 |
166 | if ($result && $oldversion < 2008070300) { |
167 | $result = $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false)); |
168 | upgrade_main_savepoint($result, 2008070300); |
169 | } |
4e781c7b |
170 | |
fe074586 |
171 | if ($result && $oldversion < 2008070700) { |
172 | if (isset($CFG->defaultuserroleid) and isset($CFG->guestroleid) and $CFG->defaultuserroleid == $CFG->guestroleid) { |
173 | // guest can not be selected in defaultuserroleid! |
174 | unset_config('defaultuserroleid'); |
175 | } |
176 | upgrade_main_savepoint($result, 2008070700); |
177 | } |
178 | |
ac5efef6 |
179 | if ($result && $oldversion < 2008070701) { |
180 | |
181 | /// Define table portfolio_instance to be created |
182 | $table = new xmldb_table('portfolio_instance'); |
183 | |
184 | /// Adding fields to table portfolio_instance |
185 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
186 | $table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null); |
187 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
188 | $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1'); |
189 | |
190 | /// Adding keys to table portfolio_instance |
191 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
192 | |
193 | /// Conditionally launch create table for portfolio_instance |
194 | if (!$dbman->table_exists($table)) { |
195 | $dbman->create_table($table); |
196 | } |
197 | /// Define table portfolio_instance_config to be created |
198 | $table = new xmldb_table('portfolio_instance_config'); |
199 | |
200 | /// Adding fields to table portfolio_instance_config |
201 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
202 | $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
203 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
204 | $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); |
205 | |
206 | /// Adding keys to table portfolio_instance_config |
207 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
208 | $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id')); |
209 | |
210 | /// Adding indexes to table portfolio_instance_config |
211 | $table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name')); |
212 | |
213 | /// Conditionally launch create table for portfolio_instance_config |
214 | if (!$dbman->table_exists($table)) { |
215 | $dbman->create_table($table); |
216 | } |
217 | |
218 | /// Define table portfolio_instance_user to be created |
219 | $table = new xmldb_table('portfolio_instance_user'); |
220 | |
221 | /// Adding fields to table portfolio_instance_user |
222 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
223 | $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
224 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
225 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
226 | $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); |
227 | |
228 | /// Adding keys to table portfolio_instance_user |
229 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
230 | $table->add_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id')); |
231 | $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
232 | |
233 | /// Conditionally launch create table for portfolio_instance_user |
234 | if (!$dbman->table_exists($table)) { |
235 | $dbman->create_table($table); |
236 | } |
237 | |
238 | /// Main savepoint reached |
239 | upgrade_main_savepoint($result, 2008070701); |
240 | } |
172dd12c |
241 | |
775f811a |
242 | if ($result && $oldversion < 2008072400) { |
243 | /// Create the database tables for message_processors |
f65b2dae |
244 | $table = new xmldb_table('message_processors'); |
245 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
246 | $table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null); |
247 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
3b120e46 |
248 | $dbman->create_table($table); |
249 | |
3b120e46 |
250 | /// delete old and create new fields |
f65b2dae |
251 | $table = new xmldb_table('message'); |
252 | $field = new xmldb_field('messagetype'); |
3b120e46 |
253 | $dbman->drop_field($table, $field); |
254 | |
255 | /// fields to rename |
f65b2dae |
256 | $field = new xmldb_field('message'); |
257 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null); |
3b120e46 |
258 | $dbman->rename_field($table, $field, 'fullmessage'); |
f65b2dae |
259 | $field = new xmldb_field('format'); |
260 | $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '0', null); |
3b120e46 |
261 | $dbman->rename_field($table, $field, 'fullmessageformat'); |
262 | |
263 | /// new message fields |
f65b2dae |
264 | $field = new xmldb_field('subject'); |
265 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null); |
3b120e46 |
266 | $dbman->add_field($table, $field); |
f65b2dae |
267 | $field = new xmldb_field('fullmessagehtml'); |
268 | $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, null); |
3b120e46 |
269 | $dbman->add_field($table, $field); |
f65b2dae |
270 | $field = new xmldb_field('smallmessage'); |
271 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null); |
3b120e46 |
272 | $dbman->add_field($table, $field); |
273 | |
274 | |
f65b2dae |
275 | $table = new xmldb_table('message_read'); |
276 | $field = new xmldb_field('messagetype'); |
3b120e46 |
277 | $dbman->drop_field($table, $field); |
f65b2dae |
278 | $field = new xmldb_field('mailed'); |
3b120e46 |
279 | $dbman->drop_field($table, $field); |
280 | |
281 | /// fields to rename |
f65b2dae |
282 | $field = new xmldb_field('message'); |
283 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null); |
3b120e46 |
284 | $dbman->rename_field($table, $field, 'fullmessage'); |
f65b2dae |
285 | $field = new xmldb_field('format'); |
286 | $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '0', null); |
3b120e46 |
287 | $dbman->rename_field($table, $field, 'fullmessageformat'); |
288 | |
289 | |
290 | /// new message fields |
f65b2dae |
291 | $field = new xmldb_field('subject'); |
292 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null); |
3b120e46 |
293 | $dbman->add_field($table, $field); |
f65b2dae |
294 | $field = new xmldb_field('fullmessagehtml'); |
295 | $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, null); |
3b120e46 |
296 | $dbman->add_field($table, $field); |
f65b2dae |
297 | $field = new xmldb_field('smallmessage'); |
298 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null); |
3b120e46 |
299 | $dbman->add_field($table, $field); |
300 | |
301 | /// new table |
f65b2dae |
302 | $table = new xmldb_table('message_working'); |
303 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
304 | $table->add_field('unreadmessageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
305 | $table->add_field('processorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
306 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
3b120e46 |
307 | $dbman->create_table($table); |
308 | |
309 | |
310 | upgrade_main_savepoint($result, 2008072400); |
311 | } |
312 | |
4e781c7b |
313 | if ($result && $oldversion < 2008072800) { |
314 | |
315 | /// Define field enablecompletion to be added to course |
316 | $table = new xmldb_table('course'); |
317 | $field = new xmldb_field('enablecompletion'); |
318 | $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'defaultrole'); |
319 | |
320 | /// Launch add field enablecompletion |
775f811a |
321 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
322 | $dbman->add_field($table, $field); |
323 | } |
775f811a |
324 | |
4e781c7b |
325 | /// Define field completion to be added to course_modules |
326 | $table = new xmldb_table('course_modules'); |
327 | $field = new xmldb_field('completion'); |
328 | $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'groupmembersonly'); |
329 | |
330 | /// Launch add field completion |
775f811a |
331 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
332 | $dbman->add_field($table, $field); |
333 | } |
334 | |
335 | /// Define field completiongradeitemnumber to be added to course_modules |
336 | $field = new xmldb_field('completiongradeitemnumber'); |
337 | $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'completion'); |
338 | |
339 | /// Launch add field completiongradeitemnumber |
775f811a |
340 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
341 | $dbman->add_field($table, $field); |
342 | } |
343 | |
344 | /// Define field completionview to be added to course_modules |
345 | $field = new xmldb_field('completionview'); |
346 | $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completiongradeitemnumber'); |
347 | |
348 | /// Launch add field completionview |
775f811a |
349 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
350 | $dbman->add_field($table, $field); |
351 | } |
352 | |
353 | /// Define field completionexpected to be added to course_modules |
354 | $field = new xmldb_field('completionexpected'); |
355 | $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionview'); |
356 | |
357 | /// Launch add field completionexpected |
775f811a |
358 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
359 | $dbman->add_field($table, $field); |
360 | } |
361 | |
362 | /// Define table course_modules_completion to be created |
363 | $table = new xmldb_table('course_modules_completion'); |
775f811a |
364 | if (!$dbman->table_exists($table)) { |
4e781c7b |
365 | |
366 | /// Adding fields to table course_modules_completion |
1e0c56ea |
367 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
368 | $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
369 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
370 | $table->add_field('completionstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
371 | $table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null); |
372 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
775f811a |
373 | |
4e781c7b |
374 | /// Adding keys to table course_modules_completion |
1e0c56ea |
375 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
775f811a |
376 | |
4e781c7b |
377 | /// Adding indexes to table course_modules_completion |
1e0c56ea |
378 | $table->add_index('coursemoduleid', XMLDB_INDEX_NOTUNIQUE, array('coursemoduleid')); |
379 | $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); |
775f811a |
380 | |
4e781c7b |
381 | /// Launch create table for course_modules_completion |
382 | $dbman->create_table($table); |
383 | } |
384 | |
385 | /// Main savepoint reached |
386 | upgrade_main_savepoint($result, 2008072800); |
387 | } |
775f811a |
388 | |
4ab16a09 |
389 | if ($result && $oldversion < 2008073000) { |
ac5efef6 |
390 | |
4ab16a09 |
391 | /// Define table portfolio_log to be created |
392 | $table = new xmldb_table('portfolio_log'); |
393 | |
394 | /// Adding fields to table portfolio_log |
395 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
396 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
397 | $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
398 | $table->add_field('portfolio', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
399 | $table->add_field('caller_class', XMLDB_TYPE_CHAR, '150', null, XMLDB_NOTNULL, null, null, null, null); |
400 | $table->add_field('caller_file', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
401 | $table->add_field('caller_sha1', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
402 | |
403 | /// Adding keys to table portfolio_log |
404 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
405 | $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
406 | $table->add_key('portfoliofk', XMLDB_KEY_FOREIGN, array('portfolio'), 'portfolio_instance', array('id')); |
407 | |
408 | /// Conditionally launch create table for portfolio_log |
409 | if (!$dbman->table_exists($table)) { |
410 | $dbman->create_table($table); |
411 | } |
412 | |
413 | /// Main savepoint reached |
414 | upgrade_main_savepoint($result, 2008073000); |
415 | } |
120b3758 |
416 | |
417 | if ($result && $oldversion < 2008073104) { |
418 | /// Drop old table that might exist for some people |
419 | $table = new xmldb_table('message_providers'); |
420 | if ($dbman->table_exists($table)) { |
421 | $dbman->drop_table($table); |
422 | } |
423 | |
424 | /// Define table message_providers to be created |
425 | $table = new xmldb_table('message_providers'); |
426 | |
427 | /// Adding fields to table message_providers |
428 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
429 | $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null); |
430 | $table->add_field('component', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null, null, null); |
431 | $table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); |
432 | |
433 | /// Adding keys to table message_providers |
434 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
435 | |
436 | /// Adding indexes to table message_providers |
437 | $table->add_index('componentname', XMLDB_INDEX_UNIQUE, array('component', 'name')); |
438 | |
439 | /// Create table for message_providers |
440 | $dbman->create_table($table); |
441 | |
442 | upgrade_main_savepoint($result, 2008073104); |
443 | } |
172dd12c |
444 | |
445 | if ($result && $oldversion < 2008073111) { |
446 | /// Define table files to be created |
447 | $table = new xmldb_table('files'); |
448 | |
449 | /// Adding fields to table files |
450 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
451 | $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null); |
452 | $table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null); |
453 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
454 | $table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null); |
455 | $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
456 | $table->add_field('filepath', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
457 | $table->add_field('filename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
458 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); |
459 | $table->add_field('filesize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
460 | $table->add_field('mimetype', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null); |
461 | $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); |
462 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
463 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
464 | |
465 | /// Adding keys to table files |
466 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
467 | $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); |
468 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
469 | |
470 | /// Adding indexes to table files |
471 | $table->add_index('filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('filearea', 'contextid', 'itemid')); |
472 | $table->add_index('contenthash', XMLDB_INDEX_NOTUNIQUE, array('contenthash')); |
473 | $table->add_index('pathnamehash', XMLDB_INDEX_UNIQUE, array('pathnamehash')); |
474 | |
475 | /// Conditionally launch create table for files |
476 | $dbman->create_table($table); |
477 | |
478 | /// Main savepoint reached |
479 | upgrade_main_savepoint($result, 2008073111); |
480 | } |
481 | |
482 | if ($result && $oldversion < 2008073112) { |
483 | /// Define table files_cleanup to be created |
484 | $table = new xmldb_table('files_cleanup'); |
485 | |
486 | /// Adding fields to table files_cleanup |
487 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
488 | $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null); |
489 | |
490 | /// Adding keys to table files_cleanup |
491 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
492 | |
493 | /// Adding indexes to table files_cleanup |
494 | $table->add_index('contenthash', XMLDB_INDEX_UNIQUE, array('contenthash')); |
495 | |
496 | /// Conditionally launch create table for files_cleanup |
497 | $dbman->create_table($table); |
498 | |
499 | /// Main savepoint reached |
500 | upgrade_main_savepoint($result, 2008073112); |
501 | } |
502 | |
503 | if ($result && $oldversion < 2008073113) { |
504 | /// move all course, backup and other files to new filepool based storage |
505 | upgrade_migrate_files_courses(); |
506 | /// Main savepoint reached |
507 | upgrade_main_savepoint($result, 2008073113); |
508 | } |
509 | |
510 | if ($result && $oldversion < 2008073114) { |
511 | /// move all course, backup and other files to new filepool based storage |
512 | upgrade_migrate_files_blog(); |
513 | /// Main savepoint reached |
514 | upgrade_main_savepoint($result, 2008073114); |
515 | } |
f33e1ed4 |
516 | |
1ce2da58 |
517 | if ($result && $oldversion < 2008080400) { |
518 | // Add field ssl_jump_url to mnet application, and populate existing default applications |
519 | $table = new xmldb_table('mnet_application'); |
520 | $field = new xmldb_field('sso_jump_url'); |
521 | if (!$dbman->field_exists($table, $field)) { |
522 | $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
c5a04d12 |
523 | $dbman->add_field($table, $field); |
524 | $result = $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle')); |
1ce2da58 |
525 | $result = $result && $DB->set_field('mnet_application', 'sso_jump_url', '/auth/xmlrpc/jump.php', array('name' => 'mahara')); |
526 | } |
527 | |
528 | /// Main savepoint reached |
529 | upgrade_main_savepoint($result, 2008080400); |
530 | } |
04f35360 |
531 | |
532 | if ($result && $oldversion < 2008080500) { |
533 | |
534 | /// Define table portfolio_tempdata to be created |
535 | $table = new xmldb_table('portfolio_tempdata'); |
536 | |
537 | /// Adding fields to table portfolio_tempdata |
538 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
539 | $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); |
540 | |
541 | /// Adding keys to table portfolio_tempdata |
542 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
543 | |
544 | /// Conditionally launch create table for portfolio_tempdata |
545 | if (!$dbman->table_exists($table)) { |
546 | $dbman->create_table($table); |
547 | } |
548 | |
549 | /// Main savepoint reached |
550 | upgrade_main_savepoint($result, 2008080500); |
551 | } |
552 | |
84a44985 |
553 | if ($result && $oldversion < 2008080600) { |
554 | |
555 | $DB->delete_records('portfolio_tempdata'); // there shouldnt' be any, and it will cause problems with this upgrade. |
556 | /// Define field expirytime to be added to portfolio_tempdata |
557 | $table = new xmldb_table('portfolio_tempdata'); |
558 | $field = new xmldb_field('expirytime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'data'); |
559 | |
560 | /// Conditionally launch add field expirytime |
561 | if (!$dbman->field_exists($table, $field)) { |
562 | $dbman->add_field($table, $field); |
563 | } |
564 | |
565 | /// Main savepoint reached |
566 | upgrade_main_savepoint($result, 2008080600); |
567 | } |
775f811a |
568 | |
f9a2cf86 |
569 | /// Changing the type of all the columns that the question bank uses to store grades to be NUMBER(12, 7). |
570 | if ($result && $oldversion < 2008081500) { |
571 | $table = new xmldb_table('question'); |
572 | $field = new xmldb_field('defaultgrade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'generalfeedback'); |
573 | $dbman->change_field_type($table, $field); |
574 | upgrade_main_savepoint($result, 2008081500); |
575 | } |
576 | |
577 | if ($result && $oldversion < 2008081501) { |
578 | $table = new xmldb_table('question'); |
579 | $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'defaultgrade'); |
580 | $dbman->change_field_type($table, $field); |
581 | upgrade_main_savepoint($result, 2008081501); |
582 | } |
583 | |
584 | if ($result && $oldversion < 2008081502) { |
585 | $table = new xmldb_table('question_answers'); |
586 | $field = new xmldb_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'answer'); |
587 | $dbman->change_field_type($table, $field); |
588 | upgrade_main_savepoint($result, 2008081502); |
589 | } |
590 | |
591 | if ($result && $oldversion < 2008081503) { |
592 | $table = new xmldb_table('question_sessions'); |
593 | $field = new xmldb_field('sumpenalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'newgraded'); |
594 | $dbman->change_field_type($table, $field); |
595 | upgrade_main_savepoint($result, 2008081503); |
596 | } |
597 | |
598 | if ($result && $oldversion < 2008081504) { |
599 | $table = new xmldb_table('question_states'); |
600 | $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'event'); |
601 | $dbman->change_field_type($table, $field); |
602 | upgrade_main_savepoint($result, 2008081504); |
603 | } |
604 | |
605 | if ($result && $oldversion < 2008081505) { |
606 | $table = new xmldb_table('question_states'); |
607 | $field = new xmldb_field('raw_grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'grade'); |
608 | $dbman->change_field_type($table, $field); |
609 | upgrade_main_savepoint($result, 2008081505); |
610 | } |
611 | |
612 | if ($result && $oldversion < 2008081506) { |
613 | $table = new xmldb_table('question_states'); |
614 | $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'raw_grade'); |
615 | $dbman->change_field_type($table, $field); |
616 | upgrade_main_savepoint($result, 2008081506); |
617 | } |
618 | |
775f811a |
619 | if ($result && $oldversion < 2008081600) { |
620 | |
621 | /// all 1.9 sites and fresh installs must already be unicode, not needed anymore |
622 | unset_config('unicodedb'); |
623 | |
624 | /// Main savepoint reached |
625 | upgrade_main_savepoint($result, 2008081600); |
626 | } |
627 | |
ff2f69bc |
628 | if ($result && $oldversion < 2008081900) { |
629 | /// Define field userid to be added to portfolio_tempdata |
630 | $table = new xmldb_table('portfolio_tempdata'); |
631 | $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'expirytime'); |
632 | |
633 | /// Conditionally launch add field userid |
634 | if (!$dbman->field_exists($table, $field)) { |
635 | $dbman->add_field($table, $field); |
636 | } |
637 | $DB->set_field('portfolio_tempdata', 'userid', 0); |
638 | /// now change it to be notnull |
639 | |
640 | /// Changing nullability of field userid on table portfolio_tempdata to not null |
641 | $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'expirytime'); |
642 | |
643 | /// Launch change of nullability for field userid |
644 | $dbman->change_field_notnull($table, $field); |
645 | |
646 | /// Define key userfk (foreign) to be added to portfolio_tempdata |
647 | $table = new xmldb_table('portfolio_tempdata'); |
648 | $key = new xmldb_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
649 | |
650 | /// Launch add key userfk |
651 | $dbman->add_key($table, $key); |
652 | |
653 | upgrade_main_savepoint($result, 2008081900); |
654 | } |
8f3f6cc3 |
655 | if ($result && $oldversion < 2008082602) { |
27051e43 |
656 | |
657 | /// Define table repository to be dropped |
658 | $table = new xmldb_table('repository'); |
659 | |
660 | /// Conditionally launch drop table for repository |
661 | if ($dbman->table_exists($table)) { |
662 | $dbman->drop_table($table); |
663 | } |
664 | |
665 | /// Define table repository to be created |
666 | $table = new xmldb_table('repository'); |
667 | |
668 | /// Adding fields to table repository |
669 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
670 | $table->add_field('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
671 | $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, '1'); |
672 | $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); |
673 | |
674 | /// Adding keys to table repository |
675 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
676 | |
677 | /// Conditionally launch create table for repository |
678 | if (!$dbman->table_exists($table)) { |
679 | $dbman->create_table($table); |
680 | } |
681 | /// Define table repository_instances to be created |
682 | $table = new xmldb_table('repository_instances'); |
683 | |
684 | /// Adding fields to table repository_instances |
685 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
686 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
687 | $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
688 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); |
689 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
690 | $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); |
691 | $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); |
692 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); |
693 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); |
694 | |
695 | /// Adding keys to table repository_instances |
696 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
697 | |
698 | /// Conditionally launch create table for repository_instances |
699 | if (!$dbman->table_exists($table)) { |
700 | $dbman->create_table($table); |
701 | } |
702 | |
703 | /// Define table repository_instance_config to be created |
704 | $table = new xmldb_table('repository_instance_config'); |
705 | |
706 | /// Adding fields to table repository_instance_config |
707 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
708 | $table->add_field('instanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
709 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
710 | $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); |
711 | |
712 | /// Adding keys to table repository_instance_config |
713 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
714 | |
715 | /// Conditionally launch create table for repository_instance_config |
716 | if (!$dbman->table_exists($table)) { |
717 | $dbman->create_table($table); |
718 | } |
719 | |
720 | /// Main savepoint reached |
8f3f6cc3 |
721 | upgrade_main_savepoint($result, 2008082602); |
27051e43 |
722 | } |
723 | |
62e76c67 |
724 | if ($result && $oldversion < 2008082700) { |
725 | /// Add a new column to the question sessions table to record whether a |
726 | /// question has been flagged. |
727 | |
728 | /// Define field flagged to be added to question_sessions |
729 | $table = new xmldb_table('question_sessions'); |
730 | $field = new xmldb_field('flagged', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, null, null, '0', 'manualcomment'); |
731 | |
732 | /// Conditionally launch add field flagged |
733 | if (!$dbman->field_exists($table, $field)) { |
734 | $dbman->add_field($table, $field); |
735 | } |
736 | |
737 | /// Main savepoint reached |
738 | upgrade_main_savepoint($result, 2008082700); |
739 | } |
ff2f69bc |
740 | |
2c48aeab |
741 | if ($result && $oldversion < 2008082900) { |
742 | |
743 | /// Changing precision of field parent_type on table mnet_rpc to (20) |
744 | $table = new xmldb_table('mnet_rpc'); |
745 | $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, null, 'xmlrpc_path'); |
746 | |
747 | /// Launch change of precision for field parent_type |
748 | $dbman->change_field_precision($table, $field); |
749 | |
750 | /// Main savepoint reached |
751 | upgrade_main_savepoint($result, 2008082900); |
752 | } |
753 | |
ac9b0805 |
754 | return $result; |
4e423cbf |
755 | } |
271e6dec |
756 | |
757 | |
4e423cbf |
758 | ?> |