MDL-12563 Fixed RSS dates so that they are always GMT
[moodle.git] / lib / db / upgrade.php
CommitLineData
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 22function 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'));
b91de8a5 157 if ($dbman->index_exists($table, $index)) {
158 $dbman->drop_index($table, $index);
159 }
38fb8190 160 $index = new xmldb_index('itemtype-itemid-tagid-tiuserid');
161 $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
b91de8a5 162 if (!$dbman->index_exists($table, $index)) {
163 $dbman->add_index($table, $index);
164 }
38fb8190 165
166 /// Main savepoint reached
167 upgrade_main_savepoint($result, 2008063001);
168 }
38fb8190 169
a036d7f3 170 if ($result && $oldversion < 2008070300) {
171 $result = $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false));
172 upgrade_main_savepoint($result, 2008070300);
173 }
4e781c7b 174
fe074586 175 if ($result && $oldversion < 2008070700) {
176 if (isset($CFG->defaultuserroleid) and isset($CFG->guestroleid) and $CFG->defaultuserroleid == $CFG->guestroleid) {
177 // guest can not be selected in defaultuserroleid!
178 unset_config('defaultuserroleid');
179 }
180 upgrade_main_savepoint($result, 2008070700);
181 }
182
ac5efef6 183 if ($result && $oldversion < 2008070701) {
184
185 /// Define table portfolio_instance to be created
186 $table = new xmldb_table('portfolio_instance');
187
188 /// Adding fields to table portfolio_instance
189 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
190 $table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null);
191 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
192 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1');
193
194 /// Adding keys to table portfolio_instance
195 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
196
197 /// Conditionally launch create table for portfolio_instance
198 if (!$dbman->table_exists($table)) {
199 $dbman->create_table($table);
200 }
201 /// Define table portfolio_instance_config to be created
202 $table = new xmldb_table('portfolio_instance_config');
203
204 /// Adding fields to table portfolio_instance_config
205 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
206 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
207 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
208 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
209
210 /// Adding keys to table portfolio_instance_config
211 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
212 $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
213
214 /// Adding indexes to table portfolio_instance_config
215 $table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name'));
216
217 /// Conditionally launch create table for portfolio_instance_config
218 if (!$dbman->table_exists($table)) {
219 $dbman->create_table($table);
220 }
221
222 /// Define table portfolio_instance_user to be created
223 $table = new xmldb_table('portfolio_instance_user');
224
225 /// Adding fields to table portfolio_instance_user
226 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
227 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
228 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
229 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
230 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
231
232 /// Adding keys to table portfolio_instance_user
233 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
234 $table->add_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
235 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
236
237 /// Conditionally launch create table for portfolio_instance_user
238 if (!$dbman->table_exists($table)) {
239 $dbman->create_table($table);
240 }
241
242 /// Main savepoint reached
243 upgrade_main_savepoint($result, 2008070701);
244 }
172dd12c 245
775f811a 246 if ($result && $oldversion < 2008072400) {
247 /// Create the database tables for message_processors
f65b2dae 248 $table = new xmldb_table('message_processors');
249 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
250 $table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null);
251 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3b120e46 252 $dbman->create_table($table);
253
3b120e46 254 /// delete old and create new fields
f65b2dae 255 $table = new xmldb_table('message');
256 $field = new xmldb_field('messagetype');
3b120e46 257 $dbman->drop_field($table, $field);
258
259 /// fields to rename
f65b2dae 260 $field = new xmldb_field('message');
261 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 262 $dbman->rename_field($table, $field, 'fullmessage');
f65b2dae 263 $field = new xmldb_field('format');
264 $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '0', null);
3b120e46 265 $dbman->rename_field($table, $field, 'fullmessageformat');
266
267 /// new message fields
f65b2dae 268 $field = new xmldb_field('subject');
269 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 270 $dbman->add_field($table, $field);
f65b2dae 271 $field = new xmldb_field('fullmessagehtml');
272 $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, null);
3b120e46 273 $dbman->add_field($table, $field);
f65b2dae 274 $field = new xmldb_field('smallmessage');
275 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 276 $dbman->add_field($table, $field);
277
278
f65b2dae 279 $table = new xmldb_table('message_read');
280 $field = new xmldb_field('messagetype');
3b120e46 281 $dbman->drop_field($table, $field);
f65b2dae 282 $field = new xmldb_field('mailed');
3b120e46 283 $dbman->drop_field($table, $field);
284
285 /// fields to rename
f65b2dae 286 $field = new xmldb_field('message');
287 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 288 $dbman->rename_field($table, $field, 'fullmessage');
f65b2dae 289 $field = new xmldb_field('format');
290 $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '0', null);
3b120e46 291 $dbman->rename_field($table, $field, 'fullmessageformat');
292
293
294 /// new message fields
f65b2dae 295 $field = new xmldb_field('subject');
296 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 297 $dbman->add_field($table, $field);
f65b2dae 298 $field = new xmldb_field('fullmessagehtml');
299 $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, null);
3b120e46 300 $dbman->add_field($table, $field);
f65b2dae 301 $field = new xmldb_field('smallmessage');
302 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 303 $dbman->add_field($table, $field);
304
305 /// new table
f65b2dae 306 $table = new xmldb_table('message_working');
307 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
308 $table->add_field('unreadmessageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
309 $table->add_field('processorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
310 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3b120e46 311 $dbman->create_table($table);
312
313
314 upgrade_main_savepoint($result, 2008072400);
315 }
316
4e781c7b 317 if ($result && $oldversion < 2008072800) {
318
319 /// Define field enablecompletion to be added to course
320 $table = new xmldb_table('course');
321 $field = new xmldb_field('enablecompletion');
322 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'defaultrole');
323
324 /// Launch add field enablecompletion
775f811a 325 if (!$dbman->field_exists($table,$field)) {
4e781c7b 326 $dbman->add_field($table, $field);
327 }
775f811a 328
4e781c7b 329 /// Define field completion to be added to course_modules
330 $table = new xmldb_table('course_modules');
331 $field = new xmldb_field('completion');
332 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'groupmembersonly');
333
334 /// Launch add field completion
775f811a 335 if (!$dbman->field_exists($table,$field)) {
4e781c7b 336 $dbman->add_field($table, $field);
337 }
338
339 /// Define field completiongradeitemnumber to be added to course_modules
340 $field = new xmldb_field('completiongradeitemnumber');
341 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'completion');
342
343 /// Launch add field completiongradeitemnumber
775f811a 344 if (!$dbman->field_exists($table,$field)) {
4e781c7b 345 $dbman->add_field($table, $field);
346 }
347
348 /// Define field completionview to be added to course_modules
349 $field = new xmldb_field('completionview');
350 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completiongradeitemnumber');
351
352 /// Launch add field completionview
775f811a 353 if (!$dbman->field_exists($table,$field)) {
4e781c7b 354 $dbman->add_field($table, $field);
355 }
356
357 /// Define field completionexpected to be added to course_modules
358 $field = new xmldb_field('completionexpected');
359 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionview');
360
361 /// Launch add field completionexpected
775f811a 362 if (!$dbman->field_exists($table,$field)) {
4e781c7b 363 $dbman->add_field($table, $field);
364 }
365
366 /// Define table course_modules_completion to be created
367 $table = new xmldb_table('course_modules_completion');
775f811a 368 if (!$dbman->table_exists($table)) {
4e781c7b 369
370 /// Adding fields to table course_modules_completion
1e0c56ea 371 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
372 $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
373 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
374 $table->add_field('completionstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
375 $table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null);
376 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
775f811a 377
4e781c7b 378 /// Adding keys to table course_modules_completion
1e0c56ea 379 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
775f811a 380
4e781c7b 381 /// Adding indexes to table course_modules_completion
1e0c56ea 382 $table->add_index('coursemoduleid', XMLDB_INDEX_NOTUNIQUE, array('coursemoduleid'));
383 $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
775f811a 384
4e781c7b 385 /// Launch create table for course_modules_completion
386 $dbman->create_table($table);
387 }
388
389 /// Main savepoint reached
390 upgrade_main_savepoint($result, 2008072800);
391 }
775f811a 392
4ab16a09 393 if ($result && $oldversion < 2008073000) {
ac5efef6 394
4ab16a09 395 /// Define table portfolio_log to be created
396 $table = new xmldb_table('portfolio_log');
397
398 /// Adding fields to table portfolio_log
399 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
400 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
401 $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
402 $table->add_field('portfolio', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
403 $table->add_field('caller_class', XMLDB_TYPE_CHAR, '150', null, XMLDB_NOTNULL, null, null, null, null);
404 $table->add_field('caller_file', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
405 $table->add_field('caller_sha1', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
406
407 /// Adding keys to table portfolio_log
408 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
409 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
410 $table->add_key('portfoliofk', XMLDB_KEY_FOREIGN, array('portfolio'), 'portfolio_instance', array('id'));
411
412 /// Conditionally launch create table for portfolio_log
413 if (!$dbman->table_exists($table)) {
414 $dbman->create_table($table);
415 }
416
417 /// Main savepoint reached
418 upgrade_main_savepoint($result, 2008073000);
419 }
120b3758 420
421 if ($result && $oldversion < 2008073104) {
422 /// Drop old table that might exist for some people
423 $table = new xmldb_table('message_providers');
424 if ($dbman->table_exists($table)) {
425 $dbman->drop_table($table);
426 }
427
428 /// Define table message_providers to be created
429 $table = new xmldb_table('message_providers');
430
431 /// Adding fields to table message_providers
432 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
433 $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null);
434 $table->add_field('component', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null, null, null);
435 $table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
436
437 /// Adding keys to table message_providers
438 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
439
440 /// Adding indexes to table message_providers
441 $table->add_index('componentname', XMLDB_INDEX_UNIQUE, array('component', 'name'));
442
443 /// Create table for message_providers
444 $dbman->create_table($table);
445
446 upgrade_main_savepoint($result, 2008073104);
447 }
172dd12c 448
449 if ($result && $oldversion < 2008073111) {
450 /// Define table files to be created
451 $table = new xmldb_table('files');
452
453 /// Adding fields to table files
454 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
455 $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null);
456 $table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null);
457 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
458 $table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null);
459 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
460 $table->add_field('filepath', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
461 $table->add_field('filename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
462 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
463 $table->add_field('filesize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
464 $table->add_field('mimetype', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null);
465 $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
466 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
467 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
468
469 /// Adding keys to table files
470 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
471 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
472 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
473
474 /// Adding indexes to table files
475 $table->add_index('filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('filearea', 'contextid', 'itemid'));
476 $table->add_index('contenthash', XMLDB_INDEX_NOTUNIQUE, array('contenthash'));
477 $table->add_index('pathnamehash', XMLDB_INDEX_UNIQUE, array('pathnamehash'));
478
479 /// Conditionally launch create table for files
480 $dbman->create_table($table);
481
482 /// Main savepoint reached
483 upgrade_main_savepoint($result, 2008073111);
484 }
485
486 if ($result && $oldversion < 2008073112) {
487 /// Define table files_cleanup to be created
488 $table = new xmldb_table('files_cleanup');
489
490 /// Adding fields to table files_cleanup
491 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
492 $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null);
493
494 /// Adding keys to table files_cleanup
495 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
496
497 /// Adding indexes to table files_cleanup
498 $table->add_index('contenthash', XMLDB_INDEX_UNIQUE, array('contenthash'));
499
500 /// Conditionally launch create table for files_cleanup
501 $dbman->create_table($table);
502
503 /// Main savepoint reached
504 upgrade_main_savepoint($result, 2008073112);
505 }
506
507 if ($result && $oldversion < 2008073113) {
508 /// move all course, backup and other files to new filepool based storage
509 upgrade_migrate_files_courses();
510 /// Main savepoint reached
511 upgrade_main_savepoint($result, 2008073113);
512 }
513
514 if ($result && $oldversion < 2008073114) {
515 /// move all course, backup and other files to new filepool based storage
516 upgrade_migrate_files_blog();
517 /// Main savepoint reached
518 upgrade_main_savepoint($result, 2008073114);
519 }
f33e1ed4 520
1ce2da58 521 if ($result && $oldversion < 2008080400) {
522 // Add field ssl_jump_url to mnet application, and populate existing default applications
523 $table = new xmldb_table('mnet_application');
524 $field = new xmldb_field('sso_jump_url');
525 if (!$dbman->field_exists($table, $field)) {
526 $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
c5a04d12 527 $dbman->add_field($table, $field);
528 $result = $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle'));
1ce2da58 529 $result = $result && $DB->set_field('mnet_application', 'sso_jump_url', '/auth/xmlrpc/jump.php', array('name' => 'mahara'));
530 }
531
532 /// Main savepoint reached
533 upgrade_main_savepoint($result, 2008080400);
534 }
04f35360 535
536 if ($result && $oldversion < 2008080500) {
537
538 /// Define table portfolio_tempdata to be created
539 $table = new xmldb_table('portfolio_tempdata');
540
541 /// Adding fields to table portfolio_tempdata
542 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
543 $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
544
545 /// Adding keys to table portfolio_tempdata
546 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
547
548 /// Conditionally launch create table for portfolio_tempdata
549 if (!$dbman->table_exists($table)) {
550 $dbman->create_table($table);
551 }
552
553 /// Main savepoint reached
554 upgrade_main_savepoint($result, 2008080500);
555 }
556
84a44985 557 if ($result && $oldversion < 2008080600) {
558
559 $DB->delete_records('portfolio_tempdata'); // there shouldnt' be any, and it will cause problems with this upgrade.
560 /// Define field expirytime to be added to portfolio_tempdata
561 $table = new xmldb_table('portfolio_tempdata');
562 $field = new xmldb_field('expirytime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'data');
563
564 /// Conditionally launch add field expirytime
565 if (!$dbman->field_exists($table, $field)) {
566 $dbman->add_field($table, $field);
567 }
568
569 /// Main savepoint reached
570 upgrade_main_savepoint($result, 2008080600);
571 }
775f811a 572
f9a2cf86 573/// Changing the type of all the columns that the question bank uses to store grades to be NUMBER(12, 7).
574 if ($result && $oldversion < 2008081500) {
575 $table = new xmldb_table('question');
576 $field = new xmldb_field('defaultgrade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'generalfeedback');
577 $dbman->change_field_type($table, $field);
578 upgrade_main_savepoint($result, 2008081500);
579 }
580
581 if ($result && $oldversion < 2008081501) {
582 $table = new xmldb_table('question');
583 $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'defaultgrade');
584 $dbman->change_field_type($table, $field);
585 upgrade_main_savepoint($result, 2008081501);
586 }
587
588 if ($result && $oldversion < 2008081502) {
589 $table = new xmldb_table('question_answers');
590 $field = new xmldb_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'answer');
591 $dbman->change_field_type($table, $field);
592 upgrade_main_savepoint($result, 2008081502);
593 }
594
595 if ($result && $oldversion < 2008081503) {
596 $table = new xmldb_table('question_sessions');
597 $field = new xmldb_field('sumpenalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'newgraded');
598 $dbman->change_field_type($table, $field);
599 upgrade_main_savepoint($result, 2008081503);
600 }
601
602 if ($result && $oldversion < 2008081504) {
603 $table = new xmldb_table('question_states');
604 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'event');
605 $dbman->change_field_type($table, $field);
606 upgrade_main_savepoint($result, 2008081504);
607 }
608
609 if ($result && $oldversion < 2008081505) {
610 $table = new xmldb_table('question_states');
611 $field = new xmldb_field('raw_grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'grade');
612 $dbman->change_field_type($table, $field);
613 upgrade_main_savepoint($result, 2008081505);
614 }
615
616 if ($result && $oldversion < 2008081506) {
617 $table = new xmldb_table('question_states');
618 $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'raw_grade');
619 $dbman->change_field_type($table, $field);
620 upgrade_main_savepoint($result, 2008081506);
621 }
622
775f811a 623 if ($result && $oldversion < 2008081600) {
624
625 /// all 1.9 sites and fresh installs must already be unicode, not needed anymore
626 unset_config('unicodedb');
627
628 /// Main savepoint reached
629 upgrade_main_savepoint($result, 2008081600);
630 }
631
ff2f69bc 632 if ($result && $oldversion < 2008081900) {
633 /// Define field userid to be added to portfolio_tempdata
634 $table = new xmldb_table('portfolio_tempdata');
635 $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'expirytime');
636
637 /// Conditionally launch add field userid
638 if (!$dbman->field_exists($table, $field)) {
639 $dbman->add_field($table, $field);
640 }
641 $DB->set_field('portfolio_tempdata', 'userid', 0);
642 /// now change it to be notnull
643
644 /// Changing nullability of field userid on table portfolio_tempdata to not null
645 $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'expirytime');
646
647 /// Launch change of nullability for field userid
648 $dbman->change_field_notnull($table, $field);
649
650 /// Define key userfk (foreign) to be added to portfolio_tempdata
651 $table = new xmldb_table('portfolio_tempdata');
652 $key = new xmldb_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
653
654 /// Launch add key userfk
655 $dbman->add_key($table, $key);
656
657 upgrade_main_savepoint($result, 2008081900);
658 }
8f3f6cc3 659 if ($result && $oldversion < 2008082602) {
27051e43 660
661 /// Define table repository to be dropped
662 $table = new xmldb_table('repository');
663
664 /// Conditionally launch drop table for repository
665 if ($dbman->table_exists($table)) {
666 $dbman->drop_table($table);
667 }
668
669 /// Define table repository to be created
670 $table = new xmldb_table('repository');
671
672 /// Adding fields to table repository
673 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
674 $table->add_field('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
675 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, '1');
676 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
677
678 /// Adding keys to table repository
679 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
680
681 /// Conditionally launch create table for repository
682 if (!$dbman->table_exists($table)) {
683 $dbman->create_table($table);
684 }
685 /// Define table repository_instances to be created
686 $table = new xmldb_table('repository_instances');
687
688 /// Adding fields to table repository_instances
689 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
690 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
691 $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
692 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
693 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
694 $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
695 $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
696 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
697 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
698
699 /// Adding keys to table repository_instances
700 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
701
702 /// Conditionally launch create table for repository_instances
703 if (!$dbman->table_exists($table)) {
704 $dbman->create_table($table);
705 }
706
707 /// Define table repository_instance_config to be created
708 $table = new xmldb_table('repository_instance_config');
709
710 /// Adding fields to table repository_instance_config
711 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
712 $table->add_field('instanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
713 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
714 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
715
716 /// Adding keys to table repository_instance_config
717 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
718
719 /// Conditionally launch create table for repository_instance_config
720 if (!$dbman->table_exists($table)) {
721 $dbman->create_table($table);
722 }
723
724 /// Main savepoint reached
8f3f6cc3 725 upgrade_main_savepoint($result, 2008082602);
27051e43 726 }
727
62e76c67 728 if ($result && $oldversion < 2008082700) {
729 /// Add a new column to the question sessions table to record whether a
730 /// question has been flagged.
731
732 /// Define field flagged to be added to question_sessions
733 $table = new xmldb_table('question_sessions');
734 $field = new xmldb_field('flagged', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, null, null, '0', 'manualcomment');
735
736 /// Conditionally launch add field flagged
737 if (!$dbman->field_exists($table, $field)) {
738 $dbman->add_field($table, $field);
739 }
740
741 /// Main savepoint reached
742 upgrade_main_savepoint($result, 2008082700);
743 }
ff2f69bc 744
2c48aeab 745 if ($result && $oldversion < 2008082900) {
746
747 /// Changing precision of field parent_type on table mnet_rpc to (20)
748 $table = new xmldb_table('mnet_rpc');
749 $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, null, 'xmlrpc_path');
750
751 /// Launch change of precision for field parent_type
752 $dbman->change_field_precision($table, $field);
753
754 /// Main savepoint reached
755 upgrade_main_savepoint($result, 2008082900);
756 }
757
ff7e7f92 758 if ($result && $oldversion < 2008090108) {
759 $repo = new object();
760 $repo->type = 'upload';
761 $repo->visible = 1;
762 $repo->sortorder = 1;
763 if (!$DB->record_exists('repository', array('type'=>'upload'))) {
764 $typeid = $DB->insert_record('repository', $repo);
765 }else{
766 $record = $DB->get_record('repository', array('type'=>'upload'));
767 $typeid = $record->id;
768 }
769 if (!$DB->record_exists('repository_instances', array('typeid'=>$typeid))) {
770 $instance = new object();
fb7cae3b 771 $instance->name = get_string('repositoryname', 'repository_upload');
ff7e7f92 772 $instance->typeid = $typeid;
773 $instance->userid = 0;
774 $instance->contextid = SITEID;
775 $instance->timecreated = time();
776 $instance->timemodified = time();
777 $result = $result && $DB->insert_record('repository_instances', $instance);
778 }
779 $repo->type = 'local';
780 $repo->visible = 1;
781 $repo->sortorder = 1;
782 if (!$DB->record_exists('repository', array('type'=>'local'))) {
783 $typeid = $DB->insert_record('repository', $repo);
784 }else{
785 $record = $DB->get_record('repository', array('type'=>'local'));
786 $typeid = $record->id;
787 }
788 if (!$DB->record_exists('repository_instances', array('typeid'=>$typeid))) {
789 $instance = new object();
fb7cae3b 790 $instance->name = get_string('repositoryname', 'repository_local');
ff7e7f92 791 $instance->typeid = $typeid;
792 $instance->userid = 0;
793 $instance->contextid = SITEID;
794 $instance->timecreated = time();
795 $instance->timemodified = time();
796 $result = $result && $DB->insert_record('repository_instances', $instance);
797 }
798
799 upgrade_main_savepoint($result, 2008090108);
800 }
801
d849880e 802 // MDL-16411 Move all plugintype_pluginname_version values from config to config_plugins.
803 if ($result && $oldversion < 2008091000) {
804 foreach (get_object_vars($CFG) as $name => $value) {
805 if (substr($name, strlen($name) - 8) !== '_version') {
806 continue;
807 }
808 $pluginname = substr($name, 0, strlen($name) - 8);
809 if (!strpos($pluginname, '_')) {
810 // Skip things like backup_version that don't contain an extra _
811 continue;
812 }
813 if ($pluginname == 'enrol_ldap_version') {
814 // Special case - this is something different from a plugin version number.
815 continue;
816 }
6f49dd0f 817 if (!preg_match('/^\d{10}$/', $value)) {
d849880e 818 // Extra safety check, skip anything that does not look like a Moodle
819 // version number (10 digits).
820 continue;
821 }
822 $result = $result && set_config('version', $value, $pluginname);
823 $result = $result && unset_config($name);
824 }
825 upgrade_main_savepoint($result, 2008091000);
826 }
827
ac9b0805 828 return $result;
4e423cbf 829}
271e6dec 830
831
4e423cbf 832?>