HotPot module: differentiate between "guesses-correct" (JCloze) and "guess-correct...
[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) {
aa9a6867 23 global $CFG, $THEME, $USER, $DB, $OUTPUT;
4e423cbf 24
4f12838e 25 require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions
13a0d3d3 26
4e423cbf 27 $result = true;
28
46d318bc 29 $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
f33e1ed4 30
1ea260d8 31 ////////////////////////////////////////
32 ///upgrade supported only from 1.9.x ///
33 ////////////////////////////////////////
da4aa3e4 34
795a08ad 35 if ($result && $oldversion < 2008030600) {
36 //NOTE: this table was added much later, that is why this step is repeated later in this file
37
38 /// Define table upgrade_log to be created
39 $table = new xmldb_table('upgrade_log');
40
41 /// Adding fields to table upgrade_log
2a88f626 42 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
43 $table->add_field('type', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
44 $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null);
45 $table->add_field('version', XMLDB_TYPE_CHAR, '100', null, null, null, null);
46 $table->add_field('info', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
47 $table->add_field('details', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
48 $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
49 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
50 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
795a08ad 51
52 /// Adding keys to table upgrade_log
53 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
54 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
55
56 /// Adding indexes to table upgrade_log
57 $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
58 $table->add_index('type-timemodified', XMLDB_INDEX_NOTUNIQUE, array('type', 'timemodified'));
59
60 /// Create table for upgrade_log
61 $dbman->create_table($table);
62
63 /// Main savepoint reached
64 upgrade_main_savepoint($result, 2008030600);
65 }
66
a1f27717 67 if ($result && $oldversion < 2008030700) {
775f811a 68 upgrade_set_timeout(60*20); // this may take a while
a1f27717 69
70 /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters
a8cb94f6 71 $table = new xmldb_table('grade_letters');
69b80cc2 72 $index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
a1f27717 73
74 /// Launch drop index contextid-lowerboundary
eee5d9bb 75 $dbman->drop_index($table, $index);
a1f27717 76
a1f27717 77 /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
a8cb94f6 78 $table = new xmldb_table('grade_letters');
69b80cc2 79 $index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
a1f27717 80
81 /// Launch add index contextid-lowerboundary-letter
eee5d9bb 82 $dbman->add_index($table, $index);
a1f27717 83
84 /// Main savepoint reached
0f77b186 85 upgrade_main_savepoint($result, 2008030700);
86 }
a1f27717 87
1ea260d8 88 if ($result && $oldversion < 2008050100) {
89 // Update courses that used weekscss to weeks
a8cb94f6 90 $result = $DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss'));
1ea260d8 91 upgrade_main_savepoint($result, 2008050100);
92 }
93
0b51c247 94 if ($result && $oldversion < 2008050200) {
95 // remove unused config options
96 unset_config('statsrolesupgraded');
97 upgrade_main_savepoint($result, 2008050200);
98 }
99
994fbaab 100 if ($result && $oldversion < 2008050700) {
775f811a 101 upgrade_set_timeout(60*20); // this may take a while
102
994fbaab 103 /// Fix minor problem caused by MDL-5482.
104 require_once($CFG->dirroot . '/question/upgrade.php');
105 $result = $result && question_fix_random_question_parents();
106 upgrade_main_savepoint($result, 2008050700);
107 }
108
ab37dc60 109 if ($result && $oldversion < 2008051200) {
110 // if guest role used as default user role unset it and force admin to choose new setting
111 if (!empty($CFG->defaultuserroleid)) {
910dd4dd 112 if ($role = $DB->get_record('role', array('id'=>$CFG->defaultuserroleid))) {
ab37dc60 113 if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
114 if (isset($guestroles[$role->id])) {
115 set_config('defaultuserroleid', null);
aa9a6867 116 echo $OUTPUT->notification('Guest role removed from "Default role for all users" setting, please select another role.', 'notifysuccess');
ab37dc60 117 }
118 }
119 } else {
120 set_config('defaultuserroleid', null);
121 }
122 }
a54e1638 123 /// Main savepoint reached
124 upgrade_main_savepoint($result, 2008051200);
ab37dc60 125 }
126
8b9cfac4 127 if ($result && $oldversion < 2008051201) {
aa9a6867 128 echo $OUTPUT->notification('Increasing size of user idnumber field, this may take a while...', 'notifysuccess');
775f811a 129 upgrade_set_timeout(60*20); // this may take a while
8b9cfac4 130
469dcbcc 131 /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859
cbc08f3b 132 $dbfamily = $DB->get_dbfamily();
133 if ($dbfamily === 'mysql' || $dbfamily === 'postgres') {
eee5d9bb 134 $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL");
469dcbcc 135 }
136
8b9cfac4 137 /// Define index idnumber (not unique) to be dropped form user
a8cb94f6 138 $table = new xmldb_table('user');
69b80cc2 139 $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
8b9cfac4 140
141 /// Launch drop index idnumber
f33e1ed4 142 if ($dbman->index_exists($table, $index)) {
eee5d9bb 143 $dbman->drop_index($table, $index);
8b9cfac4 144 }
145
146 /// Changing precision of field idnumber on table user to (255)
a8cb94f6 147 $table = new xmldb_table('user');
2a88f626 148 $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'password');
8b9cfac4 149
150 /// Launch change of precision for field idnumber
eee5d9bb 151 $dbman->change_field_precision($table, $field);
8b9cfac4 152
153 /// Launch add index idnumber again
69b80cc2 154 $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
eee5d9bb 155 $dbman->add_index($table, $index);
8b9cfac4 156
157 /// Main savepoint reached
158 upgrade_main_savepoint($result, 2008051201);
159 }
160
7ade55ad 161 if ($result && $oldversion < 2008051202) {
910dd4dd 162 $log_action = new object();
7ade55ad 163 $log_action->module = 'course';
164 $log_action->action = 'unenrol';
165 $log_action->mtable = 'course';
166 $log_action->field = 'fullname';
910dd4dd 167 if (!$DB->record_exists('log_display', array('action'=>'unenrol', 'module'=>'course'))) {
168 $result = $result && $DB->insert_record('log_display', $log_action);
7ade55ad 169 }
170 upgrade_main_savepoint($result, 2008051202);
171 }
172
fa162144 173 if ($result && $oldversion < 2008051203) {
174 $table = new xmldb_table('mnet_enrol_course');
2a88f626 175 $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
eee5d9bb 176 $dbman->change_field_precision($table, $field);
fa162144 177 upgrade_main_savepoint($result, 2008051203);
178 }
179
38fb8190 180 if ($result && $oldversion < 2008063001) {
775f811a 181 upgrade_set_timeout(60*20); // this may take a while
182
38fb8190 183 // table to be modified
184 $table = new xmldb_table('tag_instance');
185 // add field
186 $field = new xmldb_field('tiuserid');
187 if (!$dbman->field_exists($table, $field)) {
2a88f626 188 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'itemid');
38fb8190 189 $dbman->add_field($table, $field);
190 }
191 // modify index
192 $index = new xmldb_index('itemtype-itemid-tagid');
193 $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));
b91de8a5 194 if ($dbman->index_exists($table, $index)) {
195 $dbman->drop_index($table, $index);
196 }
38fb8190 197 $index = new xmldb_index('itemtype-itemid-tagid-tiuserid');
198 $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
b91de8a5 199 if (!$dbman->index_exists($table, $index)) {
200 $dbman->add_index($table, $index);
201 }
38fb8190 202
203 /// Main savepoint reached
204 upgrade_main_savepoint($result, 2008063001);
205 }
38fb8190 206
a036d7f3 207 if ($result && $oldversion < 2008070300) {
208 $result = $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false));
209 upgrade_main_savepoint($result, 2008070300);
210 }
4e781c7b 211
fe074586 212 if ($result && $oldversion < 2008070700) {
213 if (isset($CFG->defaultuserroleid) and isset($CFG->guestroleid) and $CFG->defaultuserroleid == $CFG->guestroleid) {
214 // guest can not be selected in defaultuserroleid!
215 unset_config('defaultuserroleid');
216 }
217 upgrade_main_savepoint($result, 2008070700);
218 }
219
ac5efef6 220 if ($result && $oldversion < 2008070701) {
221
222 /// Define table portfolio_instance to be created
223 $table = new xmldb_table('portfolio_instance');
224
225 /// Adding fields to table portfolio_instance
2a88f626 226 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
227 $table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
228 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
229 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
ac5efef6 230
231 /// Adding keys to table portfolio_instance
232 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
233
234 /// Conditionally launch create table for portfolio_instance
235 if (!$dbman->table_exists($table)) {
236 $dbman->create_table($table);
237 }
238 /// Define table portfolio_instance_config to be created
239 $table = new xmldb_table('portfolio_instance_config');
240
241 /// Adding fields to table portfolio_instance_config
2a88f626 242 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
243 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
244 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
245 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
ac5efef6 246
247 /// Adding keys to table portfolio_instance_config
248 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
249 $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
250
251 /// Adding indexes to table portfolio_instance_config
252 $table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name'));
253
254 /// Conditionally launch create table for portfolio_instance_config
255 if (!$dbman->table_exists($table)) {
256 $dbman->create_table($table);
257 }
258
259 /// Define table portfolio_instance_user to be created
260 $table = new xmldb_table('portfolio_instance_user');
261
262 /// Adding fields to table portfolio_instance_user
2a88f626 263 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
264 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
265 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
266 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
267 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
ac5efef6 268
269 /// Adding keys to table portfolio_instance_user
270 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
271 $table->add_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
272 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
273
274 /// Conditionally launch create table for portfolio_instance_user
275 if (!$dbman->table_exists($table)) {
276 $dbman->create_table($table);
277 }
278
279 /// Main savepoint reached
280 upgrade_main_savepoint($result, 2008070701);
281 }
172dd12c 282
775f811a 283 if ($result && $oldversion < 2008072400) {
284 /// Create the database tables for message_processors
f65b2dae 285 $table = new xmldb_table('message_processors');
2a88f626 286 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
287 $table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null);
f65b2dae 288 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3b120e46 289 $dbman->create_table($table);
290
3b120e46 291 /// delete old and create new fields
f65b2dae 292 $table = new xmldb_table('message');
293 $field = new xmldb_field('messagetype');
3b120e46 294 $dbman->drop_field($table, $field);
295
296 /// fields to rename
f65b2dae 297 $field = new xmldb_field('message');
2a88f626 298 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
3b120e46 299 $dbman->rename_field($table, $field, 'fullmessage');
f65b2dae 300 $field = new xmldb_field('format');
2a88f626 301 $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null);
3b120e46 302 $dbman->rename_field($table, $field, 'fullmessageformat');
303
304 /// new message fields
f65b2dae 305 $field = new xmldb_field('subject');
2a88f626 306 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
3b120e46 307 $dbman->add_field($table, $field);
f65b2dae 308 $field = new xmldb_field('fullmessagehtml');
2a88f626 309 $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null);
3b120e46 310 $dbman->add_field($table, $field);
f65b2dae 311 $field = new xmldb_field('smallmessage');
2a88f626 312 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
3b120e46 313 $dbman->add_field($table, $field);
314
315
f65b2dae 316 $table = new xmldb_table('message_read');
317 $field = new xmldb_field('messagetype');
3b120e46 318 $dbman->drop_field($table, $field);
f65b2dae 319 $field = new xmldb_field('mailed');
3b120e46 320 $dbman->drop_field($table, $field);
321
322 /// fields to rename
f65b2dae 323 $field = new xmldb_field('message');
2a88f626 324 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
3b120e46 325 $dbman->rename_field($table, $field, 'fullmessage');
f65b2dae 326 $field = new xmldb_field('format');
2a88f626 327 $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null);
3b120e46 328 $dbman->rename_field($table, $field, 'fullmessageformat');
329
330
331 /// new message fields
f65b2dae 332 $field = new xmldb_field('subject');
2a88f626 333 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
3b120e46 334 $dbman->add_field($table, $field);
f65b2dae 335 $field = new xmldb_field('fullmessagehtml');
2a88f626 336 $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null);
3b120e46 337 $dbman->add_field($table, $field);
f65b2dae 338 $field = new xmldb_field('smallmessage');
2a88f626 339 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
3b120e46 340 $dbman->add_field($table, $field);
341
342 /// new table
f65b2dae 343 $table = new xmldb_table('message_working');
2a88f626 344 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
345 $table->add_field('unreadmessageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
346 $table->add_field('processorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
f65b2dae 347 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3b120e46 348 $dbman->create_table($table);
349
350
351 upgrade_main_savepoint($result, 2008072400);
352 }
353
4e781c7b 354 if ($result && $oldversion < 2008072800) {
355
356 /// Define field enablecompletion to be added to course
357 $table = new xmldb_table('course');
358 $field = new xmldb_field('enablecompletion');
2a88f626 359 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'defaultrole');
4e781c7b 360
361 /// Launch add field enablecompletion
775f811a 362 if (!$dbman->field_exists($table,$field)) {
4e781c7b 363 $dbman->add_field($table, $field);
364 }
775f811a 365
4e781c7b 366 /// Define field completion to be added to course_modules
367 $table = new xmldb_table('course_modules');
368 $field = new xmldb_field('completion');
2a88f626 369 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'groupmembersonly');
4e781c7b 370
371 /// Launch add field completion
775f811a 372 if (!$dbman->field_exists($table,$field)) {
4e781c7b 373 $dbman->add_field($table, $field);
374 }
375
376 /// Define field completiongradeitemnumber to be added to course_modules
377 $field = new xmldb_field('completiongradeitemnumber');
2a88f626 378 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'completion');
4e781c7b 379
380 /// Launch add field completiongradeitemnumber
775f811a 381 if (!$dbman->field_exists($table,$field)) {
4e781c7b 382 $dbman->add_field($table, $field);
383 }
384
385 /// Define field completionview to be added to course_modules
386 $field = new xmldb_field('completionview');
2a88f626 387 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completiongradeitemnumber');
4e781c7b 388
389 /// Launch add field completionview
775f811a 390 if (!$dbman->field_exists($table,$field)) {
4e781c7b 391 $dbman->add_field($table, $field);
392 }
393
394 /// Define field completionexpected to be added to course_modules
395 $field = new xmldb_field('completionexpected');
2a88f626 396 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionview');
4e781c7b 397
398 /// Launch add field completionexpected
775f811a 399 if (!$dbman->field_exists($table,$field)) {
4e781c7b 400 $dbman->add_field($table, $field);
401 }
402
403 /// Define table course_modules_completion to be created
404 $table = new xmldb_table('course_modules_completion');
775f811a 405 if (!$dbman->table_exists($table)) {
4e781c7b 406
407 /// Adding fields to table course_modules_completion
2a88f626 408 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
409 $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
410 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
411 $table->add_field('completionstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
412 $table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null);
413 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
775f811a 414
4e781c7b 415 /// Adding keys to table course_modules_completion
1e0c56ea 416 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
775f811a 417
4e781c7b 418 /// Adding indexes to table course_modules_completion
1e0c56ea 419 $table->add_index('coursemoduleid', XMLDB_INDEX_NOTUNIQUE, array('coursemoduleid'));
420 $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
775f811a 421
4e781c7b 422 /// Launch create table for course_modules_completion
423 $dbman->create_table($table);
424 }
425
426 /// Main savepoint reached
427 upgrade_main_savepoint($result, 2008072800);
428 }
775f811a 429
4ab16a09 430 if ($result && $oldversion < 2008073000) {
ac5efef6 431
4ab16a09 432 /// Define table portfolio_log to be created
433 $table = new xmldb_table('portfolio_log');
434
435 /// Adding fields to table portfolio_log
2a88f626 436 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
437 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
438 $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
439 $table->add_field('portfolio', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
440 $table->add_field('caller_class', XMLDB_TYPE_CHAR, '150', null, XMLDB_NOTNULL, null, null);
441 $table->add_field('caller_file', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
442 $table->add_field('caller_sha1', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
4ab16a09 443
444 /// Adding keys to table portfolio_log
445 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
446 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
447 $table->add_key('portfoliofk', XMLDB_KEY_FOREIGN, array('portfolio'), 'portfolio_instance', array('id'));
448
449 /// Conditionally launch create table for portfolio_log
450 if (!$dbman->table_exists($table)) {
451 $dbman->create_table($table);
452 }
453
454 /// Main savepoint reached
455 upgrade_main_savepoint($result, 2008073000);
456 }
120b3758 457
458 if ($result && $oldversion < 2008073104) {
459 /// Drop old table that might exist for some people
460 $table = new xmldb_table('message_providers');
461 if ($dbman->table_exists($table)) {
462 $dbman->drop_table($table);
463 }
464
465 /// Define table message_providers to be created
466 $table = new xmldb_table('message_providers');
467
468 /// Adding fields to table message_providers
2a88f626 469 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
470 $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
471 $table->add_field('component', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
472 $table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null);
120b3758 473
474 /// Adding keys to table message_providers
475 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
476
477 /// Adding indexes to table message_providers
478 $table->add_index('componentname', XMLDB_INDEX_UNIQUE, array('component', 'name'));
479
480 /// Create table for message_providers
481 $dbman->create_table($table);
482
483 upgrade_main_savepoint($result, 2008073104);
484 }
172dd12c 485
486 if ($result && $oldversion < 2008073111) {
487 /// Define table files to be created
488 $table = new xmldb_table('files');
489
490 /// Adding fields to table files
2a88f626 491 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
492 $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
493 $table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
494 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
495 $table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
496 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
497 $table->add_field('filepath', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
498 $table->add_field('filename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
499 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
500 $table->add_field('filesize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
501 $table->add_field('mimetype', XMLDB_TYPE_CHAR, '100', null, null, null, null);
502 $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
503 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
504 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
172dd12c 505
506 /// Adding keys to table files
507 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
508 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
509 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
510
511 /// Adding indexes to table files
512 $table->add_index('filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('filearea', 'contextid', 'itemid'));
513 $table->add_index('contenthash', XMLDB_INDEX_NOTUNIQUE, array('contenthash'));
514 $table->add_index('pathnamehash', XMLDB_INDEX_UNIQUE, array('pathnamehash'));
515
516 /// Conditionally launch create table for files
517 $dbman->create_table($table);
518
519 /// Main savepoint reached
520 upgrade_main_savepoint($result, 2008073111);
521 }
522
172dd12c 523 if ($result && $oldversion < 2008073113) {
524 /// move all course, backup and other files to new filepool based storage
525 upgrade_migrate_files_courses();
526 /// Main savepoint reached
527 upgrade_main_savepoint($result, 2008073113);
528 }
529
530 if ($result && $oldversion < 2008073114) {
531 /// move all course, backup and other files to new filepool based storage
532 upgrade_migrate_files_blog();
533 /// Main savepoint reached
534 upgrade_main_savepoint($result, 2008073114);
535 }
f33e1ed4 536
1ce2da58 537 if ($result && $oldversion < 2008080400) {
538 // Add field ssl_jump_url to mnet application, and populate existing default applications
539 $table = new xmldb_table('mnet_application');
540 $field = new xmldb_field('sso_jump_url');
541 if (!$dbman->field_exists($table, $field)) {
2a88f626 542 $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
c5a04d12 543 $dbman->add_field($table, $field);
544 $result = $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle'));
1ce2da58 545 $result = $result && $DB->set_field('mnet_application', 'sso_jump_url', '/auth/xmlrpc/jump.php', array('name' => 'mahara'));
546 }
547
548 /// Main savepoint reached
549 upgrade_main_savepoint($result, 2008080400);
550 }
04f35360 551
552 if ($result && $oldversion < 2008080500) {
553
554 /// Define table portfolio_tempdata to be created
555 $table = new xmldb_table('portfolio_tempdata');
556
557 /// Adding fields to table portfolio_tempdata
2a88f626 558 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
559 $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
04f35360 560
561 /// Adding keys to table portfolio_tempdata
562 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
563
564 /// Conditionally launch create table for portfolio_tempdata
565 if (!$dbman->table_exists($table)) {
566 $dbman->create_table($table);
567 }
568
569 /// Main savepoint reached
570 upgrade_main_savepoint($result, 2008080500);
571 }
572
84a44985 573 if ($result && $oldversion < 2008080600) {
574
575 $DB->delete_records('portfolio_tempdata'); // there shouldnt' be any, and it will cause problems with this upgrade.
576 /// Define field expirytime to be added to portfolio_tempdata
577 $table = new xmldb_table('portfolio_tempdata');
2a88f626 578 $field = new xmldb_field('expirytime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'data');
84a44985 579
580 /// Conditionally launch add field expirytime
581 if (!$dbman->field_exists($table, $field)) {
582 $dbman->add_field($table, $field);
583 }
584
585 /// Main savepoint reached
586 upgrade_main_savepoint($result, 2008080600);
587 }
775f811a 588
c1f58efe 589 if ($result && $oldversion < 2008081500) {
590 /// Changing the type of all the columns that the question bank uses to store grades to be NUMBER(12, 7).
591 $table = new xmldb_table('question');
592 $field = new xmldb_field('defaultgrade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'generalfeedback');
593 $dbman->change_field_type($table, $field);
594 upgrade_main_savepoint($result, 2008081500);
595 }
596
f9a2cf86 597 if ($result && $oldversion < 2008081501) {
598 $table = new xmldb_table('question');
2a88f626 599 $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'defaultgrade');
f9a2cf86 600 $dbman->change_field_type($table, $field);
601 upgrade_main_savepoint($result, 2008081501);
602 }
603
604 if ($result && $oldversion < 2008081502) {
605 $table = new xmldb_table('question_answers');
2a88f626 606 $field = new xmldb_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'answer');
f9a2cf86 607 $dbman->change_field_type($table, $field);
608 upgrade_main_savepoint($result, 2008081502);
609 }
610
611 if ($result && $oldversion < 2008081503) {
612 $table = new xmldb_table('question_sessions');
2a88f626 613 $field = new xmldb_field('sumpenalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'newgraded');
f9a2cf86 614 $dbman->change_field_type($table, $field);
615 upgrade_main_savepoint($result, 2008081503);
616 }
617
618 if ($result && $oldversion < 2008081504) {
619 $table = new xmldb_table('question_states');
2a88f626 620 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'event');
f9a2cf86 621 $dbman->change_field_type($table, $field);
622 upgrade_main_savepoint($result, 2008081504);
623 }
624
625 if ($result && $oldversion < 2008081505) {
626 $table = new xmldb_table('question_states');
2a88f626 627 $field = new xmldb_field('raw_grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'grade');
f9a2cf86 628 $dbman->change_field_type($table, $field);
629 upgrade_main_savepoint($result, 2008081505);
630 }
631
632 if ($result && $oldversion < 2008081506) {
633 $table = new xmldb_table('question_states');
2a88f626 634 $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'raw_grade');
f9a2cf86 635 $dbman->change_field_type($table, $field);
636 upgrade_main_savepoint($result, 2008081506);
637 }
638
775f811a 639 if ($result && $oldversion < 2008081600) {
640
641 /// all 1.9 sites and fresh installs must already be unicode, not needed anymore
642 unset_config('unicodedb');
643
644 /// Main savepoint reached
645 upgrade_main_savepoint($result, 2008081600);
646 }
647
ff2f69bc 648 if ($result && $oldversion < 2008081900) {
649 /// Define field userid to be added to portfolio_tempdata
650 $table = new xmldb_table('portfolio_tempdata');
2a88f626 651 $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'expirytime');
ff2f69bc 652
653 /// Conditionally launch add field userid
654 if (!$dbman->field_exists($table, $field)) {
655 $dbman->add_field($table, $field);
656 }
657 $DB->set_field('portfolio_tempdata', 'userid', 0);
658 /// now change it to be notnull
659
660 /// Changing nullability of field userid on table portfolio_tempdata to not null
2a88f626 661 $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'expirytime');
ff2f69bc 662
663 /// Launch change of nullability for field userid
664 $dbman->change_field_notnull($table, $field);
665
666 /// Define key userfk (foreign) to be added to portfolio_tempdata
667 $table = new xmldb_table('portfolio_tempdata');
668 $key = new xmldb_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
669
670 /// Launch add key userfk
671 $dbman->add_key($table, $key);
672
673 upgrade_main_savepoint($result, 2008081900);
674 }
8f3f6cc3 675 if ($result && $oldversion < 2008082602) {
27051e43 676
677 /// Define table repository to be dropped
678 $table = new xmldb_table('repository');
679
680 /// Conditionally launch drop table for repository
681 if ($dbman->table_exists($table)) {
682 $dbman->drop_table($table);
683 }
684
685 /// Define table repository to be created
686 $table = new xmldb_table('repository');
687
688 /// Adding fields to table repository
2a88f626 689 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
690 $table->add_field('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
691 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '1');
692 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
27051e43 693
694 /// Adding keys to table repository
695 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
696
697 /// Conditionally launch create table for repository
698 if (!$dbman->table_exists($table)) {
699 $dbman->create_table($table);
700 }
701 /// Define table repository_instances to be created
702 $table = new xmldb_table('repository_instances');
703
704 /// Adding fields to table repository_instances
2a88f626 705 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
706 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
707 $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
708 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
709 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
710 $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null);
711 $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null);
712 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
713 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
27051e43 714
715 /// Adding keys to table repository_instances
716 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
717
718 /// Conditionally launch create table for repository_instances
719 if (!$dbman->table_exists($table)) {
720 $dbman->create_table($table);
721 }
722
723 /// Define table repository_instance_config to be created
724 $table = new xmldb_table('repository_instance_config');
725
726 /// Adding fields to table repository_instance_config
2a88f626 727 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
728 $table->add_field('instanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
729 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
730 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
27051e43 731
732 /// Adding keys to table repository_instance_config
733 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
734
735 /// Conditionally launch create table for repository_instance_config
736 if (!$dbman->table_exists($table)) {
737 $dbman->create_table($table);
738 }
739
740 /// Main savepoint reached
8f3f6cc3 741 upgrade_main_savepoint($result, 2008082602);
27051e43 742 }
743
62e76c67 744 if ($result && $oldversion < 2008082700) {
745 /// Add a new column to the question sessions table to record whether a
746 /// question has been flagged.
747
748 /// Define field flagged to be added to question_sessions
749 $table = new xmldb_table('question_sessions');
2a88f626 750 $field = new xmldb_field('flagged', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'manualcomment');
62e76c67 751
752 /// Conditionally launch add field flagged
753 if (!$dbman->field_exists($table, $field)) {
754 $dbman->add_field($table, $field);
755 }
756
757 /// Main savepoint reached
758 upgrade_main_savepoint($result, 2008082700);
759 }
ff2f69bc 760
2c48aeab 761 if ($result && $oldversion < 2008082900) {
762
763 /// Changing precision of field parent_type on table mnet_rpc to (20)
764 $table = new xmldb_table('mnet_rpc');
2a88f626 765 $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path');
2c48aeab 766
767 /// Launch change of precision for field parent_type
768 $dbman->change_field_precision($table, $field);
769
770 /// Main savepoint reached
771 upgrade_main_savepoint($result, 2008082900);
772 }
773
ff7e7f92 774 if ($result && $oldversion < 2008090108) {
775 $repo = new object();
776 $repo->type = 'upload';
777 $repo->visible = 1;
778 $repo->sortorder = 1;
779 if (!$DB->record_exists('repository', array('type'=>'upload'))) {
780 $typeid = $DB->insert_record('repository', $repo);
781 }else{
782 $record = $DB->get_record('repository', array('type'=>'upload'));
783 $typeid = $record->id;
784 }
785 if (!$DB->record_exists('repository_instances', array('typeid'=>$typeid))) {
786 $instance = new object();
fb7cae3b 787 $instance->name = get_string('repositoryname', 'repository_upload');
ff7e7f92 788 $instance->typeid = $typeid;
789 $instance->userid = 0;
790 $instance->contextid = SITEID;
791 $instance->timecreated = time();
792 $instance->timemodified = time();
793 $result = $result && $DB->insert_record('repository_instances', $instance);
794 }
795 $repo->type = 'local';
796 $repo->visible = 1;
797 $repo->sortorder = 1;
798 if (!$DB->record_exists('repository', array('type'=>'local'))) {
799 $typeid = $DB->insert_record('repository', $repo);
800 }else{
801 $record = $DB->get_record('repository', array('type'=>'local'));
802 $typeid = $record->id;
803 }
804 if (!$DB->record_exists('repository_instances', array('typeid'=>$typeid))) {
805 $instance = new object();
fb7cae3b 806 $instance->name = get_string('repositoryname', 'repository_local');
ff7e7f92 807 $instance->typeid = $typeid;
808 $instance->userid = 0;
809 $instance->contextid = SITEID;
810 $instance->timecreated = time();
811 $instance->timemodified = time();
812 $result = $result && $DB->insert_record('repository_instances', $instance);
813 }
814
815 upgrade_main_savepoint($result, 2008090108);
816 }
817
d849880e 818 // MDL-16411 Move all plugintype_pluginname_version values from config to config_plugins.
819 if ($result && $oldversion < 2008091000) {
820 foreach (get_object_vars($CFG) as $name => $value) {
821 if (substr($name, strlen($name) - 8) !== '_version') {
822 continue;
823 }
824 $pluginname = substr($name, 0, strlen($name) - 8);
825 if (!strpos($pluginname, '_')) {
826 // Skip things like backup_version that don't contain an extra _
827 continue;
828 }
829 if ($pluginname == 'enrol_ldap_version') {
830 // Special case - this is something different from a plugin version number.
831 continue;
832 }
6f49dd0f 833 if (!preg_match('/^\d{10}$/', $value)) {
d849880e 834 // Extra safety check, skip anything that does not look like a Moodle
835 // version number (10 digits).
836 continue;
837 }
838 $result = $result && set_config('version', $value, $pluginname);
839 $result = $result && unset_config($name);
840 }
841 upgrade_main_savepoint($result, 2008091000);
842 }
843
948c2860 844 //Add a readonly field to the repository_instances table
845 //in order to support instance created automatically by a repository plugin
846 if ($result && $oldversion < 2008091611) {
847
848 /// Define field readonly to be added to repository_instances
849 $table = new xmldb_table('repository_instances');
2a88f626 850 $field = new xmldb_field('readonly', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timemodified');
948c2860 851
852 /// Conditionally launch add field readonly
853 if (!$dbman->field_exists($table, $field)) {
854 $dbman->add_field($table, $field);
855 }
856
857 /// Main savepoint reached
858 upgrade_main_savepoint($result, 2008091611);
859 }
860
53b20fe3 861 if ($result && $oldversion < 2008092300) {
862 unset_config('editorspelling');
863 unset_config('editordictionary');
864 /// Main savepoint reached
865 upgrade_main_savepoint($result, 2008092300);
866 }
867
a7df430b 868 if ($result && $oldversion < 2008101000) {
869
870 /// Changing the default of field lang on table user to en_utf8
871 $table = new xmldb_table('user');
2a88f626 872 $field = new xmldb_field('lang', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, 'en_utf8', 'country');
a7df430b 873
874 /// Launch change of default for field lang
875 $dbman->change_field_default($table, $field);
876
877 /// Main savepoint reached
878 upgrade_main_savepoint($result, 2008101000);
879 }
880
5e7206a8 881 if ($result && $oldversion < 2008101300) {
882
d9e673c1 883 if (!get_config(NULL, 'statsruntimedays')) {
5e7206a8 884 set_config('statsruntimedays', '31');
885 }
886
887 /// Main savepoint reached
888 upgrade_main_savepoint($result, 2008101300);
889 }
53b20fe3 890
01a80f51 891 /// New table for storing which roles can be assigned in which contexts.
892 if ($result && $oldversion < 2008110601) {
893
894 /// Define table role_context_levels to be created
895 $table = new xmldb_table('role_context_levels');
896
897 /// Adding fields to table role_context_levels
2a88f626 898 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
899 $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
900 $table->add_field('contextlevel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
01a80f51 901
902 /// Adding keys to table role_context_levels
903 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
904 $table->add_key('contextlevel-roleid', XMLDB_KEY_UNIQUE, array('contextlevel', 'roleid'));
905 $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
906
907 /// Conditionally launch create table for role_context_levels
908 if (!$dbman->table_exists($table)) {
909 $dbman->create_table($table);
910 }
911
912 /// Main savepoint reached
913 upgrade_main_savepoint($result, 2008110601);
914 }
915
916 /// Now populate the role_context_levels table with the defaults that match
917 /// moodle_install_roles, and any other combinations that exist in this system.
918 if ($result && $oldversion < 2008110602) {
919 $roleids = $DB->get_records_menu('role', array(), '', 'shortname,id');
920
921 /// Defaults, should match moodle_install_roles.
922 $rolecontextlevels = array();
923 if (isset($roleids['admin'])) {
924 $rolecontextlevels[$roleids['admin']] = get_default_contextlevels('admin');
925 }
926 if (isset($roleids['coursecreator'])) {
927 $rolecontextlevels[$roleids['coursecreator']] = get_default_contextlevels('coursecreator');
928 }
929 if (isset($roleids['editingteacher'])) {
930 $rolecontextlevels[$roleids['editingteacher']] = get_default_contextlevels('editingteacher');
931 }
932 if (isset($roleids['teacher'])) {
933 $rolecontextlevels[$roleids['teacher']] = get_default_contextlevels('teacher');
934 }
935 if (isset($roleids['student'])) {
936 $rolecontextlevels[$roleids['student']] = get_default_contextlevels('student');
937 }
938 if (isset($roleids['guest'])) {
939 $rolecontextlevels[$roleids['guest']] = get_default_contextlevels('guest');
940 }
941 if (isset($roleids['user'])) {
942 $rolecontextlevels[$roleids['user']] = get_default_contextlevels('user');
943 }
656be893 944
01a80f51 945 /// See what other role assignments are in this database, extend the allowed
946 /// lists to allow them too.
947 $existingrolecontextlevels = $DB->get_recordset_sql('SELECT DISTINCT ra.roleid, con.contextlevel FROM
948 {role_assignments} ra JOIN {context} con ON ra.contextid = con.id');
949 foreach ($existingrolecontextlevels as $rcl) {
950 if (!isset($rolecontextlevels[$rcl->roleid])) {
951 $rolecontextlevels[$rcl->roleid] = array($rcl->contextlevel);
952 } else if (!in_array($rcl->contextlevel, $rolecontextlevels[$rcl->roleid])) {
953 $rolecontextlevels[$rcl->roleid][] = $rcl->contextlevel;
954 }
955 }
956
957 /// Put the data into the database.
958 foreach ($rolecontextlevels as $roleid => $contextlevels) {
959 set_role_contextlevels($roleid, $contextlevels);
960 }
961
962 /// Main savepoint reached
963 upgrade_main_savepoint($result, 2008110602);
964 }
965
06de498b 966 /// Remove any role overrides for moodle/site:doanything, or any permissions
967 /// for it in a role without legacy:admin.
968 if ($result && $oldversion < 2008110603) {
969 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
970
971 // Remove all overrides.
972 $DB->delete_records_select('role_capabilities', 'capability = ? AND contextid <> ?', array('moodle/site:doanything', $systemcontext->id));
973
974 // Get the ids of all the roles that are moodle/legacy:admin.
975 $adminroleids = $DB->get_records_menu('role_capabilities',
976 array('capability' => 'moodle/legacy:admin', 'permission' => 1, 'contextid' => $systemcontext->id),
977 '', 'id, roleid');
978
979 // Remove moodle/site:doanything from all other roles.
980 list($notroletest, $params) = $DB->get_in_or_equal($adminroleids, SQL_PARAMS_QM, '', false);
981 $DB->delete_records_select('role_capabilities', "roleid $notroletest AND capability = ? AND contextid = ?",
982 array_merge($params, array('moodle/site:doanything', $systemcontext->id)));
983
984 // Ensure that for all admin-y roles, the permission for moodle/site:doanything is 1
985 list($isroletest, $params) = $DB->get_in_or_equal($adminroleids);
986 $DB->set_field_select('role_capabilities', 'permission', 1,
987 "roleid $isroletest AND capability = ? AND contextid = ?",
988 array_merge($params, array('moodle/site:doanything', $systemcontext->id)));
989
990 // And for any admin-y roles where moodle/site:doanything is not set, set it.
991 $doanythingroleids = $DB->get_records_menu('role_capabilities',
992 array('capability' => 'moodle/site:doanything', 'permission' => 1, 'contextid' => $systemcontext->id),
993 '', 'id, roleid');
994 foreach ($adminroleids as $roleid) {
995 if (!in_array($roleid, $doanythingroleids)) {
996 $rc = new stdClass;
997 $rc->contextid = $systemcontext->id;
998 $rc->roleid = $roleid;
999 $rc->capability = 'moodle/site:doanything';
1000 $rc->permission = 1;
1001 $rc->timemodified = time();
1002 $DB->insert_record('role_capabilities', $rc);
1003 }
1004 }
1005
1006 /// Main savepoint reached
1007 upgrade_main_savepoint($result, 2008110603);
1008 }
1009
9101efd3 1010 /// Drop the deprecated teacher, teachers, student and students columns from the course table.
1011 if ($result && $oldversion < 2008111200) {
1012 $table = new xmldb_table('course');
1013
1014 /// Conditionally launch drop field teacher
1015 $field = new xmldb_field('teacher');
1016 if ($dbman->field_exists($table, $field)) {
1017 $dbman->drop_field($table, $field);
1018 }
1019
1020 /// Conditionally launch drop field teacher
1021 $field = new xmldb_field('teachers');
1022 if ($dbman->field_exists($table, $field)) {
1023 $dbman->drop_field($table, $field);
1024 }
1025
1026 /// Conditionally launch drop field teacher
1027 $field = new xmldb_field('student');
1028 if ($dbman->field_exists($table, $field)) {
1029 $dbman->drop_field($table, $field);
1030 }
1031
1032 /// Conditionally launch drop field teacher
1033 $field = new xmldb_field('students');
1034 if ($dbman->field_exists($table, $field)) {
1035 $dbman->drop_field($table, $field);
1036 }
1037
1038 /// Main savepoint reached
1039 upgrade_main_savepoint($result, 2008111200);
1040 }
1041
40c792c3 1042/// Add a unique index to the role.name column.
1043 if ($result && $oldversion < 2008111800) {
1044
1045 /// Define index name (unique) to be added to role
1046 $table = new xmldb_table('role');
1047 $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name'));
1048
1049 /// Conditionally launch add index name
1050 if (!$dbman->index_exists($table, $index)) {
1051 $dbman->add_index($table, $index);
1052 }
1053
1054 /// Main savepoint reached
1055 upgrade_main_savepoint($result, 2008111800);
1056 }
1057
1058/// Add a unique index to the role.shortname column.
1059 if ($result && $oldversion < 2008111801) {
1060
1061 /// Define index shortname (unique) to be added to role
1062 $table = new xmldb_table('role');
1063 $index = new xmldb_index('shortname', XMLDB_INDEX_UNIQUE, array('shortname'));
1064
1065 /// Conditionally launch add index shortname
1066 if (!$dbman->index_exists($table, $index)) {
1067 $dbman->add_index($table, $index);
1068 }
1069
1070 /// Main savepoint reached
1071 upgrade_main_savepoint($result, 2008111801);
1072 }
1073
82bd6a5e 1074 if ($result && $oldversion < 2008120700) {
1075
1076 /// Changing precision of field shortname on table course_request to (100)
1077 $table = new xmldb_table('course_request');
2a88f626 1078 $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname');
82bd6a5e 1079
da750a51 1080 /// Before changing the field, drop dependent indexes
1081 /// Define index shortname (not unique) to be dropped form course_request
1082 $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname'));
1083 /// Conditionally launch drop index shortname
1084 if ($dbman->index_exists($table, $index)) {
1085 $dbman->drop_index($table, $index);
1086 }
1087
82bd6a5e 1088 /// Launch change of precision for field shortname
1089 $dbman->change_field_precision($table, $field);
1090
da750a51 1091 /// After changing the field, recreate dependent indexes
1092 /// Define index shortname (not unique) to be added to course_request
1093 $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname'));
1094 /// Conditionally launch add index shortname
1095 if (!$dbman->index_exists($table, $index)) {
1096 $dbman->add_index($table, $index);
1097 }
1098
82bd6a5e 1099 /// Main savepoint reached
1100 upgrade_main_savepoint($result, 2008120700);
1101 }
1102
1103 /// For MDL-17501. Ensure that any role that has moodle/course:update also
1104 /// has moodle/course:visibility.
1105 if ($result && $oldversion < 2008120800) {
1106 /// Get the roles with 'moodle/course:update'.
1107 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
1108 $roles = get_roles_with_capability('moodle/course:update', CAP_ALLOW, $systemcontext);
1109
1110 /// Give those roles 'moodle/course:visibility'.
1111 foreach ($roles as $role) {
1112 assign_capability('moodle/course:visibility', CAP_ALLOW, $role->id, $systemcontext->id);
1113 }
1114
1115 /// Force all sessions to refresh access data.
1116 mark_context_dirty($systemcontext->path);
1117
1118 /// Main savepoint reached
1119 upgrade_main_savepoint($result, 2008120800);
1120 }
1121
1122 if ($result && $oldversion < 2008120801) {
1123
1124 /// Changing precision of field shortname on table mnet_enrol_course to (100)
1125 $table = new xmldb_table('mnet_enrol_course');
2a88f626 1126 $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname');
82bd6a5e 1127
1128 /// Launch change of precision for field shortname
1129 $dbman->change_field_precision($table, $field);
1130
1131 /// Main savepoint reached
1132 upgrade_main_savepoint($result, 2008120801);
1133 }
1134
1135 if ($result && $oldversion < 2008121701) {
0953a4e7 1136
1137 /// Define field availablefrom to be added to course_modules
1138 $table = new xmldb_table('course_modules');
2a88f626 1139 $field = new xmldb_field('availablefrom', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionexpected');
0953a4e7 1140
1141 /// Conditionally launch add field availablefrom
1142 if (!$dbman->field_exists($table, $field)) {
1143 $dbman->add_field($table, $field);
1144 }
1145
1146 /// Define field availableuntil to be added to course_modules
2a88f626 1147 $field = new xmldb_field('availableuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availablefrom');
0953a4e7 1148
1149 /// Conditionally launch add field availableuntil
1150 if (!$dbman->field_exists($table, $field)) {
1151 $dbman->add_field($table, $field);
1152 }
82bd6a5e 1153
0953a4e7 1154 /// Define field showavailability to be added to course_modules
2a88f626 1155 $field = new xmldb_field('showavailability', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availableuntil');
0953a4e7 1156
1157 /// Conditionally launch add field showavailability
1158 if (!$dbman->field_exists($table, $field)) {
1159 $dbman->add_field($table, $field);
1160 }
82bd6a5e 1161
0953a4e7 1162 /// Define table course_modules_availability to be created
1163 $table = new xmldb_table('course_modules_availability');
1164
1165 /// Adding fields to table course_modules_availability
2a88f626 1166 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1167 $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1168 $table->add_field('sourcecmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
1169 $table->add_field('requiredcompletion', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null);
1170 $table->add_field('gradeitemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
1171 $table->add_field('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
1172 $table->add_field('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
0953a4e7 1173
1174 /// Adding keys to table course_modules_availability
1175 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
cbb17d54 1176 $table->add_key('coursemoduleid', XMLDB_KEY_FOREIGN, array('coursemoduleid'), 'course_modules', array('id'));
1177 $table->add_key('sourcecmid', XMLDB_KEY_FOREIGN, array('sourcecmid'), 'course_modules', array('id'));
1178 $table->add_key('gradeitemid', XMLDB_KEY_FOREIGN, array('gradeitemid'), 'grade_items', array('id'));
0953a4e7 1179
1180 /// Conditionally launch create table for course_modules_availability
1181 if (!$dbman->table_exists($table)) {
1182 $dbman->create_table($table);
1183 }
1184
82bd6a5e 1185 /// Changes to modinfo mean we need to rebuild course cache
a9a0b93d 1186 require_once($CFG->dirroot . '/course/lib.php');
8b6a0968 1187 rebuild_course_cache(0, true);
9136a60c 1188
82bd6a5e 1189 /// For developer upgrades, turn on the conditional activities and completion
1190 /// features automatically (to gain more testing)
8b6a0968 1191//TODO: remove before 2.0 final!
1192 if (debugging('', DEBUG_DEVELOPER)) {
1193 set_config('enableavailability', 1);
1194 set_config('enablecompletion', 1);
9136a60c 1195 }
1196
9d510a2e 1197 /// Main savepoint reached
82bd6a5e 1198 upgrade_main_savepoint($result, 2008121701);
9d510a2e 1199 }
1200
656be893 1201 if ($result && $oldversion < 2009010500) {
1202 /// clean up config table a bit
1203 unset_config('session_error_counter');
1204
1205 /// Main savepoint reached
1206 upgrade_main_savepoint($result, 2009010500);
1207 }
1208
1209 if ($result && $oldversion < 2009010600) {
1210
1211 /// Define field originalquestion to be dropped from question_states
1212 $table = new xmldb_table('question_states');
1213 $field = new xmldb_field('originalquestion');
1214
1215 /// Conditionally launch drop field originalquestion
1216 if ($dbman->field_exists($table, $field)) {
1217 $dbman->drop_field($table, $field);
1218 }
1219
1220 /// Main savepoint reached
1221 upgrade_main_savepoint($result, 2009010600);
1222 }
1223
1224 if ($result && $oldversion < 2009010601) {
1225
1226 /// Changing precision of field ip on table log to (45)
1227 $table = new xmldb_table('log');
2a88f626 1228 $field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'userid');
656be893 1229
1230 /// Launch change of precision for field ip
1231 $dbman->change_field_precision($table, $field);
1232
1233 /// Main savepoint reached
1234 upgrade_main_savepoint($result, 2009010601);
1235 }
1236
1237 if ($result && $oldversion < 2009010602) {
1238
1239 /// Changing precision of field lastip on table user to (45)
1240 $table = new xmldb_table('user');
2a88f626 1241 $field = new xmldb_field('lastip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'currentlogin');
656be893 1242
1243 /// Launch change of precision for field lastip
1244 $dbman->change_field_precision($table, $field);
1245
1246 /// Main savepoint reached
1247 upgrade_main_savepoint($result, 2009010602);
1248 }
1249
1250 if ($result && $oldversion < 2009010603) {
1251
1252 /// Changing precision of field ip_address on table mnet_host to (45)
1253 $table = new xmldb_table('mnet_host');
2a88f626 1254 $field = new xmldb_field('ip_address', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'wwwroot');
656be893 1255
1256 /// Launch change of precision for field ip_address
1257 $dbman->change_field_precision($table, $field);
1258
1259 /// Main savepoint reached
1260 upgrade_main_savepoint($result, 2009010603);
1261 }
1262
1263 if ($result && $oldversion < 2009010604) {
1264
1265 /// Changing precision of field ip on table mnet_log to (45)
1266 $table = new xmldb_table('mnet_log');
2a88f626 1267 $field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'userid');
656be893 1268
1269 /// Launch change of precision for field ip
1270 $dbman->change_field_precision($table, $field);
1271
1272 /// Main savepoint reached
1273 upgrade_main_savepoint($result, 2009010604);
1274 }
1275
4413941f 1276 if ($result && $oldversion < 2009010800) {
1277 /// Update the notifyloginfailures setting.
1278 if ($CFG->notifyloginfailures == 'mainadmin') {
1279 set_config('notifyloginfailures', get_admin()->username);
1280 } else if ($CFG->notifyloginfailures == 'alladmins') {
1281 set_config('notifyloginfailures', '$@ALL@$');
1282 } else {
1283 set_config('notifyloginfailures', '');
1284 }
1285
1286 /// Main savepoint reached
1287 upgrade_main_savepoint($result, 2009010800);
1288 }
1289
ab2eb65c 1290 if ($result && $oldversion < 2009011000) {
1291
1292 /// Changing nullability of field configdata on table block_instance to null
1293 $table = new xmldb_table('block_instance');
1294 $field = new xmldb_field('configdata');
2a88f626 1295 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'visible');
ab2eb65c 1296
1297 /// Launch change of nullability for field configdata
1298 $dbman->change_field_notnull($table, $field);
1299
1300 /// Main savepoint reached
1301 upgrade_main_savepoint($result, 2009011000);
1302 }
1303
1caea91e 1304 if ($result && $oldversion < 2009011100) {
1305 /// Remove unused settings
1306 unset_config('zip');
1307 unset_config('unzip');
1308 unset_config('adminblocks_initialised');
1309
1310 /// Main savepoint reached
1311 upgrade_main_savepoint($result, 2009011100);
1312 }
1313
eb6a973c 1314 if ($result && $oldversion < 2009011101) {
1315 /// Migrate backup settings to core plugin config table
1316 $configs = $DB->get_records('backup_config');
1317 foreach ($configs as $config) {
1318 set_config($config->name, $config->value, 'backup');
1319 }
1320
1321 /// Define table to be dropped
1322 $table = new xmldb_table('backup_config');
1323
1324 /// Launch drop table for old backup config
1325 $dbman->drop_table($table);
1326
1327 /// Main savepoint reached
1328 upgrade_main_savepoint($result, 2009011101);
1329 }
1330
301bf0b2 1331 if ($result && $oldversion < 2009011303) {
1332
1333 /// Define table config_log to be created
1334 $table = new xmldb_table('config_log');
1335
1336 /// Adding fields to table config_log
2a88f626 1337 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1338 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1339 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1340 $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null);
1341 $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
1342 $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
1343 $table->add_field('oldvalue', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
301bf0b2 1344
1345 /// Adding keys to table config_log
1346 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1347 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1348
1349 /// Adding indexes to table config_log
1350 $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
1351
1352 /// Launch create table for config_log
1353 $dbman->create_table($table);
1354
1355 /// Main savepoint reached
1356 upgrade_main_savepoint($result, 2009011303);
1357 }
1358
b9fb7103 1359 if ($result && $oldversion < 2009011900) {
3f57bd45 1360
1361 /// Define table sessions2 to be dropped
1362 $table = new xmldb_table('sessions2');
1363
1364 /// Conditionally launch drop table for sessions
1365 if ($dbman->table_exists($table)) {
1366 $dbman->drop_table($table);
1367 }
1368
1369 /// Define table sessions to be dropped
1370 $table = new xmldb_table('sessions');
1371
1372 /// Conditionally launch drop table for sessions
1373 if ($dbman->table_exists($table)) {
1374 $dbman->drop_table($table);
1375 }
1376
1377 /// Define table sessions to be created
1378 $table = new xmldb_table('sessions');
1379
1380 /// Adding fields to table sessions
2a88f626 1381 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1382 $table->add_field('state', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
1383 $table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null);
1384 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1385 $table->add_field('sessdata', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
1386 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1387 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1388 $table->add_field('firstip', XMLDB_TYPE_CHAR, '45', null, null, null, null);
1389 $table->add_field('lastip', XMLDB_TYPE_CHAR, '45', null, null, null, null);
3f57bd45 1390
1391 /// Adding keys to table sessions
1392 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1393 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1394
1395 /// Adding indexes to table sessions
1396 $table->add_index('state', XMLDB_INDEX_NOTUNIQUE, array('state'));
1397 $table->add_index('sid', XMLDB_INDEX_UNIQUE, array('sid'));
1398 $table->add_index('timecreated', XMLDB_INDEX_NOTUNIQUE, array('timecreated'));
1399 $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
1400
1401 /// Launch create table for sessions
1402 $dbman->create_table($table);
1403
1404 /// Main savepoint reached
b9fb7103 1405 upgrade_main_savepoint($result, 2009011900);
3f57bd45 1406 }
1407
dc6f76b9 1408 if ($result && $oldversion < 2009012901) {
795a08ad 1409 // NOTE: this table may already exist, see beginning of this file ;-)
1f20942c 1410
1411 /// Define table upgrade_log to be created
1412 $table = new xmldb_table('upgrade_log');
1413
1414 /// Adding fields to table upgrade_log
2a88f626 1415 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1416 $table->add_field('type', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1417 $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null);
1418 $table->add_field('version', XMLDB_TYPE_CHAR, '100', null, null, null, null);
1419 $table->add_field('info', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
1420 $table->add_field('details', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
1421 $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
1422 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1423 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1f20942c 1424
1425 /// Adding keys to table upgrade_log
1426 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1427 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1428
1429 /// Adding indexes to table upgrade_log
1430 $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
1431 $table->add_index('type-timemodified', XMLDB_INDEX_NOTUNIQUE, array('type', 'timemodified'));
1432
1433 /// Conditionally launch create table for upgrade_log
1434 if (!$dbman->table_exists($table)) {
1435 $dbman->create_table($table);
1436 }
1437
1438 /// Main savepoint reached
dc6f76b9 1439 upgrade_main_savepoint($result, 2009012901);
1f20942c 1440 }
1caea91e 1441
75564228 1442 if ($result && $oldversion < 2009021800) {
eb2761f8 1443 // Converting format of grade conditions, if any exist, to percentages.
75564228 1444 $DB->execute("
1445UPDATE {course_modules_availability} SET grademin=(
1446 SELECT 100.0*({course_modules_availability}.grademin-gi.grademin)
eb2761f8 1447 /(gi.grademax-gi.grademin)
1448 FROM {grade_items} gi
75564228 1449 WHERE gi.id={course_modules_availability}.gradeitemid)
1450WHERE gradeitemid IS NOT NULL AND grademin IS NOT NULL");
1451 $DB->execute("
1452UPDATE {course_modules_availability} SET grademax=(
1453 SELECT 100.0*({course_modules_availability}.grademax-gi.grademin)
eb2761f8 1454 /(gi.grademax-gi.grademin)
1455 FROM {grade_items} gi
75564228 1456 WHERE gi.id={course_modules_availability}.gradeitemid)
1457WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
1458
1459 /// Main savepoint reached
1460 upgrade_main_savepoint($result, 2009021800);
1461 }
bc7ec91a 1462 if ($result && $oldversion < 2009021801) {
1463 /// Define field backuptype to be added to backup_log
382123a0 1464 $table = new xmldb_table('backup_log');
2a88f626 1465 $field = new xmldb_field('backuptype', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, 'info');
bc7ec91a 1466 /// Conditionally Launch add field backuptype and set all old records as 'scheduledbackup' records.
1467 if (!$dbman->field_exists($table, $field)) {
1468 $dbman->add_field($table, $field);
1469 $DB->execute("UPDATE {backup_log} SET backuptype='scheduledbackup'");
1470 }
75564228 1471
bc7ec91a 1472 /// Main savepoint reached
1473 upgrade_main_savepoint($result, 2009021801);
1474 }
af52ecee 1475 /// Add default sort order for question types.
1476 if ($result && $oldversion < 2009030300) {
1477 set_config('multichoice_sortorder', 1, 'question');
1478 set_config('truefalse_sortorder', 2, 'question');
1479 set_config('shortanswer_sortorder', 3, 'question');
1480 set_config('numerical_sortorder', 4, 'question');
1481 set_config('calculated_sortorder', 5, 'question');
1482 set_config('essay_sortorder', 6, 'question');
1483 set_config('match_sortorder', 7, 'question');
1484 set_config('randomsamatch_sortorder', 8, 'question');
1485 set_config('multianswer_sortorder', 9, 'question');
1486 set_config('description_sortorder', 10, 'question');
1487 set_config('random_sortorder', 11, 'question');
1488 set_config('missingtype_sortorder', 12, 'question');
1489
1490 upgrade_main_savepoint($result, 2009030300);
1491 }
a75c78d3 1492 if ($result && $oldversion < 2009030501) {
1493 /// setup default repository plugins
1494 require_once($CFG->dirroot . '/repository/lib.php');
1495 repository_setup_default_plugins();
1496 /// Main savepoint reached
1497 upgrade_main_savepoint($result, 2009030501);
1498 }
af52ecee 1499
82701e24 1500 /// MDL-18132 replace the use a new Role allow switch settings page, instead of
1501 /// $CFG->allowuserswitchrolestheycantassign
1502 if ($result && $oldversion < 2009032000) {
1503 /// First create the new table.
1504 $table = new xmldb_table('role_allow_switch');
1505
1506 /// Adding fields to table role_allow_switch
2a88f626 1507 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1508 $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1509 $table->add_field('allowswitch', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
82701e24 1510
1511 /// Adding keys to table role_allow_switch
1512 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1513 $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
1514 $table->add_key('allowswitch', XMLDB_KEY_FOREIGN, array('allowswitch'), 'role', array('id'));
1515
1516 /// Adding indexes to table role_allow_switch
1517 $table->add_index('roleid-allowoverride', XMLDB_INDEX_UNIQUE, array('roleid', 'allowswitch'));
1518
1519 /// Conditionally launch create table for role_allow_switch
1520 if (!$dbman->table_exists($table)) {
1521 $dbman->create_table($table);
1522 }
1523
1524 /// Main savepoint reached
1525 upgrade_main_savepoint($result, 2009032000);
1526 }
0fc9c009 1527
82701e24 1528 if ($result && $oldversion < 2009032001) {
1529 /// Copy from role_allow_assign into the new table.
dc740f97 1530 $DB->execute('INSERT INTO {role_allow_switch} (roleid, allowswitch)
1531 SELECT roleid, allowassign FROM {role_allow_assign}');
82701e24 1532
1533 /// Unset the config variable used in 1.9.
1534 unset_config('allowuserswitchrolestheycantassign');
1535
1536 /// Main savepoint reached
1537 upgrade_main_savepoint($result, 2009032001);
1538 }
c94985ef 1539
1540 if ($result && $oldversion < 2009033100) {
1541 require_once("$CFG->dirroot/filter/tex/lib.php");
1542 filter_tex_updatedcallback(null);
1543 /// Main savepoint reached
1544 upgrade_main_savepoint($result, 2009033100);
1545 }
1546
0fc9c009 1547 if ($result && $oldversion < 2009040300) {
1548
1549 /// Define table filter_active to be created
1550 $table = new xmldb_table('filter_active');
1551
1552 /// Adding fields to table filter_active
2a88f626 1553 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1554 $table->add_field('filter', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
1555 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1556 $table->add_field('active', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null);
1557 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
0fc9c009 1558
1559 /// Adding keys to table filter_active
1560 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1561 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
1562
1563 /// Adding indexes to table filter_active
1564 $table->add_index('contextid-filter', XMLDB_INDEX_UNIQUE, array('contextid', 'filter'));
1565
1566 /// Conditionally launch create table for filter_active
1567 if (!$dbman->table_exists($table)) {
1568 $dbman->create_table($table);
1569 }
1570
1571 /// Main savepoint reached
1572 upgrade_main_savepoint($result, 2009040300);
1573 }
1574
1575 if ($result && $oldversion < 2009040301) {
1576
1577 /// Define table filter_config to be created
1578 $table = new xmldb_table('filter_config');
1579
1580 /// Adding fields to table filter_config
2a88f626 1581 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1582 $table->add_field('filter', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
1583 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1584 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
1585 $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
0fc9c009 1586
1587 /// Adding keys to table filter_config
1588 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1589 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
1590
1591 /// Adding indexes to table filter_config
1592 $table->add_index('contextid-filter-name', XMLDB_INDEX_UNIQUE, array('contextid', 'filter', 'name'));
1593
1594 /// Conditionally launch create table for filter_config
1595 if (!$dbman->table_exists($table)) {
1596 $dbman->create_table($table);
1597 }
1598
1599 /// Main savepoint reached
1600 upgrade_main_savepoint($result, 2009040301);
1601 }
1602
c07e6d8d 1603 if ($result && $oldversion < 2009040302) {
1604 /// Transfer current settings from $CFG->textfilters
1605 $disabledfilters = filter_get_all_installed();
1606 if (empty($CFG->textfilters)) {
1607 $activefilters = array();
1608 } else {
1609 $activefilters = explode(',', $CFG->textfilters);
1610 }
1611 $syscontext = get_context_instance(CONTEXT_SYSTEM);
1612 $sortorder = 1;
1613 foreach ($activefilters as $filter) {
1614 filter_set_global_state($filter, TEXTFILTER_ON, $sortorder);
1615 $sortorder += 1;
1616 unset($disabledfilters[$filter]);
1617 }
1618 foreach ($disabledfilters as $filter => $notused) {
1619 filter_set_global_state($filter, TEXTFILTER_DISABLED, $sortorder);
1620 $sortorder += 1;
1621 }
1622
1623 /// Main savepoint reached
1624 upgrade_main_savepoint($result, 2009040302);
1625 }
1626
bbb45905 1627 if ($result && $oldversion < 2009040600) {
1628 /// Ensure that $CFG->stringfilters is set.
1629 if (empty($CFG->stringfilters)) {
1630 if (!empty($CFG->filterall)) {
1631 set_config('stringfilters', $CFG->textfilters);
1632 } else {
1633 set_config('stringfilters', '');
1634 }
1635 }
1636
1637 set_config('filterall', !empty($CFG->stringfilters));
1638 unset_config('textfilters');
1639
1640 /// Main savepoint reached
1641 upgrade_main_savepoint($result, 2009040600);
1642 }
1643
e7c6bf0e 1644 if ($result && $oldversion < 2009041700) {
1645 /// To ensure the UI remains consistent with no behaviour change, any
1646 /// 'until' date in an activity condition should have 1 second subtracted
1647 /// (to go from 0:00 on the following day to 23:59 on the previous one).
1648 $DB->execute('UPDATE {course_modules} SET availableuntil = availableuntil - 1 WHERE availableuntil <> 0');
6861b6fe 1649 require_once($CFG->dirroot . '/course/lib.php');
0f9534c1 1650 rebuild_course_cache(0, true);
e7c6bf0e 1651
1652 /// Main savepoint reached
1653 upgrade_main_savepoint($result, 2009041700);
1654 }
1655
6bdf4c99 1656 if ($result && $oldversion < 2009042600) {
1657 /// Deleting orphaned messages from deleted users.
1658 require_once($CFG->dirroot.'/message/lib.php');
1659 /// Detect deleted users with messages sent(useridfrom) and not read
1660 if ($deletedusers = $DB->get_records_sql('SELECT DISTINCT u.id
1661 FROM {user} u
1662 JOIN {message} m ON m.useridfrom = u.id
1663 WHERE u.deleted = ?', array(1))) {
1664 foreach ($deletedusers as $deleteduser) {
1665 message_move_userfrom_unread2read($deleteduser->id); // move messages
1666 }
1667 }
1668 /// Main savepoint reached
1669 upgrade_main_savepoint($result, 2009042600);
1670 }
1671
e37cd84a 1672 /// Dropping all enums/check contraints from core. MDL-18577
1673 if ($result && $oldversion < 2009042700) {
1674
1675 /// Changing list of values (enum) of field stattype on table stats_daily to none
1676 $table = new xmldb_table('stats_daily');
2a88f626 1677 $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
e37cd84a 1678
1679 /// Launch change of list of values for field stattype
2a88f626 1680 $dbman->drop_enum_from_field($table, $field);
e37cd84a 1681
1682 /// Changing list of values (enum) of field stattype on table stats_weekly to none
1683 $table = new xmldb_table('stats_weekly');
2a88f626 1684 $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
e37cd84a 1685
1686 /// Launch change of list of values for field stattype
2a88f626 1687 $dbman->drop_enum_from_field($table, $field);
e37cd84a 1688
1689 /// Changing list of values (enum) of field stattype on table stats_monthly to none
1690 $table = new xmldb_table('stats_monthly');
2a88f626 1691 $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
e37cd84a 1692
1693 /// Launch change of list of values for field stattype
2a88f626 1694 $dbman->drop_enum_from_field($table, $field);
e37cd84a 1695
1696 /// Changing list of values (enum) of field publishstate on table post to none
1697 $table = new xmldb_table('post');
2a88f626 1698 $field = new xmldb_field('publishstate', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'draft', 'attachment');
e37cd84a 1699
1700 /// Launch change of list of values for field publishstate
2a88f626 1701 $dbman->drop_enum_from_field($table, $field);
e37cd84a 1702
1703 /// Main savepoint reached
1704 upgrade_main_savepoint($result, 2009042700);
1705 }
1706
c045e45a 1707 if ($result && $oldversion < 2009043000) {
1708 unset_config('grade_report_showgroups');
1709 upgrade_main_savepoint($result, 2009043000);
1710 }
1711
1712 if ($result && $oldversion < 2009050600) {
e88462a0 1713 /// Site front page blocks need to be moved due to page name change.
1714 $DB->set_field('block_instance', 'pagetype', 'site-index', array('pagetype' => 'course-view', 'pageid' => SITEID));
1715
1716 /// Main savepoint reached
c045e45a 1717 upgrade_main_savepoint($result, 2009050600);
e88462a0 1718 }
1719
c045e45a 1720 if ($result && $oldversion < 2009050601) {
66b10689 1721
3aceb097 1722 /// Define table block_instance to be renamed to block_instances
66b10689 1723 $table = new xmldb_table('block_instance');
1724
1725 /// Launch rename table for block_instance
3aceb097 1726 $dbman->rename_table($table, 'block_instances');
66b10689 1727
1728 /// Main savepoint reached
c045e45a 1729 upgrade_main_savepoint($result, 2009050601);
66b10689 1730 }
1731
c045e45a 1732 if ($result && $oldversion < 2009050602) {
66b10689 1733
1734 /// Define table block_instance to be renamed to block_instance_old
1735 $table = new xmldb_table('block_pinned');
1736
1737 /// Launch rename table for block_instance
1738 $dbman->rename_table($table, 'block_pinned_old');
1739
1740 /// Main savepoint reached
c045e45a 1741 upgrade_main_savepoint($result, 2009050602);
66b10689 1742 }
1743
c045e45a 1744 if ($result && $oldversion < 2009050603) {
66b10689 1745
1746 /// Define table block_instance_old to be created
1747 $table = new xmldb_table('block_instance_old');
1748
1749 /// Adding fields to table block_instance_old
2b212777 1750 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1751 $table->add_field('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1752 $table->add_field('blockid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
1753 $table->add_field('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
1754 $table->add_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null);
1755 $table->add_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null);
1756 $table->add_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0');
1757 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
1758 $table->add_field('configdata', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
66b10689 1759
1760 /// Adding keys to table block_instance_old
1761 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1762 $table->add_key('blockid', XMLDB_KEY_FOREIGN, array('blockid'), 'block', array('id'));
1763
1764 /// Adding indexes to table block_instance_old
1765 $table->add_index('pageid', XMLDB_INDEX_NOTUNIQUE, array('pageid'));
1766 $table->add_index('pagetype', XMLDB_INDEX_NOTUNIQUE, array('pagetype'));
1767
1768 /// Conditionally launch create table for block_instance_old
1769 if (!$dbman->table_exists($table)) {
1770 $dbman->create_table($table);
1771 }
1772
1773 /// Main savepoint reached
c045e45a 1774 upgrade_main_savepoint($result, 2009050603);
66b10689 1775 }
1776
c045e45a 1777 if ($result && $oldversion < 2009050604) {
66b10689 1778 /// Copy current blocks data from block_instances to block_instance_old
35550fd6 1779 $DB->execute('INSERT INTO {block_instance_old} (oldid, blockid, pageid, pagetype, position, weight, visible, configdata)
1780 SELECT id, blockid, pageid, pagetype, position, weight, visible, configdata FROM {block_instances} ORDER BY id');
66b10689 1781
c045e45a 1782 upgrade_main_savepoint($result, 2009050604);
66b10689 1783 }
1784
c045e45a 1785 if ($result && $oldversion < 2009050605) {
66b10689 1786
1787 /// Define field multiple to be dropped from block
1788 $table = new xmldb_table('block');
1789 $field = new xmldb_field('multiple');
1790
1791 /// Conditionally launch drop field multiple
1792 if ($dbman->field_exists($table, $field)) {
1793 $dbman->drop_field($table, $field);
1794 }
1795
1796 /// Main savepoint reached
c045e45a 1797 upgrade_main_savepoint($result, 2009050605);
66b10689 1798 }
1799
c045e45a 1800 if ($result && $oldversion < 2009050606) {
66b10689 1801 $table = new xmldb_table('block_instances');
1802
1803 /// Rename field weight on table block_instances to defaultweight
2b212777 1804 $field = new xmldb_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0', 'position');
66b10689 1805 $dbman->rename_field($table, $field, 'defaultweight');
1806
1807 /// Rename field position on table block_instances to defaultregion
2b212777 1808 $field = new xmldb_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, 'pagetype');
66b10689 1809 $dbman->rename_field($table, $field, 'defaultregion');
1810
1811 /// Main savepoint reached
c045e45a 1812 upgrade_main_savepoint($result, 2009050606);
66b10689 1813 }
1814
c045e45a 1815 if ($result && $oldversion < 2009050607) {
66b10689 1816 /// Changing precision of field defaultregion on table block_instances to (16)
a26146d5 1817 $table = new xmldb_table('block_instances');
1818 $field = new xmldb_field('defaultregion', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, 'pagetype');
66b10689 1819
1820 /// Launch change of precision for field defaultregion
1821 $dbman->change_field_precision($table, $field);
1822
1823 /// Main savepoint reached
a26146d5 1824 upgrade_main_savepoint($result, 2009050607);
66b10689 1825 }
1826
c045e45a 1827 if ($result && $oldversion < 2009050608) {
66b10689 1828 /// Change regions to the new notation
1829 $DB->set_field('block_instances', 'defaultregion', 'side-pre', array('defaultregion' => 'l'));
1830 $DB->set_field('block_instances', 'defaultregion', 'side-post', array('defaultregion' => 'r'));
1831 $DB->set_field('block_instances', 'defaultregion', 'course-view-top', array('defaultregion' => 'c'));
1832 // This third one is a custom value from contrib/patches/center_blocks_position_patch and the
1833 // flex page course format. Hopefully this new value is an adequate alternative.
1834
1835 /// Main savepoint reached
c045e45a 1836 upgrade_main_savepoint($result, 2009050608);
66b10689 1837 }
1838
c045e45a 1839 if ($result && $oldversion < 2009050609) {
66b10689 1840
1841 /// Define key blockname (unique) to be added to block
1842 $table = new xmldb_table('block');
1843 $key = new xmldb_key('blockname', XMLDB_KEY_UNIQUE, array('name'));
1844
1845 /// Launch add key blockname
1846 $dbman->add_key($table, $key);
1847
1848 /// Main savepoint reached
c045e45a 1849 upgrade_main_savepoint($result, 2009050609);
66b10689 1850 }
1851
c045e45a 1852 if ($result && $oldversion < 2009050610) {
66b10689 1853 $table = new xmldb_table('block_instances');
1854
1855 /// Define field blockname to be added to block_instances
2b212777 1856 $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, null, null, null, 'blockid');
66b10689 1857 if (!$dbman->field_exists($table, $field)) {
1858 $dbman->add_field($table, $field);
1859 }
1860
1861 /// Define field contextid to be added to block_instances
2b212777 1862 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'blockname');
66b10689 1863 if (!$dbman->field_exists($table, $field)) {
1864 $dbman->add_field($table, $field);
1865 }
1866
1867 /// Define field showinsubcontexts to be added to block_instances
2b212777 1868 $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, null, null, null, 'contextid');
66b10689 1869 if (!$dbman->field_exists($table, $field)) {
1870 $dbman->add_field($table, $field);
1871 }
1872
1873 /// Define field subpagepattern to be added to block_instances
2b212777 1874 $field = new xmldb_field('subpagepattern', XMLDB_TYPE_CHAR, '16', null, null, null, null, 'pagetype');
66b10689 1875 if (!$dbman->field_exists($table, $field)) {
1876 $dbman->add_field($table, $field);
1877 }
1878
1879 /// Main savepoint reached
c045e45a 1880 upgrade_main_savepoint($result, 2009050610);
66b10689 1881 }
1882
c045e45a 1883 if ($result && $oldversion < 2009050611) {
66b10689 1884 $table = new xmldb_table('block_instances');
1885
1886 /// Fill in blockname from blockid
1887 $DB->execute("UPDATE {block_instances} SET blockname = (SELECT name FROM {block} WHERE id = blockid)");
1888
1889 /// Set showinsubcontexts = 0 for all rows.
1890 $DB->execute("UPDATE {block_instances} SET showinsubcontexts = 0");
1891
1892 /// Main savepoint reached
c045e45a 1893 upgrade_main_savepoint($result, 2009050611);
66b10689 1894 }
1895
c045e45a 1896 if ($result && $oldversion < 2009050612) {
66b10689 1897
1898 /// Rename field pagetype on table block_instances to pagetypepattern
1899 $table = new xmldb_table('block_instances');
2b212777 1900 $field = new xmldb_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'pageid');
66b10689 1901
1902 /// Launch rename field pagetype
1903 $dbman->rename_field($table, $field, 'pagetypepattern');
1904
1905 /// Main savepoint reached
c045e45a 1906 upgrade_main_savepoint($result, 2009050612);
66b10689 1907 }
1908
c045e45a 1909 if ($result && $oldversion < 2009050613) {
66b10689 1910 /// fill in contextid and subpage, and update pagetypepattern from pagetype and pageid
1911
1912 /// site-index
1913 $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
eb2761f8 1914 $DB->execute("UPDATE {block_instances} SET contextid = " . $frontpagecontext->id . ",
1915 pagetypepattern = 'site-index',
1916 subpagepattern = NULL
1917 WHERE pagetypepattern = 'site-index'");
66b10689 1918
1919 /// course-view
eb2761f8 1920 $DB->execute("UPDATE {block_instances} SET
1921 contextid = (
1922 SELECT {context}.id
1923 FROM {context}
1924 JOIN {course} ON instanceid = {course}.id AND contextlevel = " . CONTEXT_COURSE . "
1925 WHERE {course}.id = pageid
1926 ),
1927 pagetypepattern = 'course-view-*',
1928 subpagepattern = NULL
1929 WHERE pagetypepattern = 'course-view'");
66b10689 1930
1931 /// admin
1932 $syscontext = get_context_instance(CONTEXT_SYSTEM);
eb2761f8 1933 $DB->execute("UPDATE {block_instances} SET
1934 contextid = " . $syscontext->id . ",
1935 pagetypepattern = 'admin-*',
1936 subpagepattern = NULL
1937 WHERE pagetypepattern = 'admin'");
66b10689 1938
1939 /// my-index
eb2761f8 1940 $DB->execute("UPDATE {block_instances} SET
1941 contextid = (
1942 SELECT {context}.id
1943 FROM {context}
1944 JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . "
1945 WHERE {user}.id = pageid
1946 ),
1947 pagetypepattern = 'my-index',
1948 subpagepattern = NULL
1949 WHERE pagetypepattern = 'my-index'");
66b10689 1950
1951 /// tag-index
eb2761f8 1952 $DB->execute("UPDATE {block_instances} SET
1953 contextid = " . $syscontext->id . ",
1954 pagetypepattern = 'tag-index',
1955 subpagepattern = pageid
1956 WHERE pagetypepattern = 'tag-index'");
66b10689 1957
1958 /// blog-view
eb2761f8 1959 $DB->execute("UPDATE {block_instances} SET
1960 contextid = (
1961 SELECT {context}.id
1962 FROM {context}
1963 JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . "
1964 WHERE {user}.id = pageid
1965 ),
1966 pagetypepattern = 'blog-index',
1967 subpagepattern = NULL
1968 WHERE pagetypepattern = 'blog-view'");
66b10689 1969
1970 /// mod-xxx-view
1971 $moduleswithblocks = array('chat', 'data', 'lesson', 'quiz', 'dimdim', 'game', 'wiki', 'oublog');
1972 foreach ($moduleswithblocks as $modname) {
1973 if (!$dbman->table_exists($modname)) {
1974 continue;
1975 }
eb2761f8 1976 $DB->execute("UPDATE {block_instances} SET
1977 contextid = (
1978 SELECT {context}.id
1979 FROM {context}
1980 JOIN {course_modules} ON instanceid = {course_modules}.id AND contextlevel = " . CONTEXT_MODULE . "
1981 JOIN {modules} ON {modules}.id = {course_modules}.module AND {modules}.name = '$modname'
1982 JOIN {{$modname}} ON {course_modules}.instance = {{$modname}}.id
1983 WHERE {{$modname}}.id = pageid
1984 ),
1985 pagetypepattern = 'blog-index',
1986 subpagepattern = NULL
1987 WHERE pagetypepattern = 'blog-view'");
66b10689 1988 }
1989
1990 /// Main savepoint reached
c045e45a 1991 upgrade_main_savepoint($result, 2009050613);
66b10689 1992 }
1993
c045e45a 1994 if ($result && $oldversion < 2009050614) {
66b10689 1995 /// fill in any missing contextids with a dummy value, so we can add the not-null constraint.
1996 $DB->execute("UPDATE {block_instances} SET contextid = -1 WHERE contextid IS NULL");
1997
1998 /// Main savepoint reached
c045e45a 1999 upgrade_main_savepoint($result, 2009050614);
66b10689 2000 }
2001
c045e45a 2002 if ($result && $oldversion < 2009050615) {
66b10689 2003 $table = new xmldb_table('block_instances');
2004
2005 /// Changing nullability of field blockname on table block_instances to not null
2b212777 2006 $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'id');
66b10689 2007 $dbman->change_field_notnull($table, $field);
2008
2009 /// Changing nullability of field contextid on table block_instances to not null
2b212777 2010 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'blockname');
66b10689 2011 $dbman->change_field_notnull($table, $field);
2012
2013 /// Changing nullability of field showinsubcontexts on table block_instances to not null
2b212777 2014 $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, 'contextid');
66b10689 2015 $dbman->change_field_notnull($table, $field);
2016
2017 /// Main savepoint reached
c045e45a 2018 upgrade_main_savepoint($result, 2009050615);
66b10689 2019 }
2020
c045e45a 2021 if ($result && $oldversion < 2009050616) {
66b10689 2022 /// Add exiting sticky blocks.
2023 $blocks = $DB->get_records('block');
2024 $syscontext = get_context_instance(CONTEXT_SYSTEM);
2025 $newregions = array(
2026 'l' => 'side-pre',
2027 'r' => 'side-post',
2028 'c' => 'course-view-top',
2029 );
2030 $stickyblocks = $DB->get_recordset('block_pinned_old');
2031 foreach ($stickyblocks as $stickyblock) {
2032 $newblock = stdClass;
2033 $newblock->blockname = $blocks[$stickyblock]->name;
2034 $newblock->contextid = $syscontext->id;
2035 $newblock->showinsubcontexts = 1;
2036 switch ($stickyblock->pagetype) {
2037 case 'course-view':
2038 $newblock->pagetypepattern = 'course-view-*';
2039 break;
2040 default:
2041 $newblock->pagetypepattern = $stickyblock->pagetype;
2042 }
2043 $newblock->defaultregion = $newregions[$stickyblock->position];
2044 $newblock->defaultweight = $stickyblock->weight;
2045 $newblock->configdata = $stickyblock->configdata;
2046 $DB->insert_record('block_instances', $newblock);
2047 }
2048
2049 /// Main savepoint reached
c045e45a 2050 upgrade_main_savepoint($result, 2009050616);
66b10689 2051 }
2052
c045e45a 2053 if ($result && $oldversion < 2009050617) {
66b10689 2054
2055 /// Define table block_positions to be created
2056 $table = new xmldb_table('block_positions');
2057
2058 /// Adding fields to table block_positions
2b212777 2059 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2060 $table->add_field('blockinstanceid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2061 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2062 $table->add_field('pagetype', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
2063 $table->add_field('subpage', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null);
2064 $table->add_field('visible', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '1');
2065 $table->add_field('region', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null);
2066 $table->add_field('weight', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
66b10689 2067
2068 /// Adding keys to table block_positions
2069 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2070 $table->add_key('blockinstanceid', XMLDB_KEY_FOREIGN, array('blockinstanceid'), 'block_instances', array('id'));
2071 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
2072
2073 /// Adding indexes to table block_positions
2074 $table->add_index('blockinstanceid-contextid-pagetype-subpage', XMLDB_INDEX_UNIQUE, array('blockinstanceid', 'contextid', 'pagetype', 'subpage'));
2075
2076 /// Conditionally launch create table for block_positions
2077 if (!$dbman->table_exists($table)) {
2078 $dbman->create_table($table);
2079 }
2080
2081 /// Main savepoint reached
c045e45a 2082 upgrade_main_savepoint($result, 2009050617);
66b10689 2083 }
2084
c045e45a 2085 if ($result && $oldversion < 2009050618) {
66b10689 2086 /// And block instances with visible = 0, copy that information to block_positions
2087 $DB->execute("INSERT INTO {block_positions} (blockinstanceid, contextid, pagetype, subpage, visible, region, weight)
2088 SELECT id, contextid,
2089 CASE WHEN pagetypepattern = 'course-view-*' THEN
2090 (SELECT " . $DB->sql_concat("'course-view-'", 'format') . "
2091 FROM {course}
2092 JOIN {context} ON {course}.id = {context}.instanceid
2093 WHERE {context}.id = contextid)
2094 ELSE pagetypepattern END,
2095 CASE WHEN subpagepattern IS NULL THEN ''
2096 ELSE subpagepattern END,
2097 0, defaultregion, defaultweight
2098 FROM {block_instances} WHERE visible = 0 AND pagetypepattern <> 'admin-*'");
2099
2100 /// Main savepoint reached
c045e45a 2101 upgrade_main_savepoint($result, 2009050618);
66b10689 2102 }
2103
c045e45a 2104 if ($result && $oldversion < 2009050619) {
66b10689 2105 $table = new xmldb_table('block_instances');
2106
2107 /// Define field blockid to be dropped from block_instances
2108 $field = new xmldb_field('blockid');
2109 if ($dbman->field_exists($table, $field)) {
4276a19a 2110 /// Before dropping the field, drop dependent indexes
2111 $index = new xmldb_index('blockid', XMLDB_INDEX_NOTUNIQUE, array('blockid'));
2112 if ($dbman->index_exists($table, $index)) {
2113 /// Launch drop index blockid
2114 $dbman->drop_index($table, $index);
2115 }
66b10689 2116 $dbman->drop_field($table, $field);
2117 }
2118
2119 /// Define field pageid to be dropped from block_instances
2120 $field = new xmldb_field('pageid');
2121 if ($dbman->field_exists($table, $field)) {
4276a19a 2122 /// Before dropping the field, drop dependent indexes
2123 $index = new xmldb_index('pageid', XMLDB_INDEX_NOTUNIQUE, array('pageid'));
2124 if ($dbman->index_exists($table, $index)) {
2125 /// Launch drop index pageid
2126 $dbman->drop_index($table, $index);
2127 }
66b10689 2128 $dbman->drop_field($table, $field);
2129 }
2130
2131 /// Define field visible to be dropped from block_instances
2132 $field = new xmldb_field('visible');
2133 if ($dbman->field_exists($table, $field)) {
2134 $dbman->drop_field($table, $field);
2135 }
2136
2137 /// Main savepoint reached
c045e45a 2138 upgrade_main_savepoint($result, 2009050619);
35079f53 2139 }
2140
ecdf5d17 2141 if ($result && $oldversion < 2009051200) {
2142 /// Let's check the status of mandatory mnet_host records, fixing them
2143 /// and moving "orphan" users to default localhost record. MDL-16879
aa9a6867 2144 echo $OUTPUT->notification('Fixing mnet records, this may take a while...', 'notifysuccess');
ecdf5d17 2145 upgrade_fix_incorrect_mnethostids();
2146
2147 /// Main savepoint reached
2148 upgrade_main_savepoint($result, 2009051200);
2149 }
2150
a5747cf8 2151
2152 if ($result && $oldversion < 2009051700) {
2153 /// migrate editor settings
2154 if (empty($CFG->htmleditor)) {
2155 set_config('texteditors', 'textarea');
2156 } else {
2157 set_config('texteditors', 'tinymce,textarea');
2158 }
2159
2160 unset_config('htmleditor');
2161 unset_config('defaulthtmleditor');
2162
2163 /// Main savepoint reached
2164 upgrade_main_savepoint($result, 2009051700);
2165 }
2166
1aa01caf 2167 if ($result && $oldversion < 2009060200) {
2168 /// Define table files_cleanup to be dropped - not needed
2169 $table = new xmldb_table('files_cleanup');
2170
2171 /// Conditionally launch drop table for files_cleanup
2172 if ($dbman->table_exists($table)) {
2173 $dbman->drop_table($table);
2174 }
2175
2176 /// Main savepoint reached
2177 upgrade_main_savepoint($result, 2009060200);
2178 }
2179
b4154c2d 2180 if ($result && $oldversion < 2009061300) {
2181 //TODO: copy this to the very beginning of this upgrade script so that we may log upgrade queries
2182
2183 /// Define table log_queries to be created
2184 $table = new xmldb_table('log_queries');
2185
2186 /// Adding fields to table log_queries
2187 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2188 $table->add_field('qtype', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2189 $table->add_field('sqltext', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null);
2190 $table->add_field('sqlparams', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
2191 $table->add_field('error', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2192 $table->add_field('info', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
2193 $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
2194 $table->add_field('exectime', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null);
2195 $table->add_field('timelogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2196
2197 /// Adding keys to table log_queries
2198 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2199
2200 /// Conditionally launch create table for log_queries
2201 if (!$dbman->table_exists($table)) {
2202 $dbman->create_table($table);
2203 }
2204
2205 /// Main savepoint reached
2206 upgrade_main_savepoint($result, 2009061300);
2207 }
2208
52902cea 2209 /// Repeat 2009050607 upgrade step, which Petr commented out becuase of XMLDB
2210 /// stupidity, so lots of peopel will have missed.
2211 if ($result && $oldversion < 2009061600) {
2212 /// Changing precision of field defaultregion on table block_instances to (16)
2213 $table = new xmldb_table('block_instances');
2214 $field = new xmldb_field('defaultregion', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, 'configdata');
2215
2216 /// Launch change of precision for field defaultregion
2217 $dbman->change_field_precision($table, $field);
2218
2219 /// Main savepoint reached
2220 upgrade_main_savepoint($result, 2009061600);
2221 }
2222
17da2e6f 2223 if ($result && $oldversion < 2009061702) {
2224 // standardizing plugin names
2225 if ($configs = $DB->get_records_select('config_plugins', "plugin LIKE 'quizreport_%'")) {
2226 foreach ($configs as $config) {
ce11763a 2227 $result = $result && unset_config($config->name, $config->plugin); /// unset old config
17da2e6f 2228 $config->plugin = str_replace('quizreport_', 'quiz_', $config->plugin);
ce11763a 2229 $result = $result && set_config($config->name, $config->value, $config->plugin); /// set new config
17da2e6f 2230 }
2231 }
2232 unset($configs);
2233 upgrade_main_savepoint($result, 2009061702);
2234 }
2235
2236 if ($result && $oldversion < 2009061703) {
2237 // standardizing plugin names
2238 if ($configs = $DB->get_records_select('config_plugins', "plugin LIKE 'assignment_type_%'")) {
2239 foreach ($configs as $config) {
ce11763a 2240 $result = $result && unset_config($config->name, $config->plugin); /// unset old config
17da2e6f 2241 $config->plugin = str_replace('assignment_type_', 'assignment_', $config->plugin);
ce11763a 2242 $result = $result && set_config($config->name, $config->value, $config->plugin); /// set new config
17da2e6f 2243 }
2244 }
2245 unset($configs);
2246 upgrade_main_savepoint($result, 2009061703);
2247 }
2248
2249 if ($result && $oldversion < 2009061704) {
13a0d3d3 2250 // change component string in capability records to new "_" format
17da2e6f 2251 if ($caps = $DB->get_records('capabilities')) {
2252 foreach ($caps as $cap) {
2253 $cap->component = str_replace('/', '_', $cap->component);
2254 $DB->update_record('capabilities', $cap);
2255 }
2256 }
2257 unset($caps);
2258 upgrade_main_savepoint($result, 2009061704);
2259 }
2260
2261 if ($result && $oldversion < 2009061705) {
13a0d3d3 2262 // change component string in events_handlers records to new "_" format
17da2e6f 2263 if ($handlers = $DB->get_records('events_handlers')) {
2264 foreach ($handlers as $handler) {
2265 $handler->handlermodule = str_replace('/', '_', $handler->handlermodule);
2266 $DB->update_record('events_handlers', $handler);
2267 }
2268 }
2269 unset($handlers);
2270 upgrade_main_savepoint($result, 2009061705);
2271 }
2272
2273 if ($result && $oldversion < 2009061706) {
13a0d3d3 2274 // change component string in message_providers records to new "_" format
17da2e6f 2275 if ($mps = $DB->get_records('message_providers')) {
2276 foreach ($mps as $mp) {
2277 $mp->component = str_replace('/', '_', $mp->component);
2278 $DB->update_record('message_providers', $cap);
2279 }
2280 }
2281 unset($caps);
2282 upgrade_main_savepoint($result, 2009061706);
2283 }
13a0d3d3 2284
adf8f3f9 2285 if ($result && $oldversion < 2009063000) {
2286 // upgrade format of _with_advanced settings - quiz only
2287 // note: this can be removed later, not needed for upgrades from 1.9.x
c1f58efe 2288 if ($quiz = get_config('quiz')) {
2289 foreach ($quiz as $name=>$value) {
2290 if (strpos($name, 'fix_') !== 0) {
2291 continue;
2292 }
2293 $newname = substr($name,4).'_adv';
2294 set_config($newname, $value, 'quiz');
2295 unset_config($name, 'quiz');
adf8f3f9 2296 }
13a0d3d3 2297 }
adf8f3f9 2298 upgrade_main_savepoint($result, 2009063000);
2299 }
13a0d3d3 2300
856b6fe6 2301 if ($result && $oldversion < 2009070100) {
2302 // MDL-19677 Change $CFG->bloglevel to BLOG_SITE_LEVEL if BLOG_COURSE_LEVEL or BLOG_GROUP_LEVEL
2303 $current_bloglevel = get_config(null, 'bloglevel');
2304
2305 if ($current_bloglevel == BLOG_GROUP_LEVEL || $current_bloglevel == BLOG_COURSE_LEVEL) {
2306 set_config('bloglevel', BLOG_SITE_LEVEL);
2307 }
35554f50 2308
2309 /// Main savepoint reached
2310 upgrade_main_savepoint($result, 2009070100);
856b6fe6 2311 }
adf8f3f9 2312
13a0d3d3 2313 if ($result && $oldversion < 2009071000) {
2314
2315 /// Rename field contextid on table block_instances to parentcontextid
2316 $table = new xmldb_table('block_instances');
2317 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'blockname');
2318
2319 /// Launch rename field parentcontextid
2320 $dbman->rename_field($table, $field, 'parentcontextid');
2321
2322 /// Main savepoint reached
2323 upgrade_main_savepoint($result, 2009071000);
2324 }
2325
e92c286c 2326 if ($result && $oldversion < 2009071300) {
2327
2328 /// Create contexts for every block. In the past, only non-sticky course block had contexts.
2329 /// This is a copy of the code in create_contexts.
2330 $sql = "INSERT INTO {context} (contextlevel, instanceid)
2331 SELECT " . CONTEXT_BLOCK . ", bi.id
2332 FROM {block_instances} bi
2333 WHERE NOT EXISTS (SELECT 'x'
2334 FROM {context} ctx
2335 WHERE bi.id = ctx.instanceid AND ctx.contextlevel=" . CONTEXT_BLOCK . ")";
2336 $DB->execute($sql);
2337
2338 /// TODO MDL-19776 We should not really use API funcitons in upgrade.
2339 /// If MDL-19776 is done, we can remove this whole upgrade block.
2340 build_context_path();
2341
2342 /// Main savepoint reached
2343 upgrade_main_savepoint($result, 2009071300);
2344 }
2345
1bcb7eb5 2346 if ($result && $oldversion < 2009072400) {
2347
2348 /// Define table comments to be created
2349 $table = new xmldb_table('comments');
2350
2351 /// Adding fields to table comments
2352 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2353 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2354 $table->add_field('commentarea', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
2355 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2356 $table->add_field('content', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
2357 $table->add_field('format', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2358 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2359 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2360
2361 /// Adding keys to table comments
2362 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2363
2364 /// Conditionally launch create table for comments
2365 if (!$dbman->table_exists($table)) {
2366 $dbman->create_table($table);
2367 }
0a127169 2368
1bcb7eb5 2369 /// Main savepoint reached
2370 upgrade_main_savepoint($result, 2009072400);
2371 }
2372
ac9b0805 2373 return $result;
4e423cbf 2374}
271e6dec 2375
e92c286c 2376//TODO: Before 2.0 release
2377// 1/ remove the automatic enabling of completion lib if debug enabled ( in 2008121701 block)
2378// 2/ move 2009061300 block to the top of the file so that we may log upgrade queries