MDL-21432 backup - make itemname bigger so it can store file component/area named
[moodle.git] / lib / db / upgrade.php
CommitLineData
117bd748 1<?PHP
4e423cbf 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
2e0406a5 11// your older installation to the current version.
4e423cbf 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
3406acde
SH
22/**
23 *
24 * @global stdClass $CFG
25 * @global stdClass $USER
26 * @global moodle_database $DB
27 * @global core_renderer $OUTPUT
28 * @param int $oldversion
29 * @return bool
30 */
775f811a 31function xmldb_main_upgrade($oldversion) {
78946b9b 32 global $CFG, $USER, $DB, $OUTPUT;
4e423cbf 33
4f12838e 34 require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions
13a0d3d3 35
46d318bc 36 $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
f33e1ed4 37
1ea260d8 38 ////////////////////////////////////////
39 ///upgrade supported only from 1.9.x ///
40 ////////////////////////////////////////
da4aa3e4 41
a4cdd6d2 42 if ($oldversion < 2008030600) {
6389e70a 43 //NOTE: this table was added much later later in dev cycle, but we need it here, upgrades from pre PR1 not supported
795a08ad 44
45 /// Define table upgrade_log to be created
46 $table = new xmldb_table('upgrade_log');
47
48 /// Adding fields to table upgrade_log
2a88f626 49 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
50 $table->add_field('type', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
51 $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null);
52 $table->add_field('version', XMLDB_TYPE_CHAR, '100', null, null, null, null);
53 $table->add_field('info', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
54 $table->add_field('details', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
55 $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
56 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
57 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
795a08ad 58
59 /// Adding keys to table upgrade_log
60 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
61 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
62
63 /// Adding indexes to table upgrade_log
64 $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
65 $table->add_index('type-timemodified', XMLDB_INDEX_NOTUNIQUE, array('type', 'timemodified'));
66
67 /// Create table for upgrade_log
68 $dbman->create_table($table);
69
70 /// Main savepoint reached
a4cdd6d2 71 upgrade_main_savepoint(true, 2008030600);
795a08ad 72 }
73
a4cdd6d2 74 if ($oldversion < 2008030601) {
6389e70a
PS
75 //NOTE: this table was added much later later in dev cycle, but we need it here, upgrades from pre PR1 not supported
76
77 /// Define table log_queries to be created
78 $table = new xmldb_table('log_queries');
79
80 /// Adding fields to table log_queries
81 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
82 $table->add_field('qtype', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
83 $table->add_field('sqltext', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null);
84 $table->add_field('sqlparams', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
85 $table->add_field('error', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
86 $table->add_field('info', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
87 $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
88 $table->add_field('exectime', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null);
89 $table->add_field('timelogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
90
91 /// Adding keys to table log_queries
92 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
93
94 /// Conditionally launch create table for log_queries
95 $dbman->create_table($table);
96
97 /// Main savepoint reached
98 upgrade_main_savepoint(true, 2008030601);
99 }
100
101 if ($oldversion < 2008030602) {
3a915b06
PS
102 @unlink($CFG->dataroot.'/cache/languages');
103
2a272405
DM
104 if (file_exists("$CFG->dataroot/lang")) {
105 // rename old lang directory so that the new and old langs do not mix
106 if (rename("$CFG->dataroot/lang", "$CFG->dataroot/oldlang")) {
107 $oldlang = "$CFG->dataroot/oldlang";
108 } else {
109 $oldlang = "$CFG->dataroot/lang";
110 }
3a915b06 111 } else {
2a272405 112 $oldlang = '';
3a915b06
PS
113 }
114 // TODO: fetch previously installed languages ("*_utf8") found in $oldlang from moodle.org
115 upgrade_set_timeout(60*20); // this may take a while
116
117
118 // TODO: add some info file to $oldlang describing what to do with "$oldlang/*_utf8_local" dirs
119
120
121 // Main savepoint reached
6389e70a 122 upgrade_main_savepoint(true, 2008030602);
3a915b06
PS
123 }
124
a4cdd6d2 125 if ($oldversion < 2008030700) {
775f811a 126 upgrade_set_timeout(60*20); // this may take a while
a1f27717 127
128 /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters
a8cb94f6 129 $table = new xmldb_table('grade_letters');
69b80cc2 130 $index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
a1f27717 131
132 /// Launch drop index contextid-lowerboundary
5cada363
EL
133 if ($dbman->index_exists($table, $index)) {
134 $dbman->drop_index($table, $index);
135 }
a1f27717 136
a1f27717 137 /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
a8cb94f6 138 $table = new xmldb_table('grade_letters');
69b80cc2 139 $index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
a1f27717 140
141 /// Launch add index contextid-lowerboundary-letter
eee5d9bb 142 $dbman->add_index($table, $index);
a1f27717 143
144 /// Main savepoint reached
a4cdd6d2 145 upgrade_main_savepoint(true, 2008030700);
0f77b186 146 }
a1f27717 147
a4cdd6d2 148 if ($oldversion < 2008050100) {
1ea260d8 149 // Update courses that used weekscss to weeks
61676608 150 $DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss'));
a4cdd6d2 151 upgrade_main_savepoint(true, 2008050100);
1ea260d8 152 }
153
a4cdd6d2 154 if ($oldversion < 2008050200) {
0b51c247 155 // remove unused config options
156 unset_config('statsrolesupgraded');
a4cdd6d2 157 upgrade_main_savepoint(true, 2008050200);
0b51c247 158 }
159
a4cdd6d2 160 if ($oldversion < 2008050700) {
775f811a 161 upgrade_set_timeout(60*20); // this may take a while
162
994fbaab 163 /// Fix minor problem caused by MDL-5482.
164 require_once($CFG->dirroot . '/question/upgrade.php');
61676608 165 question_fix_random_question_parents();
a4cdd6d2 166 upgrade_main_savepoint(true, 2008050700);
994fbaab 167 }
168
a4cdd6d2 169 if ($oldversion < 2008051201) {
aa9a6867 170 echo $OUTPUT->notification('Increasing size of user idnumber field, this may take a while...', 'notifysuccess');
775f811a 171 upgrade_set_timeout(60*20); // this may take a while
8b9cfac4 172
469dcbcc 173 /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859
cbc08f3b 174 $dbfamily = $DB->get_dbfamily();
175 if ($dbfamily === 'mysql' || $dbfamily === 'postgres') {
eee5d9bb 176 $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL");
469dcbcc 177 }
178
8b9cfac4 179 /// Define index idnumber (not unique) to be dropped form user
a8cb94f6 180 $table = new xmldb_table('user');
69b80cc2 181 $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
8b9cfac4 182
183 /// Launch drop index idnumber
f33e1ed4 184 if ($dbman->index_exists($table, $index)) {
eee5d9bb 185 $dbman->drop_index($table, $index);
8b9cfac4 186 }
187
188 /// Changing precision of field idnumber on table user to (255)
a8cb94f6 189 $table = new xmldb_table('user');
2a88f626 190 $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'password');
8b9cfac4 191
192 /// Launch change of precision for field idnumber
eee5d9bb 193 $dbman->change_field_precision($table, $field);
8b9cfac4 194
195 /// Launch add index idnumber again
69b80cc2 196 $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
eee5d9bb 197 $dbman->add_index($table, $index);
8b9cfac4 198
199 /// Main savepoint reached
a4cdd6d2 200 upgrade_main_savepoint(true, 2008051201);
8b9cfac4 201 }
202
a4cdd6d2 203 if ($oldversion < 2008051202) {
910dd4dd 204 $log_action = new object();
7ade55ad 205 $log_action->module = 'course';
206 $log_action->action = 'unenrol';
207 $log_action->mtable = 'course';
208 $log_action->field = 'fullname';
910dd4dd 209 if (!$DB->record_exists('log_display', array('action'=>'unenrol', 'module'=>'course'))) {
61676608 210 $DB->insert_record('log_display', $log_action);
7ade55ad 211 }
a4cdd6d2 212 upgrade_main_savepoint(true, 2008051202);
7ade55ad 213 }
214
a4cdd6d2 215 if ($oldversion < 2008051203) {
fa162144 216 $table = new xmldb_table('mnet_enrol_course');
2a88f626 217 $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
eee5d9bb 218 $dbman->change_field_precision($table, $field);
a4cdd6d2 219 upgrade_main_savepoint(true, 2008051203);
fa162144 220 }
221
a4cdd6d2 222 if ($oldversion < 2008063001) {
775f811a 223 upgrade_set_timeout(60*20); // this may take a while
224
38fb8190 225 // table to be modified
226 $table = new xmldb_table('tag_instance');
227 // add field
228 $field = new xmldb_field('tiuserid');
229 if (!$dbman->field_exists($table, $field)) {
2a88f626 230 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'itemid');
38fb8190 231 $dbman->add_field($table, $field);
232 }
233 // modify index
234 $index = new xmldb_index('itemtype-itemid-tagid');
235 $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));
b91de8a5 236 if ($dbman->index_exists($table, $index)) {
237 $dbman->drop_index($table, $index);
238 }
38fb8190 239 $index = new xmldb_index('itemtype-itemid-tagid-tiuserid');
240 $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
b91de8a5 241 if (!$dbman->index_exists($table, $index)) {
242 $dbman->add_index($table, $index);
243 }
38fb8190 244
245 /// Main savepoint reached
a4cdd6d2 246 upgrade_main_savepoint(true, 2008063001);
38fb8190 247 }
38fb8190 248
a4cdd6d2 249 if ($oldversion < 2008070300) {
61676608 250 $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false));
a4cdd6d2 251 upgrade_main_savepoint(true, 2008070300);
a036d7f3 252 }
4e781c7b 253
a4cdd6d2 254 if ($oldversion < 2008070701) {
ac5efef6 255
256 /// Define table portfolio_instance to be created
257 $table = new xmldb_table('portfolio_instance');
258
259 /// Adding fields to table portfolio_instance
2a88f626 260 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
261 $table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
262 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
263 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
ac5efef6 264
265 /// Adding keys to table portfolio_instance
266 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
267
268 /// Conditionally launch create table for portfolio_instance
269 if (!$dbman->table_exists($table)) {
270 $dbman->create_table($table);
271 }
272 /// Define table portfolio_instance_config to be created
273 $table = new xmldb_table('portfolio_instance_config');
274
275 /// Adding fields to table portfolio_instance_config
2a88f626 276 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
277 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
278 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
279 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
ac5efef6 280
281 /// Adding keys to table portfolio_instance_config
282 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
283 $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
284
285 /// Adding indexes to table portfolio_instance_config
286 $table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name'));
287
288 /// Conditionally launch create table for portfolio_instance_config
289 if (!$dbman->table_exists($table)) {
290 $dbman->create_table($table);
291 }
292
293 /// Define table portfolio_instance_user to be created
294 $table = new xmldb_table('portfolio_instance_user');
295
296 /// Adding fields to table portfolio_instance_user
2a88f626 297 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
298 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
299 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
300 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
301 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
ac5efef6 302
303 /// Adding keys to table portfolio_instance_user
304 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
305 $table->add_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
306 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
307
308 /// Conditionally launch create table for portfolio_instance_user
309 if (!$dbman->table_exists($table)) {
310 $dbman->create_table($table);
311 }
312
313 /// Main savepoint reached
a4cdd6d2 314 upgrade_main_savepoint(true, 2008070701);
ac5efef6 315 }
172dd12c 316
a4cdd6d2 317 if ($oldversion < 2008072400) {
775f811a 318 /// Create the database tables for message_processors
f65b2dae 319 $table = new xmldb_table('message_processors');
2a88f626 320 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
321 $table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null);
f65b2dae 322 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3b120e46 323 $dbman->create_table($table);
324
3b120e46 325 /// delete old and create new fields
f65b2dae 326 $table = new xmldb_table('message');
327 $field = new xmldb_field('messagetype');
3b120e46 328 $dbman->drop_field($table, $field);
329
330 /// fields to rename
f65b2dae 331 $field = new xmldb_field('message');
2a88f626 332 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
3b120e46 333 $dbman->rename_field($table, $field, 'fullmessage');
f65b2dae 334 $field = new xmldb_field('format');
2a88f626 335 $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null);
3b120e46 336 $dbman->rename_field($table, $field, 'fullmessageformat');
337
338 /// new message fields
f65b2dae 339 $field = new xmldb_field('subject');
2a88f626 340 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
3b120e46 341 $dbman->add_field($table, $field);
f65b2dae 342 $field = new xmldb_field('fullmessagehtml');
2a88f626 343 $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null);
3b120e46 344 $dbman->add_field($table, $field);
f65b2dae 345 $field = new xmldb_field('smallmessage');
2a88f626 346 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
3b120e46 347 $dbman->add_field($table, $field);
348
349
f65b2dae 350 $table = new xmldb_table('message_read');
351 $field = new xmldb_field('messagetype');
3b120e46 352 $dbman->drop_field($table, $field);
f65b2dae 353 $field = new xmldb_field('mailed');
3b120e46 354 $dbman->drop_field($table, $field);
355
356 /// fields to rename
f65b2dae 357 $field = new xmldb_field('message');
2a88f626 358 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
3b120e46 359 $dbman->rename_field($table, $field, 'fullmessage');
f65b2dae 360 $field = new xmldb_field('format');
2a88f626 361 $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null);
3b120e46 362 $dbman->rename_field($table, $field, 'fullmessageformat');
363
364
365 /// new message fields
f65b2dae 366 $field = new xmldb_field('subject');
2a88f626 367 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
3b120e46 368 $dbman->add_field($table, $field);
f65b2dae 369 $field = new xmldb_field('fullmessagehtml');
2a88f626 370 $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null);
3b120e46 371 $dbman->add_field($table, $field);
f65b2dae 372 $field = new xmldb_field('smallmessage');
2a88f626 373 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
3b120e46 374 $dbman->add_field($table, $field);
375
376 /// new table
f65b2dae 377 $table = new xmldb_table('message_working');
2a88f626 378 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
379 $table->add_field('unreadmessageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
380 $table->add_field('processorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
f65b2dae 381 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3b120e46 382 $dbman->create_table($table);
383
384
a4cdd6d2 385 upgrade_main_savepoint(true, 2008072400);
3b120e46 386 }
387
a4cdd6d2 388 if ($oldversion < 2008072800) {
4e781c7b 389
390 /// Define field enablecompletion to be added to course
391 $table = new xmldb_table('course');
392 $field = new xmldb_field('enablecompletion');
2a88f626 393 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'defaultrole');
4e781c7b 394
395 /// Launch add field enablecompletion
775f811a 396 if (!$dbman->field_exists($table,$field)) {
4e781c7b 397 $dbman->add_field($table, $field);
398 }
775f811a 399
4e781c7b 400 /// Define field completion to be added to course_modules
401 $table = new xmldb_table('course_modules');
402 $field = new xmldb_field('completion');
2a88f626 403 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'groupmembersonly');
4e781c7b 404
405 /// Launch add field completion
775f811a 406 if (!$dbman->field_exists($table,$field)) {
4e781c7b 407 $dbman->add_field($table, $field);
408 }
409
410 /// Define field completiongradeitemnumber to be added to course_modules
411 $field = new xmldb_field('completiongradeitemnumber');
2a88f626 412 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'completion');
4e781c7b 413
414 /// Launch add field completiongradeitemnumber
775f811a 415 if (!$dbman->field_exists($table,$field)) {
4e781c7b 416 $dbman->add_field($table, $field);
417 }
418
419 /// Define field completionview to be added to course_modules
420 $field = new xmldb_field('completionview');
2a88f626 421 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completiongradeitemnumber');
4e781c7b 422
423 /// Launch add field completionview
775f811a 424 if (!$dbman->field_exists($table,$field)) {
4e781c7b 425 $dbman->add_field($table, $field);
426 }
427
428 /// Define field completionexpected to be added to course_modules
429 $field = new xmldb_field('completionexpected');
2a88f626 430 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionview');
4e781c7b 431
432 /// Launch add field completionexpected
775f811a 433 if (!$dbman->field_exists($table,$field)) {
4e781c7b 434 $dbman->add_field($table, $field);
435 }
436
437 /// Define table course_modules_completion to be created
438 $table = new xmldb_table('course_modules_completion');
775f811a 439 if (!$dbman->table_exists($table)) {
4e781c7b 440
441 /// Adding fields to table course_modules_completion
2a88f626 442 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
443 $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
444 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
445 $table->add_field('completionstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
446 $table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null);
447 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
775f811a 448
4e781c7b 449 /// Adding keys to table course_modules_completion
1e0c56ea 450 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
775f811a 451
4e781c7b 452 /// Adding indexes to table course_modules_completion
1e0c56ea 453 $table->add_index('coursemoduleid', XMLDB_INDEX_NOTUNIQUE, array('coursemoduleid'));
454 $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
775f811a 455
4e781c7b 456 /// Launch create table for course_modules_completion
457 $dbman->create_table($table);
458 }
459
460 /// Main savepoint reached
a4cdd6d2 461 upgrade_main_savepoint(true, 2008072800);
4e781c7b 462 }
775f811a 463
a4cdd6d2 464 if ($oldversion < 2008073000) {
ac5efef6 465
4ab16a09 466 /// Define table portfolio_log to be created
467 $table = new xmldb_table('portfolio_log');
468
469 /// Adding fields to table portfolio_log
2a88f626 470 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
471 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
472 $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
473 $table->add_field('portfolio', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
474 $table->add_field('caller_class', XMLDB_TYPE_CHAR, '150', null, XMLDB_NOTNULL, null, null);
475 $table->add_field('caller_file', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
476 $table->add_field('caller_sha1', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
698fbbb0
PS
477 $table->add_field('tempdataid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
478 $table->add_field('returnurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
479 $table->add_field('continueurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
4ab16a09 480
481 /// Adding keys to table portfolio_log
482 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
483 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
484 $table->add_key('portfoliofk', XMLDB_KEY_FOREIGN, array('portfolio'), 'portfolio_instance', array('id'));
485
486 /// Conditionally launch create table for portfolio_log
487 if (!$dbman->table_exists($table)) {
488 $dbman->create_table($table);
489 }
490
491 /// Main savepoint reached
a4cdd6d2 492 upgrade_main_savepoint(true, 2008073000);
4ab16a09 493 }
120b3758 494
a4cdd6d2 495 if ($oldversion < 2008073104) {
120b3758 496 /// Drop old table that might exist for some people
497 $table = new xmldb_table('message_providers');
498 if ($dbman->table_exists($table)) {
499 $dbman->drop_table($table);
500 }
501
502 /// Define table message_providers to be created
503 $table = new xmldb_table('message_providers');
504
505 /// Adding fields to table message_providers
2a88f626 506 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
507 $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
508 $table->add_field('component', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
509 $table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null);
120b3758 510
511 /// Adding keys to table message_providers
512 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
513
514 /// Adding indexes to table message_providers
515 $table->add_index('componentname', XMLDB_INDEX_UNIQUE, array('component', 'name'));
516
517 /// Create table for message_providers
518 $dbman->create_table($table);
519
a4cdd6d2 520 upgrade_main_savepoint(true, 2008073104);
120b3758 521 }
172dd12c 522
a4cdd6d2 523 if ($oldversion < 2008073111) {
172dd12c 524 /// Define table files to be created
525 $table = new xmldb_table('files');
526
527 /// Adding fields to table files
2a88f626 528 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
529 $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
530 $table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
531 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
64f93798 532 $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
2a88f626 533 $table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
534 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
535 $table->add_field('filepath', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
536 $table->add_field('filename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
537 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
538 $table->add_field('filesize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
539 $table->add_field('mimetype', XMLDB_TYPE_CHAR, '100', null, null, null, null);
540 $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
f0b9ee18
PS
541 $table->add_field('source', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
542 $table->add_field('author', XMLDB_TYPE_CHAR, '255', null, null, null, null);
543 $table->add_field('license', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2a88f626 544 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
545 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
172dd12c 546
547 /// Adding keys to table files
548 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
549 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
550 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
551
552 /// Adding indexes to table files
64f93798 553 $table->add_index('component-filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('component', 'filearea', 'contextid', 'itemid'));
172dd12c 554 $table->add_index('contenthash', XMLDB_INDEX_NOTUNIQUE, array('contenthash'));
555 $table->add_index('pathnamehash', XMLDB_INDEX_UNIQUE, array('pathnamehash'));
556
557 /// Conditionally launch create table for files
558 $dbman->create_table($table);
559
560 /// Main savepoint reached
a4cdd6d2 561 upgrade_main_savepoint(true, 2008073111);
172dd12c 562 }
563
a4cdd6d2 564 if ($oldversion < 2008073112) {
bf34822b
PS
565 // Define field legacyfiles to be added to course
566 $table = new xmldb_table('course');
567 $field = new xmldb_field('legacyfiles', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'maxbytes');
568
569 // Launch add field legacyfiles
570 $dbman->add_field($table, $field);
571 // enable legacy files in all courses
572 $DB->execute("UPDATE {course} SET legacyfiles = 2");
573
574 // Main savepoint reached
a4cdd6d2 575 upgrade_main_savepoint(true, 2008073112);
bf34822b
PS
576 }
577
a4cdd6d2 578 if ($oldversion < 2008073113) {
172dd12c 579 /// move all course, backup and other files to new filepool based storage
580 upgrade_migrate_files_courses();
581 /// Main savepoint reached
a4cdd6d2 582 upgrade_main_savepoint(true, 2008073113);
172dd12c 583 }
584
a4cdd6d2 585 if ($oldversion < 2008073114) {
172dd12c 586 /// move all course, backup and other files to new filepool based storage
587 upgrade_migrate_files_blog();
588 /// Main savepoint reached
a4cdd6d2 589 upgrade_main_savepoint(true, 2008073114);
172dd12c 590 }
f33e1ed4 591
a4cdd6d2 592 if ($oldversion < 2008080400) {
1ce2da58 593 // Add field ssl_jump_url to mnet application, and populate existing default applications
594 $table = new xmldb_table('mnet_application');
595 $field = new xmldb_field('sso_jump_url');
596 if (!$dbman->field_exists($table, $field)) {
2a88f626 597 $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
c5a04d12 598 $dbman->add_field($table, $field);
61676608
PS
599 $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle'));
600 $DB->set_field('mnet_application', 'sso_jump_url', '/auth/xmlrpc/jump.php', array('name' => 'mahara'));
1ce2da58 601 }
602
603 /// Main savepoint reached
a4cdd6d2 604 upgrade_main_savepoint(true, 2008080400);
1ce2da58 605 }
04f35360 606
a4cdd6d2 607 if ($oldversion < 2008080500) {
04f35360 608
3bfadd29 609 /// Define table portfolio_tempdata to be created
04f35360 610 $table = new xmldb_table('portfolio_tempdata');
611
612 /// Adding fields to table portfolio_tempdata
2a88f626 613 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
614 $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
fcd1c1c2
PS
615 $table->add_field('expirytime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
616 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
617 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', null, null, null, '0');
04f35360 618
619 /// Adding keys to table portfolio_tempdata
620 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
fcd1c1c2
PS
621 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
622 $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
04f35360 623
624 /// Conditionally launch create table for portfolio_tempdata
625 if (!$dbman->table_exists($table)) {
626 $dbman->create_table($table);
627 }
628
629 /// Main savepoint reached
a4cdd6d2 630 upgrade_main_savepoint(true, 2008080500);
04f35360 631 }
632
a4cdd6d2 633 if ($oldversion < 2008081500) {
c1f58efe 634 /// Changing the type of all the columns that the question bank uses to store grades to be NUMBER(12, 7).
635 $table = new xmldb_table('question');
636 $field = new xmldb_field('defaultgrade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'generalfeedback');
637 $dbman->change_field_type($table, $field);
a4cdd6d2 638 upgrade_main_savepoint(true, 2008081500);
c1f58efe 639 }
640
a4cdd6d2 641 if ($oldversion < 2008081501) {
f9a2cf86 642 $table = new xmldb_table('question');
2a88f626 643 $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'defaultgrade');
f9a2cf86 644 $dbman->change_field_type($table, $field);
a4cdd6d2 645 upgrade_main_savepoint(true, 2008081501);
f9a2cf86 646 }
647
a4cdd6d2 648 if ($oldversion < 2008081502) {
f9a2cf86 649 $table = new xmldb_table('question_answers');
2a88f626 650 $field = new xmldb_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'answer');
f9a2cf86 651 $dbman->change_field_type($table, $field);
a4cdd6d2 652 upgrade_main_savepoint(true, 2008081502);
f9a2cf86 653 }
654
a4cdd6d2 655 if ($oldversion < 2008081503) {
f9a2cf86 656 $table = new xmldb_table('question_sessions');
2a88f626 657 $field = new xmldb_field('sumpenalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'newgraded');
f9a2cf86 658 $dbman->change_field_type($table, $field);
a4cdd6d2 659 upgrade_main_savepoint(true, 2008081503);
f9a2cf86 660 }
661
a4cdd6d2 662 if ($oldversion < 2008081504) {
f9a2cf86 663 $table = new xmldb_table('question_states');
2a88f626 664 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'event');
f9a2cf86 665 $dbman->change_field_type($table, $field);
a4cdd6d2 666 upgrade_main_savepoint(true, 2008081504);
f9a2cf86 667 }
668
a4cdd6d2 669 if ($oldversion < 2008081505) {
f9a2cf86 670 $table = new xmldb_table('question_states');
2a88f626 671 $field = new xmldb_field('raw_grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'grade');
f9a2cf86 672 $dbman->change_field_type($table, $field);
a4cdd6d2 673 upgrade_main_savepoint(true, 2008081505);
f9a2cf86 674 }
675
a4cdd6d2 676 if ($oldversion < 2008081506) {
f9a2cf86 677 $table = new xmldb_table('question_states');
2a88f626 678 $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'raw_grade');
f9a2cf86 679 $dbman->change_field_type($table, $field);
a4cdd6d2 680 upgrade_main_savepoint(true, 2008081506);
f9a2cf86 681 }
682
a4cdd6d2 683 if ($oldversion < 2008081600) {
775f811a 684
685 /// all 1.9 sites and fresh installs must already be unicode, not needed anymore
686 unset_config('unicodedb');
687
688 /// Main savepoint reached
a4cdd6d2 689 upgrade_main_savepoint(true, 2008081600);
775f811a 690 }
691
a4cdd6d2 692 if ($oldversion < 2008082602) {
27051e43 693
694 /// Define table repository to be dropped
695 $table = new xmldb_table('repository');
696
697 /// Conditionally launch drop table for repository
698 if ($dbman->table_exists($table)) {
699 $dbman->drop_table($table);
700 }
701
702 /// Define table repository to be created
703 $table = new xmldb_table('repository');
704
705 /// Adding fields to table repository
2a88f626 706 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
707 $table->add_field('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
708 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '1');
709 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
27051e43 710
711 /// Adding keys to table repository
712 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
713
714 /// Conditionally launch create table for repository
715 if (!$dbman->table_exists($table)) {
716 $dbman->create_table($table);
717 }
1c5f926d 718
27051e43 719 /// Define table repository_instances to be created
720 $table = new xmldb_table('repository_instances');
721
722 /// Adding fields to table repository_instances
2a88f626 723 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
724 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
725 $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
726 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
727 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
728 $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null);
729 $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null);
730 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
731 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
1c5f926d 732 $table->add_field('readonly', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
27051e43 733
734 /// Adding keys to table repository_instances
735 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
736
737 /// Conditionally launch create table for repository_instances
738 if (!$dbman->table_exists($table)) {
739 $dbman->create_table($table);
740 }
741
742 /// Define table repository_instance_config to be created
743 $table = new xmldb_table('repository_instance_config');
744
745 /// Adding fields to table repository_instance_config
2a88f626 746 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
747 $table->add_field('instanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
748 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
749 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
27051e43 750
751 /// Adding keys to table repository_instance_config
752 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
753
754 /// Conditionally launch create table for repository_instance_config
755 if (!$dbman->table_exists($table)) {
756 $dbman->create_table($table);
757 }
758
759 /// Main savepoint reached
a4cdd6d2 760 upgrade_main_savepoint(true, 2008082602);
27051e43 761 }
762
a4cdd6d2 763 if ($oldversion < 2008082700) {
62e76c67 764 /// Add a new column to the question sessions table to record whether a
765 /// question has been flagged.
766
767 /// Define field flagged to be added to question_sessions
768 $table = new xmldb_table('question_sessions');
2a88f626 769 $field = new xmldb_field('flagged', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'manualcomment');
62e76c67 770
771 /// Conditionally launch add field flagged
772 if (!$dbman->field_exists($table, $field)) {
773 $dbman->add_field($table, $field);
774 }
775
776 /// Main savepoint reached
a4cdd6d2 777 upgrade_main_savepoint(true, 2008082700);
62e76c67 778 }
ff2f69bc 779
a4cdd6d2 780 if ($oldversion < 2008082900) {
2c48aeab 781
782 /// Changing precision of field parent_type on table mnet_rpc to (20)
783 $table = new xmldb_table('mnet_rpc');
2a88f626 784 $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path');
2c48aeab 785
786 /// Launch change of precision for field parent_type
787 $dbman->change_field_precision($table, $field);
788
789 /// Main savepoint reached
a4cdd6d2 790 upgrade_main_savepoint(true, 2008082900);
2c48aeab 791 }
792
d849880e 793 // MDL-16411 Move all plugintype_pluginname_version values from config to config_plugins.
a4cdd6d2 794 if ($oldversion < 2008091000) {
d849880e 795 foreach (get_object_vars($CFG) as $name => $value) {
796 if (substr($name, strlen($name) - 8) !== '_version') {
797 continue;
798 }
799 $pluginname = substr($name, 0, strlen($name) - 8);
800 if (!strpos($pluginname, '_')) {
801 // Skip things like backup_version that don't contain an extra _
802 continue;
803 }
804 if ($pluginname == 'enrol_ldap_version') {
805 // Special case - this is something different from a plugin version number.
806 continue;
807 }
6f49dd0f 808 if (!preg_match('/^\d{10}$/', $value)) {
d849880e 809 // Extra safety check, skip anything that does not look like a Moodle
810 // version number (10 digits).
811 continue;
812 }
61676608
PS
813 set_config('version', $value, $pluginname);
814 unset_config($name);
d849880e 815 }
a4cdd6d2 816 upgrade_main_savepoint(true, 2008091000);
d849880e 817 }
818
a4cdd6d2 819 if ($oldversion < 2008092300) {
53b20fe3 820 unset_config('editorspelling');
821 unset_config('editordictionary');
822 /// Main savepoint reached
a4cdd6d2 823 upgrade_main_savepoint(true, 2008092300);
53b20fe3 824 }
825
a4cdd6d2 826 if ($oldversion < 2008101300) {
5e7206a8 827
d9e673c1 828 if (!get_config(NULL, 'statsruntimedays')) {
5e7206a8 829 set_config('statsruntimedays', '31');
830 }
831
832 /// Main savepoint reached
a4cdd6d2 833 upgrade_main_savepoint(true, 2008101300);
5e7206a8 834 }
53b20fe3 835
9101efd3 836 /// Drop the deprecated teacher, teachers, student and students columns from the course table.
a4cdd6d2 837 if ($oldversion < 2008111200) {
9101efd3 838 $table = new xmldb_table('course');
839
840 /// Conditionally launch drop field teacher
841 $field = new xmldb_field('teacher');
842 if ($dbman->field_exists($table, $field)) {
843 $dbman->drop_field($table, $field);
844 }
845
846 /// Conditionally launch drop field teacher
847 $field = new xmldb_field('teachers');
848 if ($dbman->field_exists($table, $field)) {
849 $dbman->drop_field($table, $field);
850 }
851
852 /// Conditionally launch drop field teacher
853 $field = new xmldb_field('student');
854 if ($dbman->field_exists($table, $field)) {
855 $dbman->drop_field($table, $field);
856 }
857
858 /// Conditionally launch drop field teacher
859 $field = new xmldb_field('students');
860 if ($dbman->field_exists($table, $field)) {
861 $dbman->drop_field($table, $field);
862 }
863
864 /// Main savepoint reached
a4cdd6d2 865 upgrade_main_savepoint(true, 2008111200);
9101efd3 866 }
867
40c792c3 868/// Add a unique index to the role.name column.
a4cdd6d2 869 if ($oldversion < 2008111800) {
40c792c3 870
871 /// Define index name (unique) to be added to role
872 $table = new xmldb_table('role');
873 $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name'));
874
875 /// Conditionally launch add index name
876 if (!$dbman->index_exists($table, $index)) {
877 $dbman->add_index($table, $index);
878 }
879
880 /// Main savepoint reached
a4cdd6d2 881 upgrade_main_savepoint(true, 2008111800);
40c792c3 882 }
883
884/// Add a unique index to the role.shortname column.
a4cdd6d2 885 if ($oldversion < 2008111801) {
40c792c3 886
887 /// Define index shortname (unique) to be added to role
888 $table = new xmldb_table('role');
889 $index = new xmldb_index('shortname', XMLDB_INDEX_UNIQUE, array('shortname'));
890
891 /// Conditionally launch add index shortname
892 if (!$dbman->index_exists($table, $index)) {
893 $dbman->add_index($table, $index);
894 }
895
896 /// Main savepoint reached
a4cdd6d2 897 upgrade_main_savepoint(true, 2008111801);
40c792c3 898 }
899
a4cdd6d2 900 if ($oldversion < 2008120700) {
82bd6a5e 901
902 /// Changing precision of field shortname on table course_request to (100)
903 $table = new xmldb_table('course_request');
2a88f626 904 $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname');
82bd6a5e 905
da750a51 906 /// Before changing the field, drop dependent indexes
907 /// Define index shortname (not unique) to be dropped form course_request
908 $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname'));
909 /// Conditionally launch drop index shortname
910 if ($dbman->index_exists($table, $index)) {
911 $dbman->drop_index($table, $index);
912 }
913
82bd6a5e 914 /// Launch change of precision for field shortname
915 $dbman->change_field_precision($table, $field);
916
da750a51 917 /// After changing the field, recreate dependent indexes
918 /// Define index shortname (not unique) to be added to course_request
919 $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname'));
920 /// Conditionally launch add index shortname
921 if (!$dbman->index_exists($table, $index)) {
922 $dbman->add_index($table, $index);
923 }
924
82bd6a5e 925 /// Main savepoint reached
a4cdd6d2 926 upgrade_main_savepoint(true, 2008120700);
82bd6a5e 927 }
928
a4cdd6d2 929 if ($oldversion < 2008120801) {
82bd6a5e 930
931 /// Changing precision of field shortname on table mnet_enrol_course to (100)
932 $table = new xmldb_table('mnet_enrol_course');
2a88f626 933 $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname');
82bd6a5e 934
935 /// Launch change of precision for field shortname
936 $dbman->change_field_precision($table, $field);
937
938 /// Main savepoint reached
a4cdd6d2 939 upgrade_main_savepoint(true, 2008120801);
82bd6a5e 940 }
941
a4cdd6d2 942 if ($oldversion < 2008121701) {
0953a4e7 943
944 /// Define field availablefrom to be added to course_modules
945 $table = new xmldb_table('course_modules');
2a88f626 946 $field = new xmldb_field('availablefrom', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionexpected');
0953a4e7 947
948 /// Conditionally launch add field availablefrom
949 if (!$dbman->field_exists($table, $field)) {
950 $dbman->add_field($table, $field);
951 }
952
953 /// Define field availableuntil to be added to course_modules
2a88f626 954 $field = new xmldb_field('availableuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availablefrom');
0953a4e7 955
956 /// Conditionally launch add field availableuntil
957 if (!$dbman->field_exists($table, $field)) {
958 $dbman->add_field($table, $field);
959 }
82bd6a5e 960
0953a4e7 961 /// Define field showavailability to be added to course_modules
2a88f626 962 $field = new xmldb_field('showavailability', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availableuntil');
0953a4e7 963
964 /// Conditionally launch add field showavailability
965 if (!$dbman->field_exists($table, $field)) {
966 $dbman->add_field($table, $field);
967 }
82bd6a5e 968
0953a4e7 969 /// Define table course_modules_availability to be created
970 $table = new xmldb_table('course_modules_availability');
971
972 /// Adding fields to table course_modules_availability
2a88f626 973 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
974 $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
975 $table->add_field('sourcecmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
976 $table->add_field('requiredcompletion', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null);
977 $table->add_field('gradeitemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
978 $table->add_field('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
979 $table->add_field('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
0953a4e7 980
981 /// Adding keys to table course_modules_availability
982 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
cbb17d54 983 $table->add_key('coursemoduleid', XMLDB_KEY_FOREIGN, array('coursemoduleid'), 'course_modules', array('id'));
984 $table->add_key('sourcecmid', XMLDB_KEY_FOREIGN, array('sourcecmid'), 'course_modules', array('id'));
985 $table->add_key('gradeitemid', XMLDB_KEY_FOREIGN, array('gradeitemid'), 'grade_items', array('id'));
0953a4e7 986
987 /// Conditionally launch create table for course_modules_availability
988 if (!$dbman->table_exists($table)) {
989 $dbman->create_table($table);
990 }
991
82bd6a5e 992 /// Changes to modinfo mean we need to rebuild course cache
a9a0b93d 993 require_once($CFG->dirroot . '/course/lib.php');
8b6a0968 994 rebuild_course_cache(0, true);
9136a60c 995
9d510a2e 996 /// Main savepoint reached
a4cdd6d2 997 upgrade_main_savepoint(true, 2008121701);
9d510a2e 998 }
999
a4cdd6d2 1000 if ($oldversion < 2009010500) {
656be893 1001 /// clean up config table a bit
1002 unset_config('session_error_counter');
1003
1004 /// Main savepoint reached
a4cdd6d2 1005 upgrade_main_savepoint(true, 2009010500);
656be893 1006 }
1007
a4cdd6d2 1008 if ($oldversion < 2009010600) {
656be893 1009
1010 /// Define field originalquestion to be dropped from question_states
1011 $table = new xmldb_table('question_states');
1012 $field = new xmldb_field('originalquestion');
1013
1014 /// Conditionally launch drop field originalquestion
1015 if ($dbman->field_exists($table, $field)) {
1016 $dbman->drop_field($table, $field);
1017 }
1018
1019 /// Main savepoint reached
a4cdd6d2 1020 upgrade_main_savepoint(true, 2009010600);
656be893 1021 }
1022
a4cdd6d2 1023 if ($oldversion < 2009010601) {
656be893 1024
1025 /// Changing precision of field ip on table log to (45)
1026 $table = new xmldb_table('log');
2a88f626 1027 $field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'userid');
656be893 1028
1029 /// Launch change of precision for field ip
1030 $dbman->change_field_precision($table, $field);
1031
1032 /// Main savepoint reached
a4cdd6d2 1033 upgrade_main_savepoint(true, 2009010601);
656be893 1034 }
1035
a4cdd6d2 1036 if ($oldversion < 2009010602) {
656be893 1037
1038 /// Changing precision of field lastip on table user to (45)
1039 $table = new xmldb_table('user');
2a88f626 1040 $field = new xmldb_field('lastip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'currentlogin');
656be893 1041
1042 /// Launch change of precision for field lastip
1043 $dbman->change_field_precision($table, $field);
1044
1045 /// Main savepoint reached
a4cdd6d2 1046 upgrade_main_savepoint(true, 2009010602);
656be893 1047 }
1048
a4cdd6d2 1049 if ($oldversion < 2009010603) {
656be893 1050
1051 /// Changing precision of field ip_address on table mnet_host to (45)
1052 $table = new xmldb_table('mnet_host');
2a88f626 1053 $field = new xmldb_field('ip_address', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'wwwroot');
656be893 1054
1055 /// Launch change of precision for field ip_address
1056 $dbman->change_field_precision($table, $field);
1057
1058 /// Main savepoint reached
a4cdd6d2 1059 upgrade_main_savepoint(true, 2009010603);
656be893 1060 }
1061
a4cdd6d2 1062 if ($oldversion < 2009010604) {
656be893 1063
1064 /// Changing precision of field ip on table mnet_log to (45)
1065 $table = new xmldb_table('mnet_log');
2a88f626 1066 $field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'userid');
656be893 1067
1068 /// Launch change of precision for field ip
1069 $dbman->change_field_precision($table, $field);
1070
1071 /// Main savepoint reached
a4cdd6d2 1072 upgrade_main_savepoint(true, 2009010604);
656be893 1073 }
1074
a4cdd6d2 1075 if ($oldversion < 2009011000) {
ab2eb65c 1076
1077 /// Changing nullability of field configdata on table block_instance to null
1078 $table = new xmldb_table('block_instance');
1079 $field = new xmldb_field('configdata');
2a88f626 1080 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'visible');
ab2eb65c 1081
1082 /// Launch change of nullability for field configdata
1083 $dbman->change_field_notnull($table, $field);
1084
1085 /// Main savepoint reached
a4cdd6d2 1086 upgrade_main_savepoint(true, 2009011000);
ab2eb65c 1087 }
1088
a4cdd6d2 1089 if ($oldversion < 2009011100) {
1caea91e 1090 /// Remove unused settings
1091 unset_config('zip');
1092 unset_config('unzip');
1093 unset_config('adminblocks_initialised');
1094
1095 /// Main savepoint reached
a4cdd6d2 1096 upgrade_main_savepoint(true, 2009011100);
1caea91e 1097 }
1098
a4cdd6d2 1099 if ($oldversion < 2009011101) {
eb6a973c 1100 /// Migrate backup settings to core plugin config table
1101 $configs = $DB->get_records('backup_config');
1102 foreach ($configs as $config) {
1103 set_config($config->name, $config->value, 'backup');
1104 }
1105
1106 /// Define table to be dropped
1107 $table = new xmldb_table('backup_config');
1108
1109 /// Launch drop table for old backup config
1110 $dbman->drop_table($table);
1111
1112 /// Main savepoint reached
a4cdd6d2 1113 upgrade_main_savepoint(true, 2009011101);
eb6a973c 1114 }
1115
a4cdd6d2 1116 if ($oldversion < 2009011303) {
301bf0b2 1117
1118 /// Define table config_log to be created
1119 $table = new xmldb_table('config_log');
1120
1121 /// Adding fields to table config_log
2a88f626 1122 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1123 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1124 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1125 $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null);
1126 $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
1127 $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
1128 $table->add_field('oldvalue', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
301bf0b2 1129
1130 /// Adding keys to table config_log
1131 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1132 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1133
1134 /// Adding indexes to table config_log
1135 $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
1136
1137 /// Launch create table for config_log
1138 $dbman->create_table($table);
1139
1140 /// Main savepoint reached
a4cdd6d2 1141 upgrade_main_savepoint(true, 2009011303);
301bf0b2 1142 }
1143
a4cdd6d2 1144 if ($oldversion < 2009011900) {
3f57bd45 1145
1146 /// Define table sessions2 to be dropped
1147 $table = new xmldb_table('sessions2');
1148
1149 /// Conditionally launch drop table for sessions
1150 if ($dbman->table_exists($table)) {
1151 $dbman->drop_table($table);
1152 }
1153
1154 /// Define table sessions to be dropped
1155 $table = new xmldb_table('sessions');
1156
1157 /// Conditionally launch drop table for sessions
1158 if ($dbman->table_exists($table)) {
1159 $dbman->drop_table($table);
1160 }
1161
1162 /// Define table sessions to be created
1163 $table = new xmldb_table('sessions');
1164
1165 /// Adding fields to table sessions
2a88f626 1166 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1167 $table->add_field('state', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
1168 $table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null);
1169 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1170 $table->add_field('sessdata', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
1171 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1172 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1173 $table->add_field('firstip', XMLDB_TYPE_CHAR, '45', null, null, null, null);
1174 $table->add_field('lastip', XMLDB_TYPE_CHAR, '45', null, null, null, null);
3f57bd45 1175
1176 /// Adding keys to table sessions
1177 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1178 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1179
1180 /// Adding indexes to table sessions
1181 $table->add_index('state', XMLDB_INDEX_NOTUNIQUE, array('state'));
1182 $table->add_index('sid', XMLDB_INDEX_UNIQUE, array('sid'));
1183 $table->add_index('timecreated', XMLDB_INDEX_NOTUNIQUE, array('timecreated'));
1184 $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
1185
1186 /// Launch create table for sessions
1187 $dbman->create_table($table);
1188
1189 /// Main savepoint reached
a4cdd6d2 1190 upgrade_main_savepoint(true, 2009011900);
3f57bd45 1191 }
1192
a4cdd6d2 1193 if ($oldversion < 2009021800) {
eb2761f8 1194 // Converting format of grade conditions, if any exist, to percentages.
75564228 1195 $DB->execute("
1196UPDATE {course_modules_availability} SET grademin=(
1197 SELECT 100.0*({course_modules_availability}.grademin-gi.grademin)
eb2761f8 1198 /(gi.grademax-gi.grademin)
1199 FROM {grade_items} gi
75564228 1200 WHERE gi.id={course_modules_availability}.gradeitemid)
1201WHERE gradeitemid IS NOT NULL AND grademin IS NOT NULL");
1202 $DB->execute("
1203UPDATE {course_modules_availability} SET grademax=(
1204 SELECT 100.0*({course_modules_availability}.grademax-gi.grademin)
eb2761f8 1205 /(gi.grademax-gi.grademin)
1206 FROM {grade_items} gi
75564228 1207 WHERE gi.id={course_modules_availability}.gradeitemid)
1208WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
1209
1210 /// Main savepoint reached
a4cdd6d2 1211 upgrade_main_savepoint(true, 2009021800);
75564228 1212 }
82601760 1213
a4cdd6d2 1214 if ($oldversion < 2009021801) {
bc7ec91a 1215 /// Define field backuptype to be added to backup_log
382123a0 1216 $table = new xmldb_table('backup_log');
2a88f626 1217 $field = new xmldb_field('backuptype', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, 'info');
bc7ec91a 1218 /// Conditionally Launch add field backuptype and set all old records as 'scheduledbackup' records.
1219 if (!$dbman->field_exists($table, $field)) {
1220 $dbman->add_field($table, $field);
1221 $DB->execute("UPDATE {backup_log} SET backuptype='scheduledbackup'");
1222 }
75564228 1223
bc7ec91a 1224 /// Main savepoint reached
a4cdd6d2 1225 upgrade_main_savepoint(true, 2009021801);
bc7ec91a 1226 }
82601760 1227
af52ecee 1228 /// Add default sort order for question types.
a4cdd6d2 1229 if ($oldversion < 2009030300) {
af52ecee 1230 set_config('multichoice_sortorder', 1, 'question');
1231 set_config('truefalse_sortorder', 2, 'question');
1232 set_config('shortanswer_sortorder', 3, 'question');
1233 set_config('numerical_sortorder', 4, 'question');
1234 set_config('calculated_sortorder', 5, 'question');
1235 set_config('essay_sortorder', 6, 'question');
1236 set_config('match_sortorder', 7, 'question');
1237 set_config('randomsamatch_sortorder', 8, 'question');
1238 set_config('multianswer_sortorder', 9, 'question');
1239 set_config('description_sortorder', 10, 'question');
1240 set_config('random_sortorder', 11, 'question');
1241 set_config('missingtype_sortorder', 12, 'question');
1242
a4cdd6d2 1243 upgrade_main_savepoint(true, 2009030300);
af52ecee 1244 }
1245
82701e24 1246 /// MDL-18132 replace the use a new Role allow switch settings page, instead of
1247 /// $CFG->allowuserswitchrolestheycantassign
a4cdd6d2 1248 if ($oldversion < 2009032000) {
82701e24 1249 /// First create the new table.
1250 $table = new xmldb_table('role_allow_switch');
1251
1252 /// Adding fields to table role_allow_switch
2a88f626 1253 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1254 $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1255 $table->add_field('allowswitch', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
82701e24 1256
1257 /// Adding keys to table role_allow_switch
1258 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1259 $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
1260 $table->add_key('allowswitch', XMLDB_KEY_FOREIGN, array('allowswitch'), 'role', array('id'));
1261
1262 /// Adding indexes to table role_allow_switch
1263 $table->add_index('roleid-allowoverride', XMLDB_INDEX_UNIQUE, array('roleid', 'allowswitch'));
1264
1265 /// Conditionally launch create table for role_allow_switch
1266 if (!$dbman->table_exists($table)) {
1267 $dbman->create_table($table);
1268 }
1269
1270 /// Main savepoint reached
a4cdd6d2 1271 upgrade_main_savepoint(true, 2009032000);
82701e24 1272 }
0fc9c009 1273
a4cdd6d2 1274 if ($oldversion < 2009032001) {
82701e24 1275 /// Copy from role_allow_assign into the new table.
dc740f97 1276 $DB->execute('INSERT INTO {role_allow_switch} (roleid, allowswitch)
1277 SELECT roleid, allowassign FROM {role_allow_assign}');
82701e24 1278
1279 /// Unset the config variable used in 1.9.
1280 unset_config('allowuserswitchrolestheycantassign');
1281
1282 /// Main savepoint reached
a4cdd6d2 1283 upgrade_main_savepoint(true, 2009032001);
82701e24 1284 }
c94985ef 1285
a4cdd6d2 1286 if ($oldversion < 2009033100) {
c94985ef 1287 require_once("$CFG->dirroot/filter/tex/lib.php");
1288 filter_tex_updatedcallback(null);
1289 /// Main savepoint reached
a4cdd6d2 1290 upgrade_main_savepoint(true, 2009033100);
c94985ef 1291 }
1292
a4cdd6d2 1293 if ($oldversion < 2009040300) {
0fc9c009 1294
1295 /// Define table filter_active to be created
1296 $table = new xmldb_table('filter_active');
1297
1298 /// Adding fields to table filter_active
2a88f626 1299 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1300 $table->add_field('filter', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
1301 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1302 $table->add_field('active', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null);
1303 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
0fc9c009 1304
1305 /// Adding keys to table filter_active
1306 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1307 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
1308
1309 /// Adding indexes to table filter_active
1310 $table->add_index('contextid-filter', XMLDB_INDEX_UNIQUE, array('contextid', 'filter'));
1311
1312 /// Conditionally launch create table for filter_active
1313 if (!$dbman->table_exists($table)) {
1314 $dbman->create_table($table);
1315 }
1316
1317 /// Main savepoint reached
a4cdd6d2 1318 upgrade_main_savepoint(true, 2009040300);
0fc9c009 1319 }
1320
a4cdd6d2 1321 if ($oldversion < 2009040301) {
0fc9c009 1322
1323 /// Define table filter_config to be created
1324 $table = new xmldb_table('filter_config');
1325
1326 /// Adding fields to table filter_config
2a88f626 1327 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1328 $table->add_field('filter', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
1329 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1330 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
1331 $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
0fc9c009 1332
1333 /// Adding keys to table filter_config
1334 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1335 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
1336
1337 /// Adding indexes to table filter_config
1338 $table->add_index('contextid-filter-name', XMLDB_INDEX_UNIQUE, array('contextid', 'filter', 'name'));
1339
1340 /// Conditionally launch create table for filter_config
1341 if (!$dbman->table_exists($table)) {
1342 $dbman->create_table($table);
1343 }
1344
1345 /// Main savepoint reached
a4cdd6d2 1346 upgrade_main_savepoint(true, 2009040301);
0fc9c009 1347 }
1348
a4cdd6d2 1349 if ($oldversion < 2009040302) {
c07e6d8d 1350 /// Transfer current settings from $CFG->textfilters
1351 $disabledfilters = filter_get_all_installed();
1352 if (empty($CFG->textfilters)) {
1353 $activefilters = array();
1354 } else {
1355 $activefilters = explode(',', $CFG->textfilters);
1356 }
1357 $syscontext = get_context_instance(CONTEXT_SYSTEM);
1358 $sortorder = 1;
1359 foreach ($activefilters as $filter) {
1360 filter_set_global_state($filter, TEXTFILTER_ON, $sortorder);
1361 $sortorder += 1;
1362 unset($disabledfilters[$filter]);
1363 }
1364 foreach ($disabledfilters as $filter => $notused) {
1365 filter_set_global_state($filter, TEXTFILTER_DISABLED, $sortorder);
1366 $sortorder += 1;
1367 }
1368
1369 /// Main savepoint reached
a4cdd6d2 1370 upgrade_main_savepoint(true, 2009040302);
c07e6d8d 1371 }
1372
a4cdd6d2 1373 if ($oldversion < 2009040600) {
bbb45905 1374 /// Ensure that $CFG->stringfilters is set.
1375 if (empty($CFG->stringfilters)) {
1376 if (!empty($CFG->filterall)) {
1377 set_config('stringfilters', $CFG->textfilters);
1378 } else {
1379 set_config('stringfilters', '');
1380 }
1381 }
1382
1383 set_config('filterall', !empty($CFG->stringfilters));
1384 unset_config('textfilters');
1385
1386 /// Main savepoint reached
a4cdd6d2 1387 upgrade_main_savepoint(true, 2009040600);
bbb45905 1388 }
1389
a4cdd6d2 1390 if ($oldversion < 2009041700) {
e7c6bf0e 1391 /// To ensure the UI remains consistent with no behaviour change, any
1392 /// 'until' date in an activity condition should have 1 second subtracted
1393 /// (to go from 0:00 on the following day to 23:59 on the previous one).
1394 $DB->execute('UPDATE {course_modules} SET availableuntil = availableuntil - 1 WHERE availableuntil <> 0');
6861b6fe 1395 require_once($CFG->dirroot . '/course/lib.php');
0f9534c1 1396 rebuild_course_cache(0, true);
e7c6bf0e 1397
1398 /// Main savepoint reached
a4cdd6d2 1399 upgrade_main_savepoint(true, 2009041700);
e7c6bf0e 1400 }
1401
a4cdd6d2 1402 if ($oldversion < 2009042600) {
6bdf4c99 1403 /// Deleting orphaned messages from deleted users.
1404 require_once($CFG->dirroot.'/message/lib.php');
1405 /// Detect deleted users with messages sent(useridfrom) and not read
1406 if ($deletedusers = $DB->get_records_sql('SELECT DISTINCT u.id
1407 FROM {user} u
1408 JOIN {message} m ON m.useridfrom = u.id
1409 WHERE u.deleted = ?', array(1))) {
1410 foreach ($deletedusers as $deleteduser) {
1411 message_move_userfrom_unread2read($deleteduser->id); // move messages
1412 }
1413 }
1414 /// Main savepoint reached
a4cdd6d2 1415 upgrade_main_savepoint(true, 2009042600);
6bdf4c99 1416 }
1417
e37cd84a 1418 /// Dropping all enums/check contraints from core. MDL-18577
a4cdd6d2 1419 if ($oldversion < 2009042700) {
e37cd84a 1420
1421 /// Changing list of values (enum) of field stattype on table stats_daily to none
1422 $table = new xmldb_table('stats_daily');
2a88f626 1423 $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
e37cd84a 1424
1425 /// Launch change of list of values for field stattype
2a88f626 1426 $dbman->drop_enum_from_field($table, $field);
e37cd84a 1427
1428 /// Changing list of values (enum) of field stattype on table stats_weekly to none
1429 $table = new xmldb_table('stats_weekly');
2a88f626 1430 $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
e37cd84a 1431
1432 /// Launch change of list of values for field stattype
2a88f626 1433 $dbman->drop_enum_from_field($table, $field);
e37cd84a 1434
1435 /// Changing list of values (enum) of field stattype on table stats_monthly to none
1436 $table = new xmldb_table('stats_monthly');
2a88f626 1437 $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
e37cd84a 1438
1439 /// Launch change of list of values for field stattype
2a88f626 1440 $dbman->drop_enum_from_field($table, $field);
e37cd84a 1441
1442 /// Changing list of values (enum) of field publishstate on table post to none
1443 $table = new xmldb_table('post');
2a88f626 1444 $field = new xmldb_field('publishstate', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'draft', 'attachment');
e37cd84a 1445
1446 /// Launch change of list of values for field publishstate
2a88f626 1447 $dbman->drop_enum_from_field($table, $field);
e37cd84a 1448
1449 /// Main savepoint reached
a4cdd6d2 1450 upgrade_main_savepoint(true, 2009042700);
e37cd84a 1451 }
1452
a4cdd6d2 1453 if ($oldversion < 2009043000) {
c045e45a 1454 unset_config('grade_report_showgroups');
a4cdd6d2 1455 upgrade_main_savepoint(true, 2009043000);
c045e45a 1456 }
1457
a4cdd6d2 1458 if ($oldversion < 2009050600) {
e88462a0 1459 /// Site front page blocks need to be moved due to page name change.
1460 $DB->set_field('block_instance', 'pagetype', 'site-index', array('pagetype' => 'course-view', 'pageid' => SITEID));
1461
1462 /// Main savepoint reached
a4cdd6d2 1463 upgrade_main_savepoint(true, 2009050600);
e88462a0 1464 }
1465
a4cdd6d2 1466 if ($oldversion < 2009050601) {
66b10689 1467
3aceb097 1468 /// Define table block_instance to be renamed to block_instances
66b10689 1469 $table = new xmldb_table('block_instance');
1470
1471 /// Launch rename table for block_instance
3aceb097 1472 $dbman->rename_table($table, 'block_instances');
66b10689 1473
1474 /// Main savepoint reached
a4cdd6d2 1475 upgrade_main_savepoint(true, 2009050601);
66b10689 1476 }
1477
a4cdd6d2 1478 if ($oldversion < 2009050602) {
66b10689 1479
1480 /// Define table block_instance to be renamed to block_instance_old
1481 $table = new xmldb_table('block_pinned');
1482
1483 /// Launch rename table for block_instance
1484 $dbman->rename_table($table, 'block_pinned_old');
1485
1486 /// Main savepoint reached
a4cdd6d2 1487 upgrade_main_savepoint(true, 2009050602);
66b10689 1488 }
1489
a4cdd6d2 1490 if ($oldversion < 2009050603) {
66b10689 1491
1492 /// Define table block_instance_old to be created
1493 $table = new xmldb_table('block_instance_old');
1494
1495 /// Adding fields to table block_instance_old
2b212777 1496 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1497 $table->add_field('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1498 $table->add_field('blockid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
1499 $table->add_field('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
1500 $table->add_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null);
1501 $table->add_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null);
1502 $table->add_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0');
1503 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
1504 $table->add_field('configdata', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
66b10689 1505
1506 /// Adding keys to table block_instance_old
1507 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1508 $table->add_key('blockid', XMLDB_KEY_FOREIGN, array('blockid'), 'block', array('id'));
1509
1510 /// Adding indexes to table block_instance_old
1511 $table->add_index('pageid', XMLDB_INDEX_NOTUNIQUE, array('pageid'));
1512 $table->add_index('pagetype', XMLDB_INDEX_NOTUNIQUE, array('pagetype'));
1513
1514 /// Conditionally launch create table for block_instance_old
1515 if (!$dbman->table_exists($table)) {
1516 $dbman->create_table($table);
1517 }
1518
1519 /// Main savepoint reached
a4cdd6d2 1520 upgrade_main_savepoint(true, 2009050603);
66b10689 1521 }
1522
a4cdd6d2 1523 if ($oldversion < 2009050604) {
66b10689 1524 /// Copy current blocks data from block_instances to block_instance_old
35550fd6 1525 $DB->execute('INSERT INTO {block_instance_old} (oldid, blockid, pageid, pagetype, position, weight, visible, configdata)
1526 SELECT id, blockid, pageid, pagetype, position, weight, visible, configdata FROM {block_instances} ORDER BY id');
66b10689 1527
a4cdd6d2 1528 upgrade_main_savepoint(true, 2009050604);
66b10689 1529 }
1530
a4cdd6d2 1531 if ($oldversion < 2009050605) {
66b10689 1532
1533 /// Define field multiple to be dropped from block
1534 $table = new xmldb_table('block');
1535 $field = new xmldb_field('multiple');
1536
1537 /// Conditionally launch drop field multiple
1538 if ($dbman->field_exists($table, $field)) {
1539 $dbman->drop_field($table, $field);
1540 }
1541
1542 /// Main savepoint reached
a4cdd6d2 1543 upgrade_main_savepoint(true, 2009050605);
66b10689 1544 }
1545
a4cdd6d2 1546 if ($oldversion < 2009050606) {
66b10689 1547 $table = new xmldb_table('block_instances');
1548
1549 /// Rename field weight on table block_instances to defaultweight
2b212777 1550 $field = new xmldb_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0', 'position');
66b10689 1551 $dbman->rename_field($table, $field, 'defaultweight');
1552
1553 /// Rename field position on table block_instances to defaultregion
2b212777 1554 $field = new xmldb_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, 'pagetype');
66b10689 1555 $dbman->rename_field($table, $field, 'defaultregion');
1556
1557 /// Main savepoint reached
a4cdd6d2 1558 upgrade_main_savepoint(true, 2009050606);
66b10689 1559 }
1560
a4cdd6d2 1561 if ($oldversion < 2009050607) {
66b10689 1562 /// Changing precision of field defaultregion on table block_instances to (16)
a26146d5 1563 $table = new xmldb_table('block_instances');
1564 $field = new xmldb_field('defaultregion', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, 'pagetype');
66b10689 1565
1566 /// Launch change of precision for field defaultregion
1567 $dbman->change_field_precision($table, $field);
1568
1569 /// Main savepoint reached
a4cdd6d2 1570 upgrade_main_savepoint(true, 2009050607);
66b10689 1571 }
1572
a4cdd6d2 1573 if ($oldversion < 2009050608) {
66b10689 1574 /// Change regions to the new notation
1575 $DB->set_field('block_instances', 'defaultregion', 'side-pre', array('defaultregion' => 'l'));
1576 $DB->set_field('block_instances', 'defaultregion', 'side-post', array('defaultregion' => 'r'));
1577 $DB->set_field('block_instances', 'defaultregion', 'course-view-top', array('defaultregion' => 'c'));
1578 // This third one is a custom value from contrib/patches/center_blocks_position_patch and the
1579 // flex page course format. Hopefully this new value is an adequate alternative.
1580
1581 /// Main savepoint reached
a4cdd6d2 1582 upgrade_main_savepoint(true, 2009050608);
66b10689 1583 }
1584
a4cdd6d2 1585 if ($oldversion < 2009050609) {
66b10689 1586
1587 /// Define key blockname (unique) to be added to block
1588 $table = new xmldb_table('block');
1589 $key = new xmldb_key('blockname', XMLDB_KEY_UNIQUE, array('name'));
1590
1591 /// Launch add key blockname
1592 $dbman->add_key($table, $key);
1593
1594 /// Main savepoint reached
a4cdd6d2 1595 upgrade_main_savepoint(true, 2009050609);
66b10689 1596 }
1597
a4cdd6d2 1598 if ($oldversion < 2009050610) {
66b10689 1599 $table = new xmldb_table('block_instances');
1600
1601 /// Define field blockname to be added to block_instances
2b212777 1602 $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, null, null, null, 'blockid');
66b10689 1603 if (!$dbman->field_exists($table, $field)) {
1604 $dbman->add_field($table, $field);
1605 }
1606
1607 /// Define field contextid to be added to block_instances
2b212777 1608 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'blockname');
66b10689 1609 if (!$dbman->field_exists($table, $field)) {
1610 $dbman->add_field($table, $field);
1611 }
1612
1613 /// Define field showinsubcontexts to be added to block_instances
2b212777 1614 $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, null, null, null, 'contextid');
66b10689 1615 if (!$dbman->field_exists($table, $field)) {
1616 $dbman->add_field($table, $field);
1617 }
1618
1619 /// Define field subpagepattern to be added to block_instances
2b212777 1620 $field = new xmldb_field('subpagepattern', XMLDB_TYPE_CHAR, '16', null, null, null, null, 'pagetype');
66b10689 1621 if (!$dbman->field_exists($table, $field)) {
1622 $dbman->add_field($table, $field);
1623 }
1624
1625 /// Main savepoint reached
a4cdd6d2 1626 upgrade_main_savepoint(true, 2009050610);
66b10689 1627 }
1628
a4cdd6d2 1629 if ($oldversion < 2009050611) {
66b10689 1630 $table = new xmldb_table('block_instances');
1631
1632 /// Fill in blockname from blockid
1633 $DB->execute("UPDATE {block_instances} SET blockname = (SELECT name FROM {block} WHERE id = blockid)");
1634
1635 /// Set showinsubcontexts = 0 for all rows.
1636 $DB->execute("UPDATE {block_instances} SET showinsubcontexts = 0");
1637
1638 /// Main savepoint reached
a4cdd6d2 1639 upgrade_main_savepoint(true, 2009050611);
66b10689 1640 }
1641
a4cdd6d2 1642 if ($oldversion < 2009050612) {
66b10689 1643
1644 /// Rename field pagetype on table block_instances to pagetypepattern
1645 $table = new xmldb_table('block_instances');
2b212777 1646 $field = new xmldb_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'pageid');
66b10689 1647
1648 /// Launch rename field pagetype
1649 $dbman->rename_field($table, $field, 'pagetypepattern');
1650
1651 /// Main savepoint reached
a4cdd6d2 1652 upgrade_main_savepoint(true, 2009050612);
66b10689 1653 }
1654
a4cdd6d2 1655 if ($oldversion < 2009050613) {
66b10689 1656 /// fill in contextid and subpage, and update pagetypepattern from pagetype and pageid
1657
1658 /// site-index
1659 $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
eb2761f8 1660 $DB->execute("UPDATE {block_instances} SET contextid = " . $frontpagecontext->id . ",
1661 pagetypepattern = 'site-index',
1662 subpagepattern = NULL
1663 WHERE pagetypepattern = 'site-index'");
66b10689 1664
1665 /// course-view
eb2761f8 1666 $DB->execute("UPDATE {block_instances} SET
1667 contextid = (
1668 SELECT {context}.id
1669 FROM {context}
1670 JOIN {course} ON instanceid = {course}.id AND contextlevel = " . CONTEXT_COURSE . "
1671 WHERE {course}.id = pageid
1672 ),
1673 pagetypepattern = 'course-view-*',
1674 subpagepattern = NULL
1675 WHERE pagetypepattern = 'course-view'");
66b10689 1676
1677 /// admin
1678 $syscontext = get_context_instance(CONTEXT_SYSTEM);
eb2761f8 1679 $DB->execute("UPDATE {block_instances} SET
1680 contextid = " . $syscontext->id . ",
1681 pagetypepattern = 'admin-*',
1682 subpagepattern = NULL
1683 WHERE pagetypepattern = 'admin'");
66b10689 1684
1685 /// my-index
eb2761f8 1686 $DB->execute("UPDATE {block_instances} SET
1687 contextid = (
1688 SELECT {context}.id
1689 FROM {context}
1690 JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . "
1691 WHERE {user}.id = pageid
1692 ),
1693 pagetypepattern = 'my-index',
1694 subpagepattern = NULL
1695 WHERE pagetypepattern = 'my-index'");
66b10689 1696
1697 /// tag-index
eb2761f8 1698 $DB->execute("UPDATE {block_instances} SET
1699 contextid = " . $syscontext->id . ",
1700 pagetypepattern = 'tag-index',
1701 subpagepattern = pageid
1702 WHERE pagetypepattern = 'tag-index'");
66b10689 1703
1704 /// blog-view
eb2761f8 1705 $DB->execute("UPDATE {block_instances} SET
1706 contextid = (
1707 SELECT {context}.id
1708 FROM {context}
1709 JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . "
1710 WHERE {user}.id = pageid
1711 ),
1712 pagetypepattern = 'blog-index',
1713 subpagepattern = NULL
1714 WHERE pagetypepattern = 'blog-view'");
66b10689 1715
1716 /// mod-xxx-view
1717 $moduleswithblocks = array('chat', 'data', 'lesson', 'quiz', 'dimdim', 'game', 'wiki', 'oublog');
1718 foreach ($moduleswithblocks as $modname) {
1719 if (!$dbman->table_exists($modname)) {
1720 continue;
1721 }
eb2761f8 1722 $DB->execute("UPDATE {block_instances} SET
1723 contextid = (
1724 SELECT {context}.id
1725 FROM {context}
1726 JOIN {course_modules} ON instanceid = {course_modules}.id AND contextlevel = " . CONTEXT_MODULE . "
1727 JOIN {modules} ON {modules}.id = {course_modules}.module AND {modules}.name = '$modname'
1728 JOIN {{$modname}} ON {course_modules}.instance = {{$modname}}.id
1729 WHERE {{$modname}}.id = pageid
1730 ),
1731 pagetypepattern = 'blog-index',
1732 subpagepattern = NULL
1733 WHERE pagetypepattern = 'blog-view'");
66b10689 1734 }
1735
1736 /// Main savepoint reached
a4cdd6d2 1737 upgrade_main_savepoint(true, 2009050613);
66b10689 1738 }
1739
a4cdd6d2 1740 if ($oldversion < 2009050614) {
66b10689 1741 /// fill in any missing contextids with a dummy value, so we can add the not-null constraint.
bf659cf0 1742 $DB->execute("UPDATE {block_instances} SET contextid = 0 WHERE contextid IS NULL");
66b10689 1743
1744 /// Main savepoint reached
a4cdd6d2 1745 upgrade_main_savepoint(true, 2009050614);
66b10689 1746 }
1747
a4cdd6d2 1748 if ($oldversion < 2009050615) {
66b10689 1749 $table = new xmldb_table('block_instances');
1750
57c3a358
EL
1751 /// Arrived here, any block_instances record without blockname is one
1752 /// orphan block coming from 1.9. Just delete them. MDL-22503
1753 $DB->delete_records_select('block_instances', 'blockname IS NULL');
1754
66b10689 1755 /// Changing nullability of field blockname on table block_instances to not null
2b212777 1756 $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'id');
66b10689 1757 $dbman->change_field_notnull($table, $field);
1758
1759 /// Changing nullability of field contextid on table block_instances to not null
2b212777 1760 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'blockname');
66b10689 1761 $dbman->change_field_notnull($table, $field);
1762
1763 /// Changing nullability of field showinsubcontexts on table block_instances to not null
2b212777 1764 $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, 'contextid');
66b10689 1765 $dbman->change_field_notnull($table, $field);
1766
1767 /// Main savepoint reached
a4cdd6d2 1768 upgrade_main_savepoint(true, 2009050615);
66b10689 1769 }
1770
a4cdd6d2 1771 if ($oldversion < 2009050616) {
66b10689 1772 /// Add exiting sticky blocks.
1773 $blocks = $DB->get_records('block');
1774 $syscontext = get_context_instance(CONTEXT_SYSTEM);
1775 $newregions = array(
1776 'l' => 'side-pre',
1777 'r' => 'side-post',
1778 'c' => 'course-view-top',
1779 );
1780 $stickyblocks = $DB->get_recordset('block_pinned_old');
1781 foreach ($stickyblocks as $stickyblock) {
4751e470
EL
1782 // Only if the block exists (avoid orphaned sticky blocks)
1783 if (!isset($blocks[$stickyblock->blockid]) || empty($blocks[$stickyblock->blockid]->name)) {
1784 continue;
1785 }
93d3a250 1786 $newblock = new object();
35fb85a7 1787 $newblock->blockname = $blocks[$stickyblock->blockid]->name;
66b10689 1788 $newblock->contextid = $syscontext->id;
1789 $newblock->showinsubcontexts = 1;
1790 switch ($stickyblock->pagetype) {
1791 case 'course-view':
1792 $newblock->pagetypepattern = 'course-view-*';
1793 break;
1794 default:
1795 $newblock->pagetypepattern = $stickyblock->pagetype;
1796 }
1797 $newblock->defaultregion = $newregions[$stickyblock->position];
1798 $newblock->defaultweight = $stickyblock->weight;
1799 $newblock->configdata = $stickyblock->configdata;
01de485d 1800 $newblock->visible = 1;
66b10689 1801 $DB->insert_record('block_instances', $newblock);
1802 }
1803
1804 /// Main savepoint reached
a4cdd6d2 1805 upgrade_main_savepoint(true, 2009050616);
66b10689 1806 }
1807
a4cdd6d2 1808 if ($oldversion < 2009050617) {
66b10689 1809
1810 /// Define table block_positions to be created
1811 $table = new xmldb_table('block_positions');
1812
1813 /// Adding fields to table block_positions
2b212777 1814 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1815 $table->add_field('blockinstanceid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1816 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1817 $table->add_field('pagetype', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
1818 $table->add_field('subpage', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null);
1819 $table->add_field('visible', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '1');
1820 $table->add_field('region', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null);
1821 $table->add_field('weight', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
66b10689 1822
1823 /// Adding keys to table block_positions
1824 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1825 $table->add_key('blockinstanceid', XMLDB_KEY_FOREIGN, array('blockinstanceid'), 'block_instances', array('id'));
1826 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
1827
1828 /// Adding indexes to table block_positions
1829 $table->add_index('blockinstanceid-contextid-pagetype-subpage', XMLDB_INDEX_UNIQUE, array('blockinstanceid', 'contextid', 'pagetype', 'subpage'));
1830
1831 /// Conditionally launch create table for block_positions
1832 if (!$dbman->table_exists($table)) {
1833 $dbman->create_table($table);
1834 }
1835
1836 /// Main savepoint reached
a4cdd6d2 1837 upgrade_main_savepoint(true, 2009050617);
66b10689 1838 }
1839
a4cdd6d2 1840 if ($oldversion < 2009050618) {
66b10689 1841 /// And block instances with visible = 0, copy that information to block_positions
1842 $DB->execute("INSERT INTO {block_positions} (blockinstanceid, contextid, pagetype, subpage, visible, region, weight)
1843 SELECT id, contextid,
1844 CASE WHEN pagetypepattern = 'course-view-*' THEN
1845 (SELECT " . $DB->sql_concat("'course-view-'", 'format') . "
1846 FROM {course}
1847 JOIN {context} ON {course}.id = {context}.instanceid
1848 WHERE {context}.id = contextid)
1849 ELSE pagetypepattern END,
1850 CASE WHEN subpagepattern IS NULL THEN ''
1851 ELSE subpagepattern END,
1852 0, defaultregion, defaultweight
1853 FROM {block_instances} WHERE visible = 0 AND pagetypepattern <> 'admin-*'");
1854
1855 /// Main savepoint reached
a4cdd6d2 1856 upgrade_main_savepoint(true, 2009050618);
66b10689 1857 }
1858
a4cdd6d2 1859 if ($oldversion < 2009050619) {
66b10689 1860 $table = new xmldb_table('block_instances');
1861
1862 /// Define field blockid to be dropped from block_instances
1863 $field = new xmldb_field('blockid');
1864 if ($dbman->field_exists($table, $field)) {
4276a19a 1865 /// Before dropping the field, drop dependent indexes
1866 $index = new xmldb_index('blockid', XMLDB_INDEX_NOTUNIQUE, array('blockid'));
1867 if ($dbman->index_exists($table, $index)) {
1868 /// Launch drop index blockid
1869 $dbman->drop_index($table, $index);
1870 }
66b10689 1871 $dbman->drop_field($table, $field);
1872 }
1873
1874 /// Define field pageid to be dropped from block_instances
1875 $field = new xmldb_field('pageid');
1876 if ($dbman->field_exists($table, $field)) {
4276a19a 1877 /// Before dropping the field, drop dependent indexes
1878 $index = new xmldb_index('pageid', XMLDB_INDEX_NOTUNIQUE, array('pageid'));
1879 if ($dbman->index_exists($table, $index)) {
1880 /// Launch drop index pageid
1881 $dbman->drop_index($table, $index);
1882 }
66b10689 1883 $dbman->drop_field($table, $field);
1884 }
1885
1886 /// Define field visible to be dropped from block_instances
1887 $field = new xmldb_field('visible');
1888 if ($dbman->field_exists($table, $field)) {
1889 $dbman->drop_field($table, $field);
1890 }
1891
1892 /// Main savepoint reached
a4cdd6d2 1893 upgrade_main_savepoint(true, 2009050619);
35079f53 1894 }
1895
a4cdd6d2 1896 if ($oldversion < 2009051200) {
ecdf5d17 1897 /// Let's check the status of mandatory mnet_host records, fixing them
1898 /// and moving "orphan" users to default localhost record. MDL-16879
aa9a6867 1899 echo $OUTPUT->notification('Fixing mnet records, this may take a while...', 'notifysuccess');
ecdf5d17 1900 upgrade_fix_incorrect_mnethostids();
1901
1902 /// Main savepoint reached
a4cdd6d2 1903 upgrade_main_savepoint(true, 2009051200);
ecdf5d17 1904 }
1905
a5747cf8 1906
a4cdd6d2 1907 if ($oldversion < 2009051700) {
a5747cf8 1908 /// migrate editor settings
1909 if (empty($CFG->htmleditor)) {
1910 set_config('texteditors', 'textarea');
1911 } else {
1912 set_config('texteditors', 'tinymce,textarea');
1913 }
1914
1915 unset_config('htmleditor');
1916 unset_config('defaulthtmleditor');
1917
1918 /// Main savepoint reached
a4cdd6d2 1919 upgrade_main_savepoint(true, 2009051700);
a5747cf8 1920 }
1921
6389e70a
PS
1922 /// Repeat 2009050607 upgrade step, which Petr commented out because of XMLDB
1923 /// stupidity, so lots of people will have missed.
a4cdd6d2 1924 if ($oldversion < 2009061600) {
52902cea 1925 /// Changing precision of field defaultregion on table block_instances to (16)
1926 $table = new xmldb_table('block_instances');
1927 $field = new xmldb_field('defaultregion', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, 'configdata');
1928
1929 /// Launch change of precision for field defaultregion
1930 $dbman->change_field_precision($table, $field);
1931
1932 /// Main savepoint reached
a4cdd6d2 1933 upgrade_main_savepoint(true, 2009061600);
52902cea 1934 }
1935
a4cdd6d2 1936 if ($oldversion < 2009061702) {
17da2e6f 1937 // standardizing plugin names
1938 if ($configs = $DB->get_records_select('config_plugins', "plugin LIKE 'quizreport_%'")) {
1939 foreach ($configs as $config) {
61676608 1940 unset_config($config->name, $config->plugin); /// unset old config
17da2e6f 1941 $config->plugin = str_replace('quizreport_', 'quiz_', $config->plugin);
61676608 1942 set_config($config->name, $config->value, $config->plugin); /// set new config
17da2e6f 1943 }
1944 }
1945 unset($configs);
a4cdd6d2 1946 upgrade_main_savepoint(true, 2009061702);
17da2e6f 1947 }
1948
a4cdd6d2 1949 if ($oldversion < 2009061703) {
17da2e6f 1950 // standardizing plugin names
1951 if ($configs = $DB->get_records_select('config_plugins', "plugin LIKE 'assignment_type_%'")) {
1952 foreach ($configs as $config) {
61676608 1953 unset_config($config->name, $config->plugin); /// unset old config
17da2e6f 1954 $config->plugin = str_replace('assignment_type_', 'assignment_', $config->plugin);
61676608 1955 set_config($config->name, $config->value, $config->plugin); /// set new config
17da2e6f 1956 }
1957 }
1958 unset($configs);
a4cdd6d2 1959 upgrade_main_savepoint(true, 2009061703);
17da2e6f 1960 }
1961
a4cdd6d2 1962 if ($oldversion < 2009061704) {
13a0d3d3 1963 // change component string in capability records to new "_" format
17da2e6f 1964 if ($caps = $DB->get_records('capabilities')) {
1965 foreach ($caps as $cap) {
1966 $cap->component = str_replace('/', '_', $cap->component);
1967 $DB->update_record('capabilities', $cap);
1968 }
1969 }
1970 unset($caps);
a4cdd6d2 1971 upgrade_main_savepoint(true, 2009061704);
17da2e6f 1972 }
1973
a4cdd6d2 1974 if ($oldversion < 2009061705) {
13a0d3d3 1975 // change component string in events_handlers records to new "_" format
17da2e6f 1976 if ($handlers = $DB->get_records('events_handlers')) {
1977 foreach ($handlers as $handler) {
1978 $handler->handlermodule = str_replace('/', '_', $handler->handlermodule);
1979 $DB->update_record('events_handlers', $handler);
1980 }
1981 }
1982 unset($handlers);
a4cdd6d2 1983 upgrade_main_savepoint(true, 2009061705);
17da2e6f 1984 }
1985
a4cdd6d2 1986 if ($oldversion < 2009063000) {
adf8f3f9 1987 // upgrade format of _with_advanced settings - quiz only
1988 // note: this can be removed later, not needed for upgrades from 1.9.x
c1f58efe 1989 if ($quiz = get_config('quiz')) {
1990 foreach ($quiz as $name=>$value) {
1991 if (strpos($name, 'fix_') !== 0) {
1992 continue;
1993 }
1994 $newname = substr($name,4).'_adv';
1995 set_config($newname, $value, 'quiz');
1996 unset_config($name, 'quiz');
adf8f3f9 1997 }
13a0d3d3 1998 }
a4cdd6d2 1999 upgrade_main_savepoint(true, 2009063000);
adf8f3f9 2000 }
13a0d3d3 2001
a4cdd6d2 2002 if ($oldversion < 2009071000) {
13a0d3d3 2003
2004 /// Rename field contextid on table block_instances to parentcontextid
2005 $table = new xmldb_table('block_instances');
2006 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'blockname');
2007
2008 /// Launch rename field parentcontextid
2009 $dbman->rename_field($table, $field, 'parentcontextid');
2010
2011 /// Main savepoint reached
a4cdd6d2 2012 upgrade_main_savepoint(true, 2009071000);
13a0d3d3 2013 }
2014
a4cdd6d2 2015 if ($oldversion < 2009071600) {
cae83708 2016
2017 /// Define field summaryformat to be added to post
2018 $table = new xmldb_table('post');
2019 $field = new xmldb_field('summaryformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'format');
2020
2021 /// Conditionally launch add field summaryformat
2022 if (!$dbman->field_exists($table, $field)) {
2023 $dbman->add_field($table, $field);
2024 }
2025
2026 /// Main savepoint reached
a4cdd6d2 2027 upgrade_main_savepoint(true, 2009071600);
cae83708 2028 }
e92c286c 2029
a4cdd6d2 2030 if ($oldversion < 2009072400) {
1bcb7eb5 2031
2032 /// Define table comments to be created
2033 $table = new xmldb_table('comments');
2034
2035 /// Adding fields to table comments
2036 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2037 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2038 $table->add_field('commentarea', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
2039 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2040 $table->add_field('content', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
2041 $table->add_field('format', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2042 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2043 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2044
2045 /// Adding keys to table comments
2046 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2047
2048 /// Conditionally launch create table for comments
2049 if (!$dbman->table_exists($table)) {
2050 $dbman->create_table($table);
2051 }
0a127169 2052
1bcb7eb5 2053 /// Main savepoint reached
a4cdd6d2 2054 upgrade_main_savepoint(true, 2009072400);
1bcb7eb5 2055 }
2056
7d2a0492 2057 /**
2058 * This upgrade is to set up the new navigation blocks that have been developed
2059 * as part of Moodle 2.0
2060 * Now I [Sam Hemelryk] hit a conundrum while exploring how to go about this
2061 * as not only do we want to install the new blocks but we also want to set up
2062 * default instances of them, and at the same time remove instances of the blocks
2063 * that were/will-be outmoded by the two new navigation blocks.
2064 * After talking it through with Tim Hunt {@link http://moodle.org/mod/cvsadmin/view.php?conversationid=3112}
2065 * we decided that the best way to go about this was to put the bulk of the
2066 * upgrade operation into core upgrade `here` but to let the plugins block
2067 * still install the blocks.
2068 * This leaves one hairy end in that we will create block_instances within the
2069 * DB before the blocks themselves are created within the DB
2070 */
a4cdd6d2 2071 if ($oldversion < 2009082800) {
7d2a0492 2072
2073 echo $OUTPUT->notification(get_string('navigationupgrade', 'admin'));
2074
2075 // Get the system context so we can set the block instances to it
2076 $syscontext = get_context_instance(CONTEXT_SYSTEM);
2077
2078 // An array to contain the new block instances we will create
2079 $newblockinstances = array('globalnavigation'=>new stdClass,'settingsnavigation'=>new stdClass);
2080 // The new global navigation block instance as a stdClass
2081 $newblockinstances['globalnavigation']->blockname = 'global_navigation_tree';
2082 $newblockinstances['globalnavigation']->parentcontextid = $syscontext->id; // System context
2e5eba85 2083 $newblockinstances['globalnavigation']->showinsubcontexts = true; // Show absolutely everywhere
7d2a0492 2084 $newblockinstances['globalnavigation']->pagetypepattern = '*'; // Thats right everywhere
2085 $newblockinstances['globalnavigation']->subpagetypepattern = null;
2086 $newblockinstances['globalnavigation']->defaultregion = BLOCK_POS_LEFT;
2087 $newblockinstances['globalnavigation']->defaultweight = -10; // Try make this first
2088 $newblockinstances['globalnavigation']->configdata = '';
2089 // The new settings navigation block instance as a stdClass
2090 $newblockinstances['settingsnavigation']->blockname = 'settings_navigation_tree';
2091 $newblockinstances['settingsnavigation']->parentcontextid = $syscontext->id;
2092 $newblockinstances['settingsnavigation']->showinsubcontexts = true;
2093 $newblockinstances['settingsnavigation']->pagetypepattern = '*';
2094 $newblockinstances['settingsnavigation']->subpagetypepattern = null;
2095 $newblockinstances['settingsnavigation']->defaultregion = BLOCK_POS_LEFT;
2096 $newblockinstances['settingsnavigation']->defaultweight = -9; // Try make this second
2097 $newblockinstances['settingsnavigation']->configdata = '';
2098
2099 // Blocks that are outmoded and for whom the bells will toll... by which I
2100 // mean we will delete all instances of
2101 $outmodedblocks = array('participants','admin_tree','activity_modules','admin','course_list');
2102 $outmodedblocksstring = '\''.join('\',\'',$outmodedblocks).'\'';
2103 unset($outmodedblocks);
2104 // Retrieve the block instance id's and parent contexts, so we can join them an GREATLY
2105 // cut down the number of delete queries we will need to run
2106 $allblockinstances = $DB->get_recordset_select('block_instances', 'blockname IN ('.$outmodedblocksstring.')', array(), '', 'id, parentcontextid');
1918f7e0 2107
7d2a0492 2108 $contextids = array();
2109 $instanceids = array();
2110 // Iterate through all block instances
2111 foreach ($allblockinstances as $blockinstance) {
2112 if (!in_array($blockinstance->parentcontextid, $contextids)) {
2113 $contextids[] = $blockinstance->parentcontextid;
2114
2115 // If we have over 1000 contexts clean them up and reset the array
2116 // this ensures we don't hit any nasty memory limits or such
2117 if (count($contextids) > 1000) {
61676608 2118 upgrade_cleanup_unwanted_block_contexts($contextids);
7d2a0492 2119 $contextids = array();
2120 }
2121 }
2122 if (!in_array($blockinstance->id, $instanceids)) {
2123 $instanceids[] = $blockinstance->id;
2124 // If we have more than 1000 block instances now remove all block positions
2125 // and empty the array
2126 if (count($contextids) > 1000) {
2127 $instanceidstring = join(',',$instanceids);
61676608 2128 $DB->delete_records_select('block_positions', 'blockinstanceid IN ('.$instanceidstring.')');
7d2a0492 2129 $instanceids = array();
2130 }
2131 }
2132 }
2133
61676608 2134 upgrade_cleanup_unwanted_block_contexts($contextids);
7d2a0492 2135
2136 $instanceidstring = join(',',$instanceids);
a4cdd6d2 2137 $DB->delete_records_select('block_positions', 'blockinstanceid IN ('.$instanceidstring.')');
1918f7e0 2138
7d2a0492 2139 unset($allblockinstances);
2140 unset($contextids);
2141 unset($instanceids);
2142 unset($instanceidstring);
1918f7e0 2143
7d2a0492 2144 // Now remove the actual block instance
7874b33d 2145 $DB->delete_records_select('block_instances', 'blockname IN ('.$outmodedblocksstring.')');
7d2a0492 2146 unset($outmodedblocksstring);
2147
2148 // Insert the new block instances. Remember they have not been installed yet
2149 // however this should not be a problem
2150 foreach ($newblockinstances as $blockinstance) {
2151 $blockinstance->id= $DB->insert_record('block_instances', $blockinstance);
2152 // Ensure the block context is created.
2153 get_context_instance(CONTEXT_BLOCK, $blockinstance->id);
2154 }
2155 unset($newblockinstances);
1918f7e0 2156
a4cdd6d2 2157 upgrade_main_savepoint(true, 2009082800);
7d2a0492 2158 // The end of the navigation upgrade
2159 }
2160
a4cdd6d2 2161 if ($oldversion < 2009090800){
b89e4ad8 2162 //insert new record for log_display table
2163 //used to record tag update.
2164 if (!$DB->record_exists('log_display', array('action'=>'update', 'module'=>'tag'))) {
2165 $log_action = new object();
2166 $log_action->module = 'tag';
2167 $log_action->action = 'update';
2168 $log_action->mtable = 'tag';
2169 $log_action->field = 'name';
2170
a4cdd6d2 2171 $DB->insert_record('log_display', $log_action);
b89e4ad8 2172 }
a4cdd6d2 2173 upgrade_main_savepoint(true, 2009090800);
b89e4ad8 2174 }
4313fa89 2175
a4cdd6d2 2176 if ($oldversion < 2009100602) {
4313fa89 2177 /// Define table external_functions to be created
2178 $table = new xmldb_table('external_functions');
2179
2180 /// Adding fields to table external_functions
2181 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
5d820ca2 2182 $table->add_field('name', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
2183 $table->add_field('classname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
2184 $table->add_field('methodname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
2185 $table->add_field('classpath', XMLDB_TYPE_CHAR, '255', null, null, null, null);
4313fa89 2186 $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
4313fa89 2187
2188 /// Adding keys to table external_functions
2189 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2190
5d820ca2 2191 /// Adding indexes to table external_functions
2192 $table->add_index('name', XMLDB_INDEX_UNIQUE, array('name'));
2193
2194 /// Launch create table for external_functions
2195 $dbman->create_table($table);
4313fa89 2196
5d820ca2 2197 /// Main savepoint reached
a4cdd6d2 2198 upgrade_main_savepoint(true, 2009100602);
5d820ca2 2199 }
4313fa89 2200
a4cdd6d2 2201 if ($oldversion < 2009100603) {
f6882162 2202 /// Define table external_services to be created
4313fa89 2203 $table = new xmldb_table('external_services');
2204
2205 /// Adding fields to table external_services
2206 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
5d820ca2 2207 $table->add_field('name', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
2208 $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2209 $table->add_field('requiredcapability', XMLDB_TYPE_CHAR, '150', null, null, null, null);
2210 $table->add_field('restrictedusers', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2211 $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, null, null, null);
f6882162
PS
2212 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2213 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
4313fa89 2214
2215 /// Adding keys to table external_services
2216 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2217
5b9a70a1 2218 /// Adding indexes to table external_services
2219 $table->add_index('name', XMLDB_INDEX_UNIQUE, array('name'));
2220
5d820ca2 2221 /// Launch create table for external_services
2222 $dbman->create_table($table);
4313fa89 2223
5d820ca2 2224 /// Main savepoint reached
a4cdd6d2 2225 upgrade_main_savepoint(true, 2009100603);
5d820ca2 2226 }
4313fa89 2227
a4cdd6d2 2228 if ($oldversion < 2009100604) {
4313fa89 2229 /// Define table external_services_functions to be created
2230 $table = new xmldb_table('external_services_functions');
2231
2232 /// Adding fields to table external_services_functions
2233 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2234 $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
5d820ca2 2235 $table->add_field('functionname', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
4313fa89 2236
2237 /// Adding keys to table external_services_functions
2238 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
5d820ca2 2239 $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id'));
4313fa89 2240
5d820ca2 2241 /// Launch create table for external_services_functions
2242 $dbman->create_table($table);
2243
2244 /// Main savepoint reached
a4cdd6d2 2245 upgrade_main_savepoint(true, 2009100604);
5d820ca2 2246 }
2247
a4cdd6d2 2248 if ($oldversion < 2009100605) {
5d820ca2 2249 /// Define table external_services_users to be created
2250 $table = new xmldb_table('external_services_users');
2251
2252 /// Adding fields to table external_services_users
2253 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2254 $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2255 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
88af54fa 2256 $table->add_field('iprestriction', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2257 $table->add_field('validuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
2258 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
5d820ca2 2259
2260 /// Adding keys to table external_services_users
2261 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2262 $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id'));
2263 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
2264
2265 /// Launch create table for external_services_users
2266 $dbman->create_table($table);
4313fa89 2267
2268 /// Main savepoint reached
a4cdd6d2 2269 upgrade_main_savepoint(true, 2009100605);
4313fa89 2270 }
2271
a4cdd6d2 2272 if ($oldversion < 2009102600) {
1942103f
PS
2273
2274 /// Define table external_tokens to be created
2275 $table = new xmldb_table('external_tokens');
2276
2277 /// Adding fields to table external_tokens
2278 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2279 $table->add_field('token', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null);
2280 $table->add_field('tokentype', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2281 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2282 $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2283 $table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, null, null, null);
2284 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
0b3681a4 2285 $table->add_field('creatorid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
1942103f
PS
2286 $table->add_field('iprestriction', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2287 $table->add_field('validuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
2288 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2289 $table->add_field('lastaccess', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
2290
2291 /// Adding keys to table external_tokens
2292 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2293 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
2294 $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id'));
2295 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
0b3681a4 2296 $table->add_key('creatorid', XMLDB_KEY_FOREIGN, array('creatorid'), 'user', array('id'));
1942103f
PS
2297
2298 /// Launch create table for external_tokens
2299 $dbman->create_table($table);
2300
2301 /// Main savepoint reached
a4cdd6d2 2302 upgrade_main_savepoint(true, 2009102600);
1942103f
PS
2303 }
2304
a4cdd6d2 2305 if ($oldversion < 2009103000) {
cc82aef6
NC
2306
2307 /// Define table blog_association to be created
2308 $table = new xmldb_table('blog_association');
2309
2310 /// Adding fields to table blog_association
2311 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2312 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2313 $table->add_field('blogid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2314
2315 /// Adding keys to table blog_association
2316 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2317 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
2318 $table->add_key('blogid', XMLDB_KEY_FOREIGN, array('blogid'), 'post', array('id'));
2319
2320 /// Conditionally launch create table for blog_association
2321 if (!$dbman->table_exists($table)) {
2322 $dbman->create_table($table);
2323 }
2324
2325/// Define table blog_external to be created
2326 $table = new xmldb_table('blog_external');
2327
2328 /// Adding fields to table blog_external
2329 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2330 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2331 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
2332 $table->add_field('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
2333 $table->add_field('url', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
2334 $table->add_field('filtertags', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2335 $table->add_field('failedlastsync', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2336 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
2337 $table->add_field('timefetched', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2338
2339 /// Adding keys to table blog_external
2340 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2341 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
2342
2343 /// Conditionally launch create table for blog_external
2344 if ($dbman->table_exists($table)) {
2345 // Delete the existing one first (comes from early dev version)
2346 $dbman->drop_table($table);
2347 }
2348 $dbman->create_table($table);
2349
adf176d7 2350 // now inform admins that some settings require attention after upgrade
cc82aef6
NC
2351 if (($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL) && empty($CFG->bloglevel_upgrade_complete)) {
2352 echo $OUTPUT->notification(get_string('bloglevelupgradenotice', 'admin'));
2353
cc82aef6
NC
2354 $site = get_site();
2355
2356 $a = new StdClass;
2357 $a->sitename = $site->fullname;
2358 $a->fixurl = "$CFG->wwwroot/$CFG->admin/bloglevelupgrade.php";
2359
c01678b1
PS
2360 $subject = get_string('bloglevelupgrade', 'admin');
2361 $description = get_string('bloglevelupgradedescription', 'admin', $a);
2362
2363 // can not use messaging here because it is not configured yet!
2364 upgrade_log(UPGRADE_LOG_NOTICE, null, $subject, $description);
cc82aef6
NC
2365 }
2366 /// Main savepoint reached
a4cdd6d2 2367 upgrade_main_savepoint(true, 2009103000);
cc82aef6 2368 }
117bd748 2369
a4cdd6d2 2370 if ($oldversion < 2009110400) {
985acc93
PS
2371 // list of tables where we need to add new format field and convert texts
2372 $extendtables = array('course' => 'summary',
2373 'course_categories' => 'description',
2374 'course_categories' => 'description',
2375 'course_request' => 'summary',
2376 'grade_outcomes' => 'description',
2377 'groups' => 'description',
2378 'groupings' => 'description',
2379 'scale' => 'description',
2380 'user_info_field' => 'description',
2381 'user_info_field' => 'defaultdata',
2382 'user_info_data' => 'data');
2383
2384 foreach ($extendtables as $tablestr=>$fieldstr) {
2385 $formatfieldstr = $fieldstr.'format';
8bdc9cac 2386
8bdc9cac 2387 $table = new xmldb_table($tablestr);
985acc93
PS
2388 $field = new xmldb_field($formatfieldstr, XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', $fieldstr);
2389 // Check that the field doesn't already exists
2390 if (!$dbman->field_exists($table, $field)) {
2391 // Add the new field
2392 $dbman->add_field($table, $field);
2393 }
2394 if ($CFG->texteditors !== 'textarea') {
2395 $rs = $DB->get_recordset($tablestr, array($formatfieldstr=>FORMAT_MOODLE), '', "id,$fieldstr,$formatfieldstr");
2396 foreach ($rs as $rec) {
2397 $rec->$fieldstr = text_to_html($rec->$fieldstr, false, false, true);
2398 $rec->$formatfieldstr = FORMAT_HTML;
2399 $DB->update_record($tablestr, $rec);
2400 upgrade_set_timeout();
8bdc9cac 2401 }
985acc93 2402 $rs->close();
8bdc9cac
SH
2403 }
2404 }
2405
985acc93 2406 unset($rec);
8bdc9cac
SH
2407 unset($extendtables);
2408
a4cdd6d2 2409 upgrade_main_savepoint(true, 2009110400);
8bdc9cac
SH
2410 }
2411
985acc93
PS
2412 if ($oldversion < 2009110401) {
2413 $table = new xmldb_table('user');
2414 $field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'description');
2415 // Check that the field doesn't already exists
2416 if (!$dbman->field_exists($table, $field)) {
2417 // Add the new field
2418 $dbman->add_field($table, $field);
2419 }
2420 if ($CFG->texteditors !== 'textarea') {
2421 $rs = $DB->get_recordset('user', array('descriptionformat'=>FORMAT_MOODLE, 'deleted'=>0, 'htmleditor'=>1), '', "id,description,descriptionformat");
2422 foreach ($rs as $rec) {
2423 $rec->description = text_to_html($rec->description, false, false, true);
2424 $rec->descriptionformat = FORMAT_HTML;
2425 $DB->update_record('user', $rec);
2426 upgrade_set_timeout();
2427 }
2428 $rs->close();
2429 }
2430
2431 upgrade_main_savepoint(true, 2009110401);
2432 }
2433
a4cdd6d2 2434 if ($oldversion < 2009112400) {
57e6ce5e
PS
2435 if (empty($CFG->passwordsaltmain)) {
2436 $subject = get_string('check_passwordsaltmain_name', 'report_security');
2437 $description = get_string('check_passwordsaltmain_warning', 'report_security');;
2438 upgrade_log(UPGRADE_LOG_NOTICE, null, $subject, $description);
2439 }
a4cdd6d2 2440 upgrade_main_savepoint(true, 2009112400);
57e6ce5e 2441 }
e1b9ac3e 2442
a4cdd6d2 2443 if ($oldversion < 2010011200) {
a25bb902
AD
2444 $table = new xmldb_table('grade_categories');
2445 $field = new xmldb_field('hidden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
2446
2447 if (!$dbman->field_exists($table, $field)) {
2448 $dbman->add_field($table, $field);
2449 }
2450
a4cdd6d2 2451 upgrade_main_savepoint(true, 2010011200);
a25bb902
AD
2452 }
2453
a4cdd6d2 2454 if ($oldversion < 2010012500) {
7062a798 2455 upgrade_fix_incorrect_mnethostids();
a4cdd6d2 2456 upgrade_main_savepoint(true, 2010012500);
7062a798 2457 }
de260e0f 2458
a4cdd6d2 2459 if ($oldversion < 2010012600) {
de260e0f
PL
2460 // do stuff to the mnet table
2461 $table = new xmldb_table('mnet_rpc');
2462
2463 $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path');
2464 $dbman->rename_field($table, $field, 'plugintype');
2465
2466 $field = new xmldb_field('parent', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path');
2467 $dbman->rename_field($table, $field, 'pluginname');
2468
2469 $field = new xmldb_field('filename', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'profile');
2470 if (!$dbman->field_exists($table, $field)) {
2471 $dbman->add_field($table, $field);
2472 }
2473
2474 $field = new xmldb_field('classname', XMLDB_TYPE_CHAR, '150', null, null, null, null, 'filename');
2475 if (!$dbman->field_exists($table, $field)) {
2476 $dbman->add_field($table, $field);
2477 }
2478
2479 $field = new xmldb_field('static', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'classname');
2480 if (!$dbman->field_exists($table, $field)) {
2481 $dbman->add_field($table, $field);
2482 }
2483
2484 /// Main savepoint reached
a4cdd6d2 2485 upgrade_main_savepoint(true, 2010012600);
de260e0f
PL
2486 }
2487
a4cdd6d2 2488 if ($oldversion < 2010012900) {
8586dbe2
PL
2489
2490 /// Define table mnet_remote_rpc to be created
2491 $table = new xmldb_table('mnet_remote_rpc');
2492
2493 /// Adding fields to table mnet_remote_rpc
2494 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2495 $table->add_field('functionname', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
2496 $table->add_field('xmlrpcpath', XMLDB_TYPE_CHAR, '80', null, XMLDB_NOTNULL, null, null);
2497
2498 /// Adding keys to table mnet_remote_rpc
2499 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2500
2501 /// Conditionally launch create table for mnet_remote_rpc
2502 if (!$dbman->table_exists($table)) {
2503 $dbman->create_table($table);
2504 }
2505
2506
2507 /// Define table mnet_remote_service2rpc to be created
2508 $table = new xmldb_table('mnet_remote_service2rpc');
2509
2510 /// Adding fields to table mnet_remote_service2rpc
2511 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2512 $table->add_field('serviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2513 $table->add_field('rpcid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2514
2515 /// Adding keys to table mnet_remote_service2rpc
2516 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2517
2518 /// Adding indexes to table mnet_remote_service2rpc
2519 $table->add_index('rpcid_serviceid', XMLDB_INDEX_UNIQUE, array('rpcid', 'serviceid'));
2520
2521 /// Conditionally launch create table for mnet_remote_service2rpc
2522 if (!$dbman->table_exists($table)) {
2523 $dbman->create_table($table);
2524 }
2525
2526
2527 /// Rename field function_name on table mnet_rpc to functionname
2528 $table = new xmldb_table('mnet_rpc');
2529 $field = new xmldb_field('function_name', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'id');
2530
2531 /// Launch rename field function_name
2532 $dbman->rename_field($table, $field, 'functionname');
2533
2534
2535 /// Rename field xmlrpc_path on table mnet_rpc to xmlrpcpath
2536 $table = new xmldb_table('mnet_rpc');
2537 $field = new xmldb_field('xmlrpc_path', XMLDB_TYPE_CHAR, '80', null, XMLDB_NOTNULL, null, null, 'function_name');
2538
2539 /// Launch rename field xmlrpc_path
2540 $dbman->rename_field($table, $field, 'xmlrpcpath');
2541
2542
2543 /// Main savepoint reached
a4cdd6d2 2544 upgrade_main_savepoint(true, 2010012900);
8586dbe2 2545 }
a6e9dafe 2546
a4cdd6d2 2547 if ($oldversion < 2010012901) {
a6e9dafe
PL
2548
2549 /// Define field plugintype to be added to mnet_remote_rpc
2550 $table = new xmldb_table('mnet_remote_rpc');
2551 $field = new xmldb_field('plugintype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpcpath');
2552
2553 /// Conditionally launch add field plugintype
2554 if (!$dbman->field_exists($table, $field)) {
2555 $dbman->add_field($table, $field);
2556 }
2557
a6e9dafe
PL
2558 /// Define field pluginname to be added to mnet_remote_rpc
2559 $field = new xmldb_field('pluginname', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'plugintype');
2560
2561 /// Conditionally launch add field pluginname
2562 if (!$dbman->field_exists($table, $field)) {
2563 $dbman->add_field($table, $field);
2564 }
5b7984a5
PL
2565
2566 /// Main savepoint reached
a4cdd6d2 2567 upgrade_main_savepoint(true, 2010012901);
5b7984a5
PL
2568 }
2569
a4cdd6d2 2570 if ($oldversion < 2010012902) {
5b7984a5
PL
2571
2572 /// Define field enabled to be added to mnet_remote_rpc
2573 $table = new xmldb_table('mnet_remote_rpc');
2574 $field = new xmldb_field('enabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, 'pluginname');
2575
2576 /// Conditionally launch add field enabled
2577 if (!$dbman->field_exists($table, $field)) {
2578 $dbman->add_field($table, $field);
2579 }
2580
2581 /// Main savepoint reached
a4cdd6d2 2582 upgrade_main_savepoint(true, 2010012902);
a6e9dafe
PL
2583 }
2584
f6852f02 2585 /// MDL-17863. Increase the portno column length on mnet_host to handle any port number
a4cdd6d2 2586 if ($oldversion < 2010020100) {
f6852f02
PL
2587 /// Changing precision of field portno on table mnet_host to (5)
2588 $table = new xmldb_table('mnet_host');
2589 $field = new xmldb_field('portno', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'transport');
2590
2591 /// Launch change of precision for field portno
2592 $dbman->change_field_precision($table, $field);
2593
a4cdd6d2 2594 upgrade_main_savepoint(true, 2010020100);
f6852f02
PL
2595 }
2596
a4cdd6d2 2597 if ($oldversion < 2010020300) {
d3d393ab
RW
2598
2599 /// Define field timecreated to be added to user
2600 $table = new xmldb_table('user');
2601 $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'trackforums');
2602
2603 if (!$dbman->field_exists($table, $field)) {
2604 /// Launch add field timecreated
2605 $dbman->add_field($table, $field);
2606
2607 $DB->execute("UPDATE {user} SET timecreated = firstaccess");
2608
2609 $sql = "UPDATE {user} SET timecreated = " . time() ." where timecreated = 0";
2610 $DB->execute($sql);
2611 }
a4cdd6d2 2612 upgrade_main_savepoint(true, 2010020300);
d3d393ab 2613 }
073d3804
EL
2614
2615 // MDL-21407. Trim leading spaces from default tex latexpreamble causing problems under some confs
a4cdd6d2 2616 if ($oldversion < 2010020301) {
073d3804
EL
2617 if ($preamble = $CFG->filter_tex_latexpreamble) {
2618 $preamble = preg_replace('/^ +/m', '', $preamble);
2619 set_config('filter_tex_latexpreamble', $preamble);
2620 }
a4cdd6d2 2621 upgrade_main_savepoint(true, 2010020301);
073d3804
EL
2622 }
2623
a4cdd6d2 2624 if ($oldversion < 2010021400) {
9a9012dc
PS
2625 /// Changes to modinfo mean we need to rebuild course cache
2626 require_once($CFG->dirroot . '/course/lib.php');
2627 rebuild_course_cache(0, true);
a4cdd6d2 2628 upgrade_main_savepoint(true, 2010021400);
9a9012dc
PS
2629 }
2630
a4cdd6d2 2631 if ($oldversion < 2010021800) {
c9606565 2632 $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle'));
a4cdd6d2 2633 upgrade_main_savepoint(true, 2010021800);
c9606565
PL
2634 }
2635
a4cdd6d2 2636 if ($oldversion < 2010031900) {
cd1bca89
PS
2637 // regeneration of sessions is always enabled, no need for this setting any more
2638 unset_config('regenloginsession');
a4cdd6d2 2639 upgrade_main_savepoint(true, 2010031900);
cd1bca89 2640 }
90723839 2641
a4cdd6d2 2642 if ($oldversion < 2010033101.02) {
98da6021 2643
1dce6261
DC
2644 /// Define table license to be created
2645 $table = new xmldb_table('license');
2646
2647 /// Adding fields to table license
2648 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2649 $table->add_field('shortname', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2650 $table->add_field('fullname', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
2651 $table->add_field('source', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2652 $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
2653 $table->add_field('version', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
2654
2655 /// Adding keys to table license
2656 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2657
2658 /// Conditionally launch create table for license
2659 if (!$dbman->table_exists($table)) {
2660 $dbman->create_table($table);
2661 }
d1d4813f
DC
2662 $active_licenses = array();
2663
2664 $license = new stdclass;
2665
2666 // add unknown license
2667 $license->shortname = 'unknown';
2668 $license->fullname = 'Unknown license';
2669 $license->source = '';
2670 $license->enabled = 1;
2671 $license->version = '2010033100';
2672 $active_licenses[] = $license->shortname;
2673 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2674 if ($record->version < $license->version) {
2675 // update license record
2676 $license->enabled = $record->enabled;
2677 $license->id = $record->id;
2678 $DB->update_record('license', $license);
2679 }
2680 } else {
2681 $DB->insert_record('license', $license);
2682 }
2683
2684 // add all rights reserved license
2685 $license->shortname = 'allrightsreserved';
2686 $license->fullname = 'All rights reserved';
2687 $license->source = 'http://en.wikipedia.org/wiki/All_rights_reserved';
2688 $license->enabled = 1;
2689 $license->version = '2010033100';
2690 $active_licenses[] = $license->shortname;
2691 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2692 if ($record->version < $license->version) {
2693 // update license record
2694 $license->id = $record->id;
2695 $license->enabled = $record->enabled;
2696 $DB->update_record('license', $license);
2697 }
2698 } else {
2699 $DB->insert_record('license', $license);
2700 }
2701
2702 // add public domain license
2703 $license->shortname = 'public';
2704 $license->fullname = 'Public Domain';
2705 $license->source = 'http://creativecommons.org/licenses/publicdomain/';
2706 $license->enabled = 1;
2707 $license->version = '2010033100';
2708 $active_licenses[] = $license->shortname;
2709 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2710 if ($record->version < $license->version) {
2711 // update license record
2712 $license->enabled = $record->enabled;
2713 $license->id = $record->id;
2714 $DB->update_record('license', $license);
2715 }
2716 } else {
2717 $DB->insert_record('license', $license);
2718 }
2719
2720 // add creative commons license
2721 $license->shortname = 'cc';
2722 $license->fullname = 'Creative Commons';
2723 $license->source = 'http://creativecommons.org/licenses/by/3.0/';
2724 $license->enabled = 1;
2725 $license->version = '2010033100';
2726 $active_licenses[] = $license->shortname;
2727 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2728 if ($record->version < $license->version) {
2729 // update license record
2730 $license->enabled = $record->enabled;
2731 $license->id = $record->id;
2732 $DB->update_record('license', $license);
2733 }
2734 } else {
2735 $DB->insert_record('license', $license);
2736 }
2737
2738 // add creative commons no derivs license
2739 $license->shortname = 'cc-nd';
2740 $license->fullname = 'Creative Commons - NoDerivs';
2741 $license->source = 'http://creativecommons.org/licenses/by-nd/3.0/';
2742 $license->enabled = 1;
2743 $license->version = '2010033100';
2744 $active_licenses[] = $license->shortname;
2745 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2746 if ($record->version < $license->version) {
2747 // update license record
2748 $license->enabled = $record->enabled;
2749 $license->id = $record->id;
2750 $DB->update_record('license', $license);
2751 }
2752 } else {
2753 $DB->insert_record('license', $license);
2754 }
2755
2756 // add creative commons no commercial no derivs license
2757 $license->shortname = 'cc-nc-nd';
2758 $license->fullname = 'Creative Commons - No Commercial NoDerivs';
2759 $license->source = 'http://creativecommons.org/licenses/by-nc-nd/3.0/';
2760 $license->enabled = 1;
2761 $license->version = '2010033100';
2762 $active_licenses[] = $license->shortname;
2763 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2764 if ($record->version < $license->version) {
2765 // update license record
2766 $license->enabled = $record->enabled;
2767 $license->id = $record->id;
2768 $DB->update_record('license', $license);
2769 }
2770 } else {
2771 $DB->insert_record('license', $license);
2772 }
2773
2774 // add creative commons no commercial
2775 $license->shortname = 'cc-nc-nd';
2776 $license->shortname = 'cc-nc';
2777 $license->fullname = 'Creative Commons - No Commercial';
2778 $license->source = 'http://creativecommons.org/licenses/by-nd/3.0/';
2779 $license->enabled = 1;
2780 $license->version = '2010033100';
2781 $active_licenses[] = $license->shortname;
2782 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2783 if ($record->version < $license->version) {
2784 // update license record
2785 $license->enabled = $record->enabled;
2786 $license->id = $record->id;
2787 $DB->update_record('license', $license);
2788 }
2789 } else {
2790 $DB->insert_record('license', $license);
2791 }
2792
2793 // add creative commons no commercial sharealike
2794 $license->shortname = 'cc-nc-sa';
2795 $license->fullname = 'Creative Commons - No Commercial ShareAlike';
2796 $license->source = 'http://creativecommons.org/licenses/by-nc-sa/3.0/';
2797 $license->enabled = 1;
2798 $license->version = '2010033100';
2799 $active_licenses[] = $license->shortname;
2800 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2801 if ($record->version < $license->version) {
2802 // update license record
2803 $license->enabled = $record->enabled;
2804 $license->id = $record->id;
2805 $DB->update_record('license', $license);
2806 }
2807 } else {
2808 $DB->insert_record('license', $license);
2809 }
2810
2811 // add creative commons sharealike
2812 $license->shortname = 'cc-sa';
2813 $license->fullname = 'Creative Commons - ShareAlike';
2814 $license->source = 'http://creativecommons.org/licenses/by-sa/3.0/';
2815 $license->enabled = 1;
2816 $license->version = '2010033100';
2817 $active_licenses[] = $license->shortname;
2818 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2819 if ($record->version < $license->version) {
2820 // update license record
2821 $license->enabled = $record->enabled;
2822 $license->id = $record->id;
2823 $DB->update_record('license', $license);
2824 }
2825 } else {
2826 $DB->insert_record('license', $license);
2827 }
2828
2829 set_config('licenses', implode(',', $active_licenses));
1dce6261
DC
2830 /// set site default license
2831 set_config('sitedefaultlicense', 'allrightsreserved');
2832
2833 /// Main savepoint reached
a4cdd6d2 2834 upgrade_main_savepoint(true, 2010033101.02);
1dce6261 2835 }
4f0c2d00 2836
a4cdd6d2 2837 if ($oldversion < 2010033102.00) {
4f0c2d00
PS
2838 // rename course view capability to participate
2839 $params = array('view'=>'moodle/course:view', 'participate'=>'moodle/course:participate');
2840 $sql = "UPDATE {role_capabilities} SET capability = :participate WHERE capability = :view";
2841 $DB->execute($sql, $params);
2842 $sql = "UPDATE {capabilities} SET name = :participate WHERE name = :view";
2843 $DB->execute($sql, $params);
2844 // note: the view capability is readded again at the end of upgrade, but with different meaning
a4cdd6d2 2845 upgrade_main_savepoint(true, 2010033102.00);
4f0c2d00
PS
2846 }
2847
a4cdd6d2 2848 if ($oldversion < 2010033102.01) {
4f0c2d00
PS
2849 // Define field archetype to be added to role table
2850 $table = new xmldb_table('role');
2851 $field = new xmldb_field('archetype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, 'sortorder');
2852 $dbman->add_field($table, $field);
a4cdd6d2 2853 upgrade_main_savepoint(true, 2010033102.01);
4f0c2d00
PS
2854 }
2855
a4cdd6d2 2856 if ($oldversion < 2010033102.02) {
4f0c2d00
PS
2857 // Set archetype for existing roles and change admin role to manager role
2858 $sql = "SELECT r.*, rc.capability
2859 FROM {role} r
2860 JOIN {role_capabilities} rc ON rc.roleid = r.id
2861 WHERE rc.contextid = :syscontextid AND rc.capability LIKE :legacycaps
2862 ORDER BY r.id";
2863 $params = array('syscontextid'=>SYSCONTEXTID, 'legacycaps'=>'moodle/legacy:%');
2864 $substart = strlen('moodle/legacy:');
2865 $roles = $DB->get_recordset_sql($sql, $params); // in theory could be multiple legacy flags in one role
2866 foreach ($roles as $role) {
2867 $role->archetype = substr($role->capability, $substart);
2868 unset($role->capability);
2869 if ($role->archetype === 'admin') {
2870 $role->archetype = 'manager';
2871 if ($role->shortname === 'admin') {
2872 $role->shortname = 'manager';
2873 $role->name = get_string('manager', 'role');
2874 $role->description = get_string('managerdescription', 'role');
2875 }
2876 }
2877 $DB->update_record('role', $role);
2878 }
2879 $roles->close();
2880
a4cdd6d2 2881 upgrade_main_savepoint(true, 2010033102.02);
4f0c2d00
PS
2882 }
2883
a4cdd6d2 2884 if ($oldversion < 2010033102.03) {
4f0c2d00
PS
2885 // Now pick site admins (===have manager role assigned at the system context)
2886 // and store them in the new $CFG->siteadmins setting as comma separated list
2887 $sql = "SELECT ra.id, ra.userid
2888 FROM {role_assignments} ra
2889 JOIN {role} r ON r.id = ra.roleid
2890 JOIN {user} u ON u.id = ra.userid
2891 WHERE ra.contextid = :syscontext AND r.archetype = 'manager' AND u.deleted = 0
2892 ORDER BY ra.id";
2893 $ras = $DB->get_records_sql($sql, array('syscontext'=>SYSCONTEXTID));
2894 $admins = array();
2895 foreach ($ras as $ra) {
2896 $admins[$ra->userid] = $ra->userid;
2897 set_config('siteadmins', implode(',', $admins)); // better to save it repeatedly, we do need at least one admin
2898 $DB->delete_records('role_assignments', array('id'=>$ra->id));
2899 }
2900
a4cdd6d2 2901 upgrade_main_savepoint(true, 2010033102.03);
4f0c2d00
PS
2902 }
2903
a4cdd6d2 2904 if ($oldversion < 2010033102.04) {
4f0c2d00
PS
2905 // clean up the manager roles
2906 $managers = $DB->get_records('role', array('archetype'=>'manager'));
2907 foreach ($managers as $manager) {
2908 // now sanitize the capabilities and overrides
2909 $DB->delete_records('role_capabilities', array('capability'=>'moodle/site:config', 'roleid'=>$manager->id)); // only site admins may configure servers
2910 // note: doanything and legacy caps are deleted automatically, they get moodle/course:view later at the end of the upgrade
2911
4f0c2d00
PS
2912 // remove manager role assignments bellow the course context level - admin role was never intended for activities and blocks,
2913 // the problem is that those assignments would not be visible after upgrade and old style admins in activities make no sense anyway
2914 $DB->delete_records_select('role_assignments', "roleid = :manager AND contextid IN (SELECT id FROM {context} WHERE contextlevel > 50)", array('manager'=>$manager->id));
2915
2916 // allow them to assign all roles except default user, guest and frontpage - users get these roles automatically on the fly when needed
2917 $DB->delete_records('role_allow_assign', array('roleid'=>$manager->id));
2918 $roles = $DB->get_records_sql("SELECT * FROM {role} WHERE archetype <> 'user' AND archetype <> 'guest' AND archetype <> 'frontpage'");
2919 foreach ($roles as $role) {
2920 $record = (object)array('roleid'=>$manager->id, 'allowassign'=>$role->id);
2921 $DB->insert_record('role_allow_assign', $record);
2922 }
2923
2924 // allow them to override all roles
2925 $DB->delete_records('role_allow_override', array('roleid'=>$manager->id));
2926 $roles = $DB->get_records_sql("SELECT * FROM {role}");
2927 foreach ($roles as $role) {
2928 $record = (object)array('roleid'=>$manager->id, 'allowoverride'=>$role->id);
2929 $DB->insert_record('role_allow_override', $record);
2930 }
2931
2932 // allow them to switch to all following roles
2933 $DB->delete_records('role_allow_switch', array('roleid'=>$manager->id));
2934 $roles = $DB->get_records_sql("SELECT * FROM {role} WHERE archetype IN ('student', 'teacher', 'editingteacher')");
2935 foreach ($roles as $role) {
2936 $record = (object)array('roleid'=>$manager->id, 'allowswitch'=>$role->id);
2937 $DB->insert_record('role_allow_switch', $record);
2938 }
2939 }
2940
a4cdd6d2 2941 upgrade_main_savepoint(true, 2010033102.04);
4f0c2d00
PS
2942 }
2943
a4cdd6d2 2944 if ($oldversion < 2010033102.05) {
4f0c2d00
PS
2945 // remove course:view from all roles that are not used for enrolment, it does NOT belong there because it really means user is enrolled!
2946 $noenrolroles = $DB->get_records_select('role', "archetype IN ('guest', 'user', 'manager', 'coursecreator', 'frontpage')");
2947 foreach ($noenrolroles as $role) {
2948 $DB->delete_records('role_capabilities', array('roleid'=>$role->id, 'capability'=>'moodle/course:participate'));
2949 }
a4cdd6d2 2950 upgrade_main_savepoint(true, 2010033102.05);
4f0c2d00
PS
2951 }
2952
a4cdd6d2 2953 if ($oldversion < 2010033102.06) {
4f0c2d00
PS
2954 // make sure there is nothing weird in default user role
2955 if (!empty($CFG->defaultuserroleid)) {
2956 if ($role = $DB->get_record('role', array('id'=>$CFG->defaultuserroleid))) {
2957 if ($role->archetype !== '' and $role->archetype !== 'user') {
2958 upgrade_log(UPGRADE_LOG_NOTICE, null, 'Default authenticated user role (defaultuserroleid) value is invalid, setting cleared.');
2959 unset_config('defaultuserroleid');
2960 }
2961 } else {
2962 unset_config('defaultuserroleid');
2963 }
2964 }
a4cdd6d2 2965 upgrade_main_savepoint(true, 2010033102.06);
4f0c2d00
PS
2966 }
2967
a4cdd6d2 2968 if ($oldversion < 2010033102.07) {
4f0c2d00
PS
2969 if (!empty($CFG->displayloginfailures) and $CFG->displayloginfailures === 'teacher') {
2970 upgrade_log(UPGRADE_LOG_NOTICE, null, 'Displaying of login failuters to teachers is not supported any more.');
2971 unset_config('displayloginfailures');
2972 }
a4cdd6d2 2973 upgrade_main_savepoint(true, 2010033102.07);
4f0c2d00
PS
2974 }
2975
a4cdd6d2 2976 if ($oldversion < 2010033102.08) {
4f0c2d00
PS
2977 // make sure there are no problems in default guest role settings
2978 if (!empty($CFG->guestroleid)) {
2979 if ($role = $DB->get_record('role', array('id'=>$CFG->guestroleid))) {
2980 if ($role->archetype !== '' and $role->archetype !== 'guest') {
2981 upgrade_log(UPGRADE_LOG_NOTICE, null, 'Default guest role (guestroleid) value is invalid, setting cleared.');
2982 unset_config('guestroleid');
2983 }
2984 } else {
df997f84 2985 upgrade_log(UPGRADE_LOG_NOTICE, null, 'Role specified in Default guest role (guestroleid) does not exist, setting cleared.');
4f0c2d00
PS
2986 unset_config('guestroleid');
2987 }
2988 }
2989 // remove all roles of the guest account - the only way to change it is to override the guest role, sorry
df997f84 2990 // the guest account gets all the role assignments on the fly which works fine in has_capability(),
4f0c2d00
PS
2991 $DB->delete_records_select('role_assignments', "userid IN (SELECT id FROM {user} WHERE username = 'guest')");
2992
a4cdd6d2 2993 upgrade_main_savepoint(true, 2010033102.08);
4f0c2d00
PS
2994 }
2995
df997f84 2996 /// New table for storing which roles can be assigned in which contexts.
a4cdd6d2 2997 if ($oldversion < 2010033102.09) {
4f0c2d00 2998
df997f84
PS
2999 /// Define table role_context_levels to be created
3000 $table = new xmldb_table('role_context_levels');
3001
3002 /// Adding fields to table role_context_levels
3003 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3004 $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3005 $table->add_field('contextlevel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3006
3007 /// Adding keys to table role_context_levels
3008 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3009 $table->add_key('contextlevel-roleid', XMLDB_KEY_UNIQUE, array('contextlevel', 'roleid'));
3010 $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
3011
3012 /// Conditionally launch create table for role_context_levels
3013 if (!$dbman->table_exists($table)) {
3014 $dbman->create_table($table);
3015 }
3016
3017 /// Main savepoint reached
a4cdd6d2 3018 upgrade_main_savepoint(true, 2010033102.09);
df997f84
PS
3019 }
3020
a4cdd6d2 3021 if ($oldversion < 2010033102.10) {
df997f84
PS
3022 // Now populate the role_context_levels table with the default values
3023 // NOTE: do not use accesslib methods here
3024
3025 $rolecontextlevels = array();
3026 $defaults = array('manager' => array(CONTEXT_SYSTEM, CONTEXT_COURSECAT, CONTEXT_COURSE),
3027 'coursecreator' => array(CONTEXT_SYSTEM, CONTEXT_COURSECAT),
3028 'editingteacher' => array(CONTEXT_COURSE, CONTEXT_MODULE),
3029 'teacher' => array(CONTEXT_COURSE, CONTEXT_MODULE),
3030 'student' => array(CONTEXT_COURSE, CONTEXT_MODULE),
3031 'guest' => array(),
3032 'user' => array(),
3033 'frontpage' => array());
3034
3035 $roles = $DB->get_records('role', array(), '', 'id, archetype');
4f0c2d00 3036 foreach ($roles as $role) {
df997f84
PS
3037 if (isset($defaults[$role->archetype])) {
3038 $rolecontextlevels[$role->id] = $defaults[$role->archetype];
3039 }
3040 }
3041
3042 // add roles without archetypes, it may contain weird things, but we can not fix them
3043 $sql = "SELECT DISTINCT ra.roleid, con.contextlevel
3044 FROM {role_assignments} ra
3045 JOIN {context} con ON ra.contextid = con.id";
3046 $existingrolecontextlevels = $DB->get_recordset_sql($sql);
3047 foreach ($existingrolecontextlevels as $rcl) {
3048 if (isset($roleids[$rcl->roleid])) {
3049 continue;
3050 }
3051 if (!isset($rolecontextlevels[$rcl->roleid])) {
3052 $rolecontextlevels[$rcl->roleid] = array($rcl->contextlevel);
3053 } else if (!in_array($rcl->contextlevel, $rolecontextlevels[$rcl->roleid])) {
3054 $rolecontextlevels[$rcl->roleid][] = $rcl->contextlevel;
3055 }
3056 }
3057 $existingrolecontextlevels->close();
3058
3059 // Put the data into the database.
3060 $rcl = new object();
3061 foreach ($rolecontextlevels as $roleid => $contextlevels) {
3062 $rcl->roleid = $roleid;
3063 foreach ($contextlevels as $level) {
3064 $rcl->contextlevel = $level;
3065 $DB->insert_record('role_context_levels', $rcl, false);
3066 }
4f0c2d00
PS
3067 }
3068
df997f84
PS
3069 // release memory!!
3070 unset($roles);
3071 unset($defaults);
3072 unset($rcl);
3073 unset($existingrolecontextlevels);
3074 unset($rolecontextlevels);
4f0c2d00
PS
3075
3076 // Main savepoint reached
a4cdd6d2 3077 upgrade_main_savepoint(true, 2010033102.10);
4f0c2d00
PS
3078 }
3079
a4cdd6d2 3080 if ($oldversion < 2010040700) {
98da6021
PS
3081 // migrate old groupings --> groupmembersonly setting
3082 if (isset($CFG->enablegroupings)) {
3083 set_config('enablegroupmembersonly', $CFG->enablegroupings);
3084 unset_config('enablegroupings');
3085 }
3086
3087 // Main savepoint reached
a4cdd6d2 3088 upgrade_main_savepoint(true, 2010040700);
98da6021
PS
3089 }
3090
a4cdd6d2 3091 if ($oldversion < 2010040900) {
3a915b06
PS
3092
3093 // Changing the default of field lang on table user to good old "en"
3094 $table = new xmldb_table('user');
3095 $field = new xmldb_field('lang', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, 'en', 'country');
3096
3097 // Launch change of default for field lang
3098 $dbman->change_field_default($table, $field);
3099
3100 // update main site lang
3101 if (strpos($CFG->lang, '_utf8') !== false) {
3102 $lang = str_replace('_utf8', '', $CFG->lang);
3103 set_config('lang', $lang);
3104 }
3105
2357ab49
PS
3106 // tweak langlist
3107 if (!empty($CFG->langlist)) {
3108 $langs = explode(',', $CFG->langlist);
3109 foreach ($langs as $key=>$lang) {
3110 $lang = str_replace('_utf8', '', $lang);
3111 $langs[$key] = $lang;
3112 }
3113 set_config('langlist', implode(',', $langs));
3114 }
3115
3a915b06 3116 // Main savepoint reached
a4cdd6d2 3117 upgrade_main_savepoint(true, 2010040900);
3a915b06
PS
3118 }
3119
a4cdd6d2 3120 if ($oldversion < 2010040901) {
3a915b06
PS
3121
3122 // Remove "_utf8" suffix from all langs in user table
3123 $langs = $DB->get_records_sql("SELECT DISTINCT lang FROM {user} WHERE lang LIKE ?", array('%_utf8'));
3124
3125 foreach ($langs as $lang=>$unused) {
3126 $newlang = str_replace('_utf8', '', $lang);
3127 $sql = "UPDATE {user} SET lang = :newlang WHERE lang = :lang";
3128 $DB->execute($sql, array('newlang'=>$newlang, 'lang'=>$lang));
3129 }
3130
3131 // Main savepoint reached
a4cdd6d2 3132 upgrade_main_savepoint(true, 2010040901);
3a915b06
PS
3133 }
3134
a4cdd6d2 3135 if ($oldversion < 2010041301) {
3406acde
SH
3136 $sql = "UPDATE {block} SET name=? WHERE name=?";
3137 $DB->execute($sql, array('navigation', 'global_navigation_tree'));
3138 $DB->execute($sql, array('settings', 'settings_navigation_tree'));
3139
3140 $sql = "UPDATE {block_instances} SET blockname=? WHERE blockname=?";
3141 $DB->execute($sql, array('navigation', 'global_navigation_tree'));
3142 $DB->execute($sql, array('settings', 'settings_navigation_tree'));
a4cdd6d2 3143 upgrade_main_savepoint(true, 2010041301);
3406acde
SH
3144 }
3145
a4cdd6d2 3146 if ($oldversion < 2010042100) {
ee4d3dee
EL
3147
3148 /// Define table backup_controllers to be created
3149 $table = new xmldb_table('backup_controllers');
3150
3151 /// Adding fields to table backup_controllers
3152 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3153 $table->add_field('backupid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
3154 $table->add_field('type', XMLDB_TYPE_CHAR, '6', null, XMLDB_NOTNULL, null, null);
3155 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3156 $table->add_field('format', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null);
3157 $table->add_field('interactive', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3158 $table->add_field('purpose', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3159 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3160 $table->add_field('status', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3161 $table->add_field('execution', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3162 $table->add_field('executiontime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3163 $table->add_field('checksum', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
3164 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3165 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3166 $table->add_field('controller', XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null);
3167
3168 /// Adding keys to table backup_controllers
3169 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3170 $table->add_key('backupid_uk', XMLDB_KEY_UNIQUE, array('backupid'));
3171 $table->add_key('userid_fk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
3172
3173 /// Adding indexes to table backup_controllers
3174 $table->add_index('typeitem_ix', XMLDB_INDEX_NOTUNIQUE, array('type', 'itemid'));
3175
3176 /// Conditionally launch create table for backup_controllers
3177 if (!$dbman->table_exists($table)) {
3178 $dbman->create_table($table);
3179 }
3180
3181 /// Define table backup_ids_template to be created
3182 $table = new xmldb_table('backup_ids_template');
3183
3184 /// Adding fields to table backup_ids_template
3185 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3186 $table->add_field('backupid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
3187 $table->add_field('itemname', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
3188 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3189 $table->add_field('parentitemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
3190
3191 /// Adding keys to table backup_ids_template
3192 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3193 $table->add_key('backupid_itemname_itemid_uk', XMLDB_KEY_UNIQUE, array('backupid', 'itemname', 'itemid'));
3194
3195 /// Adding indexes to table backup_ids_template
3196 $table->add_index('backupid_parentitemid_ix', XMLDB_INDEX_NOTUNIQUE, array('backupid', 'itemname', 'parentitemid'));
3197
3198 /// Conditionally launch create table for backup_controllers
3199 if (!$dbman->table_exists($table)) {
3200 $dbman->create_table($table);
3201 }
3202
3203 /// Main savepoint reached
a4cdd6d2 3204 upgrade_main_savepoint(true, 2010042100);
ee4d3dee
EL
3205 }
3206
a4cdd6d2 3207 if ($oldversion < 2010042301) {
0f4ab67d
SH
3208
3209 $table = new xmldb_table('course_sections');
3210 $field = new xmldb_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'section');
3211
3212 if (!$dbman->field_exists($table, $field)) {
3213 $dbman->add_field($table, $field);
3214 }
3215
a4cdd6d2 3216 upgrade_main_savepoint(true, 2010042301);
0f4ab67d
SH
3217 }
3218
a4cdd6d2 3219 if ($oldversion < 2010042302) {
74180df2
PS
3220 // Define table cohort to be created
3221 $table = new xmldb_table('cohort');
3222
3223 // Adding fields to table cohort
3224 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3225 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3226 $table->add_field('name', XMLDB_TYPE_CHAR, '254', null, XMLDB_NOTNULL, null, null);
3227 $table->add_field('idnumber', XMLDB_TYPE_CHAR, '100', null, null, null, null);
3228 $table->add_field('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
3229 $table->add_field('descriptionformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
df997f84 3230 $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
74180df2
PS
3231 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3232 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3233
3234 // Adding keys to table cohort
3235 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3236 $table->add_key('context', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
3237
3238 // Conditionally launch create table for cohort
3239 if (!$dbman->table_exists($table)) {
3240 $dbman->create_table($table);
3241 }
3242
a4cdd6d2 3243 upgrade_main_savepoint(true, 2010042302);
74180df2
PS
3244 }
3245
a4cdd6d2 3246 if ($oldversion < 2010042303) {
74180df2
PS
3247 // Define table cohort_members to be created
3248 $table = new xmldb_table('cohort_members');
3249
3250 // Adding fields to table cohort_members
3251 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3252 $table->add_field('cohortid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3253 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3254 $table->add_field('timeadded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3255
3256 // Adding keys to table cohort_members
3257 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3258 $table->add_key('cohortid', XMLDB_KEY_FOREIGN, array('cohortid'), 'cohort', array('id'));
3259 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
3260
3261 // Adding indexes to table cohort_members
3262 $table->add_index('cohortid-userid', XMLDB_INDEX_UNIQUE, array('cohortid', 'userid'));
3263
3264 // Conditionally launch create table for cohort_members
3265 if (!$dbman->table_exists($table)) {
3266 $dbman->create_table($table);
3267 }
3268
3269 // Main savepoint reached