MDL-13766, fixed repository instance name and configplugin language string
[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 < 2009040300) {
0fc9c009 1287
1288 /// Define table filter_active to be created
1289 $table = new xmldb_table('filter_active');
1290
1291 /// Adding fields to table filter_active
2a88f626 1292 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1293 $table->add_field('filter', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
1294 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1295 $table->add_field('active', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null);
1296 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
0fc9c009 1297
1298 /// Adding keys to table filter_active
1299 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1300 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
1301
1302 /// Adding indexes to table filter_active
1303 $table->add_index('contextid-filter', XMLDB_INDEX_UNIQUE, array('contextid', 'filter'));
1304
1305 /// Conditionally launch create table for filter_active
1306 if (!$dbman->table_exists($table)) {
1307 $dbman->create_table($table);
1308 }
1309
1310 /// Main savepoint reached
a4cdd6d2 1311 upgrade_main_savepoint(true, 2009040300);
0fc9c009 1312 }
1313
a4cdd6d2 1314 if ($oldversion < 2009040301) {
0fc9c009 1315
1316 /// Define table filter_config to be created
1317 $table = new xmldb_table('filter_config');
1318
1319 /// Adding fields to table filter_config
2a88f626 1320 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1321 $table->add_field('filter', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
1322 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1323 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
1324 $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
0fc9c009 1325
1326 /// Adding keys to table filter_config
1327 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1328 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
1329
1330 /// Adding indexes to table filter_config
1331 $table->add_index('contextid-filter-name', XMLDB_INDEX_UNIQUE, array('contextid', 'filter', 'name'));
1332
1333 /// Conditionally launch create table for filter_config
1334 if (!$dbman->table_exists($table)) {
1335 $dbman->create_table($table);
1336 }
1337
1338 /// Main savepoint reached
a4cdd6d2 1339 upgrade_main_savepoint(true, 2009040301);
0fc9c009 1340 }
1341
a4cdd6d2 1342 if ($oldversion < 2009040302) {
c07e6d8d 1343 /// Transfer current settings from $CFG->textfilters
1344 $disabledfilters = filter_get_all_installed();
1345 if (empty($CFG->textfilters)) {
1346 $activefilters = array();
1347 } else {
1348 $activefilters = explode(',', $CFG->textfilters);
1349 }
1350 $syscontext = get_context_instance(CONTEXT_SYSTEM);
1351 $sortorder = 1;
1352 foreach ($activefilters as $filter) {
1353 filter_set_global_state($filter, TEXTFILTER_ON, $sortorder);
1354 $sortorder += 1;
1355 unset($disabledfilters[$filter]);
1356 }
1357 foreach ($disabledfilters as $filter => $notused) {
1358 filter_set_global_state($filter, TEXTFILTER_DISABLED, $sortorder);
1359 $sortorder += 1;
1360 }
1361
1362 /// Main savepoint reached
a4cdd6d2 1363 upgrade_main_savepoint(true, 2009040302);
c07e6d8d 1364 }
1365
a4cdd6d2 1366 if ($oldversion < 2009040600) {
bbb45905 1367 /// Ensure that $CFG->stringfilters is set.
1368 if (empty($CFG->stringfilters)) {
1369 if (!empty($CFG->filterall)) {
1370 set_config('stringfilters', $CFG->textfilters);
1371 } else {
1372 set_config('stringfilters', '');
1373 }
1374 }
1375
1376 set_config('filterall', !empty($CFG->stringfilters));
1377 unset_config('textfilters');
1378
1379 /// Main savepoint reached
a4cdd6d2 1380 upgrade_main_savepoint(true, 2009040600);
bbb45905 1381 }
1382
a4cdd6d2 1383 if ($oldversion < 2009041700) {
e7c6bf0e 1384 /// To ensure the UI remains consistent with no behaviour change, any
1385 /// 'until' date in an activity condition should have 1 second subtracted
1386 /// (to go from 0:00 on the following day to 23:59 on the previous one).
1387 $DB->execute('UPDATE {course_modules} SET availableuntil = availableuntil - 1 WHERE availableuntil <> 0');
6861b6fe 1388 require_once($CFG->dirroot . '/course/lib.php');
0f9534c1 1389 rebuild_course_cache(0, true);
e7c6bf0e 1390
1391 /// Main savepoint reached
a4cdd6d2 1392 upgrade_main_savepoint(true, 2009041700);
e7c6bf0e 1393 }
1394
a4cdd6d2 1395 if ($oldversion < 2009042600) {
6bdf4c99 1396 /// Deleting orphaned messages from deleted users.
1397 require_once($CFG->dirroot.'/message/lib.php');
1398 /// Detect deleted users with messages sent(useridfrom) and not read
1399 if ($deletedusers = $DB->get_records_sql('SELECT DISTINCT u.id
1400 FROM {user} u
1401 JOIN {message} m ON m.useridfrom = u.id
1402 WHERE u.deleted = ?', array(1))) {
1403 foreach ($deletedusers as $deleteduser) {
1404 message_move_userfrom_unread2read($deleteduser->id); // move messages
1405 }
1406 }
1407 /// Main savepoint reached
a4cdd6d2 1408 upgrade_main_savepoint(true, 2009042600);
6bdf4c99 1409 }
1410
e37cd84a 1411 /// Dropping all enums/check contraints from core. MDL-18577
a4cdd6d2 1412 if ($oldversion < 2009042700) {
e37cd84a 1413
1414 /// Changing list of values (enum) of field stattype on table stats_daily to none
1415 $table = new xmldb_table('stats_daily');
2a88f626 1416 $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
e37cd84a 1417
1418 /// Launch change of list of values for field stattype
2a88f626 1419 $dbman->drop_enum_from_field($table, $field);
e37cd84a 1420
1421 /// Changing list of values (enum) of field stattype on table stats_weekly to none
1422 $table = new xmldb_table('stats_weekly');
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_monthly to none
1429 $table = new xmldb_table('stats_monthly');
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 publishstate on table post to none
1436 $table = new xmldb_table('post');
2a88f626 1437 $field = new xmldb_field('publishstate', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'draft', 'attachment');
e37cd84a 1438
1439 /// Launch change of list of values for field publishstate
2a88f626 1440 $dbman->drop_enum_from_field($table, $field);
e37cd84a 1441
1442 /// Main savepoint reached
a4cdd6d2 1443 upgrade_main_savepoint(true, 2009042700);
e37cd84a 1444 }
1445
a4cdd6d2 1446 if ($oldversion < 2009043000) {
c045e45a 1447 unset_config('grade_report_showgroups');
a4cdd6d2 1448 upgrade_main_savepoint(true, 2009043000);
c045e45a 1449 }
1450
a4cdd6d2 1451 if ($oldversion < 2009050600) {
e88462a0 1452 /// Site front page blocks need to be moved due to page name change.
1453 $DB->set_field('block_instance', 'pagetype', 'site-index', array('pagetype' => 'course-view', 'pageid' => SITEID));
1454
1455 /// Main savepoint reached
a4cdd6d2 1456 upgrade_main_savepoint(true, 2009050600);
e88462a0 1457 }
1458
a4cdd6d2 1459 if ($oldversion < 2009050601) {
66b10689 1460
3aceb097 1461 /// Define table block_instance to be renamed to block_instances
66b10689 1462 $table = new xmldb_table('block_instance');
1463
1464 /// Launch rename table for block_instance
3aceb097 1465 $dbman->rename_table($table, 'block_instances');
66b10689 1466
1467 /// Main savepoint reached
a4cdd6d2 1468 upgrade_main_savepoint(true, 2009050601);
66b10689 1469 }
1470
a4cdd6d2 1471 if ($oldversion < 2009050602) {
66b10689 1472
1473 /// Define table block_instance to be renamed to block_instance_old
1474 $table = new xmldb_table('block_pinned');
1475
1476 /// Launch rename table for block_instance
1477 $dbman->rename_table($table, 'block_pinned_old');
1478
1479 /// Main savepoint reached
a4cdd6d2 1480 upgrade_main_savepoint(true, 2009050602);
66b10689 1481 }
1482
a4cdd6d2 1483 if ($oldversion < 2009050603) {
66b10689 1484
1485 /// Define table block_instance_old to be created
1486 $table = new xmldb_table('block_instance_old');
1487
1488 /// Adding fields to table block_instance_old
2b212777 1489 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1490 $table->add_field('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1491 $table->add_field('blockid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
1492 $table->add_field('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
1493 $table->add_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null);
1494 $table->add_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null);
1495 $table->add_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0');
1496 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
1497 $table->add_field('configdata', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
66b10689 1498
1499 /// Adding keys to table block_instance_old
1500 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1501 $table->add_key('blockid', XMLDB_KEY_FOREIGN, array('blockid'), 'block', array('id'));
1502
1503 /// Adding indexes to table block_instance_old
1504 $table->add_index('pageid', XMLDB_INDEX_NOTUNIQUE, array('pageid'));
1505 $table->add_index('pagetype', XMLDB_INDEX_NOTUNIQUE, array('pagetype'));
1506
1507 /// Conditionally launch create table for block_instance_old
1508 if (!$dbman->table_exists($table)) {
1509 $dbman->create_table($table);
1510 }
1511
1512 /// Main savepoint reached
a4cdd6d2 1513 upgrade_main_savepoint(true, 2009050603);
66b10689 1514 }
1515
a4cdd6d2 1516 if ($oldversion < 2009050604) {
66b10689 1517 /// Copy current blocks data from block_instances to block_instance_old
35550fd6 1518 $DB->execute('INSERT INTO {block_instance_old} (oldid, blockid, pageid, pagetype, position, weight, visible, configdata)
1519 SELECT id, blockid, pageid, pagetype, position, weight, visible, configdata FROM {block_instances} ORDER BY id');
66b10689 1520
a4cdd6d2 1521 upgrade_main_savepoint(true, 2009050604);
66b10689 1522 }
1523
a4cdd6d2 1524 if ($oldversion < 2009050605) {
66b10689 1525
1526 /// Define field multiple to be dropped from block
1527 $table = new xmldb_table('block');
1528 $field = new xmldb_field('multiple');
1529
1530 /// Conditionally launch drop field multiple
1531 if ($dbman->field_exists($table, $field)) {
1532 $dbman->drop_field($table, $field);
1533 }
1534
1535 /// Main savepoint reached
a4cdd6d2 1536 upgrade_main_savepoint(true, 2009050605);
66b10689 1537 }
1538
a4cdd6d2 1539 if ($oldversion < 2009050606) {
66b10689 1540 $table = new xmldb_table('block_instances');
1541
1542 /// Rename field weight on table block_instances to defaultweight
2b212777 1543 $field = new xmldb_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0', 'position');
66b10689 1544 $dbman->rename_field($table, $field, 'defaultweight');
1545
1546 /// Rename field position on table block_instances to defaultregion
2b212777 1547 $field = new xmldb_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, 'pagetype');
66b10689 1548 $dbman->rename_field($table, $field, 'defaultregion');
1549
1550 /// Main savepoint reached
a4cdd6d2 1551 upgrade_main_savepoint(true, 2009050606);
66b10689 1552 }
1553
a4cdd6d2 1554 if ($oldversion < 2009050607) {
66b10689 1555 /// Changing precision of field defaultregion on table block_instances to (16)
a26146d5 1556 $table = new xmldb_table('block_instances');
1557 $field = new xmldb_field('defaultregion', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, 'pagetype');
66b10689 1558
1559 /// Launch change of precision for field defaultregion
1560 $dbman->change_field_precision($table, $field);
1561
1562 /// Main savepoint reached
a4cdd6d2 1563 upgrade_main_savepoint(true, 2009050607);
66b10689 1564 }
1565
a4cdd6d2 1566 if ($oldversion < 2009050608) {
66b10689 1567 /// Change regions to the new notation
1568 $DB->set_field('block_instances', 'defaultregion', 'side-pre', array('defaultregion' => 'l'));
1569 $DB->set_field('block_instances', 'defaultregion', 'side-post', array('defaultregion' => 'r'));
1570 $DB->set_field('block_instances', 'defaultregion', 'course-view-top', array('defaultregion' => 'c'));
1571 // This third one is a custom value from contrib/patches/center_blocks_position_patch and the
1572 // flex page course format. Hopefully this new value is an adequate alternative.
1573
1574 /// Main savepoint reached
a4cdd6d2 1575 upgrade_main_savepoint(true, 2009050608);
66b10689 1576 }
1577
a4cdd6d2 1578 if ($oldversion < 2009050609) {
66b10689 1579
1580 /// Define key blockname (unique) to be added to block
1581 $table = new xmldb_table('block');
1582 $key = new xmldb_key('blockname', XMLDB_KEY_UNIQUE, array('name'));
1583
1584 /// Launch add key blockname
1585 $dbman->add_key($table, $key);
1586
1587 /// Main savepoint reached
a4cdd6d2 1588 upgrade_main_savepoint(true, 2009050609);
66b10689 1589 }
1590
a4cdd6d2 1591 if ($oldversion < 2009050610) {
66b10689 1592 $table = new xmldb_table('block_instances');
1593
1594 /// Define field blockname to be added to block_instances
2b212777 1595 $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, null, null, null, 'blockid');
66b10689 1596 if (!$dbman->field_exists($table, $field)) {
1597 $dbman->add_field($table, $field);
1598 }
1599
1600 /// Define field contextid to be added to block_instances
2b212777 1601 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'blockname');
66b10689 1602 if (!$dbman->field_exists($table, $field)) {
1603 $dbman->add_field($table, $field);
1604 }
1605
1606 /// Define field showinsubcontexts to be added to block_instances
2b212777 1607 $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, null, null, null, 'contextid');
66b10689 1608 if (!$dbman->field_exists($table, $field)) {
1609 $dbman->add_field($table, $field);
1610 }
1611
1612 /// Define field subpagepattern to be added to block_instances
2b212777 1613 $field = new xmldb_field('subpagepattern', XMLDB_TYPE_CHAR, '16', null, null, null, null, 'pagetype');
66b10689 1614 if (!$dbman->field_exists($table, $field)) {
1615 $dbman->add_field($table, $field);
1616 }
1617
1618 /// Main savepoint reached
a4cdd6d2 1619 upgrade_main_savepoint(true, 2009050610);
66b10689 1620 }
1621
a4cdd6d2 1622 if ($oldversion < 2009050611) {
66b10689 1623 $table = new xmldb_table('block_instances');
1624
1625 /// Fill in blockname from blockid
1626 $DB->execute("UPDATE {block_instances} SET blockname = (SELECT name FROM {block} WHERE id = blockid)");
1627
1628 /// Set showinsubcontexts = 0 for all rows.
1629 $DB->execute("UPDATE {block_instances} SET showinsubcontexts = 0");
1630
1631 /// Main savepoint reached
a4cdd6d2 1632 upgrade_main_savepoint(true, 2009050611);
66b10689 1633 }
1634
a4cdd6d2 1635 if ($oldversion < 2009050612) {
66b10689 1636
1637 /// Rename field pagetype on table block_instances to pagetypepattern
1638 $table = new xmldb_table('block_instances');
2b212777 1639 $field = new xmldb_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'pageid');
66b10689 1640
1641 /// Launch rename field pagetype
1642 $dbman->rename_field($table, $field, 'pagetypepattern');
1643
1644 /// Main savepoint reached
a4cdd6d2 1645 upgrade_main_savepoint(true, 2009050612);
66b10689 1646 }
1647
a4cdd6d2 1648 if ($oldversion < 2009050613) {
66b10689 1649 /// fill in contextid and subpage, and update pagetypepattern from pagetype and pageid
1650
1651 /// site-index
1652 $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
eb2761f8 1653 $DB->execute("UPDATE {block_instances} SET contextid = " . $frontpagecontext->id . ",
1654 pagetypepattern = 'site-index',
1655 subpagepattern = NULL
1656 WHERE pagetypepattern = 'site-index'");
66b10689 1657
1658 /// course-view
eb2761f8 1659 $DB->execute("UPDATE {block_instances} SET
1660 contextid = (
1661 SELECT {context}.id
1662 FROM {context}
1663 JOIN {course} ON instanceid = {course}.id AND contextlevel = " . CONTEXT_COURSE . "
1664 WHERE {course}.id = pageid
1665 ),
1666 pagetypepattern = 'course-view-*',
1667 subpagepattern = NULL
1668 WHERE pagetypepattern = 'course-view'");
66b10689 1669
1670 /// admin
1671 $syscontext = get_context_instance(CONTEXT_SYSTEM);
eb2761f8 1672 $DB->execute("UPDATE {block_instances} SET
1673 contextid = " . $syscontext->id . ",
1674 pagetypepattern = 'admin-*',
1675 subpagepattern = NULL
1676 WHERE pagetypepattern = 'admin'");
66b10689 1677
1678 /// my-index
eb2761f8 1679 $DB->execute("UPDATE {block_instances} SET
1680 contextid = (
1681 SELECT {context}.id
1682 FROM {context}
1683 JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . "
1684 WHERE {user}.id = pageid
1685 ),
1686 pagetypepattern = 'my-index',
1687 subpagepattern = NULL
1688 WHERE pagetypepattern = 'my-index'");
66b10689 1689
1690 /// tag-index
eb2761f8 1691 $DB->execute("UPDATE {block_instances} SET
1692 contextid = " . $syscontext->id . ",
1693 pagetypepattern = 'tag-index',
1694 subpagepattern = pageid
1695 WHERE pagetypepattern = 'tag-index'");
66b10689 1696
1697 /// blog-view
eb2761f8 1698 $DB->execute("UPDATE {block_instances} SET
1699 contextid = (
1700 SELECT {context}.id
1701 FROM {context}
1702 JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . "
1703 WHERE {user}.id = pageid
1704 ),
1705 pagetypepattern = 'blog-index',
1706 subpagepattern = NULL
1707 WHERE pagetypepattern = 'blog-view'");
66b10689 1708
1709 /// mod-xxx-view
1710 $moduleswithblocks = array('chat', 'data', 'lesson', 'quiz', 'dimdim', 'game', 'wiki', 'oublog');
1711 foreach ($moduleswithblocks as $modname) {
1712 if (!$dbman->table_exists($modname)) {
1713 continue;
1714 }
eb2761f8 1715 $DB->execute("UPDATE {block_instances} SET
1716 contextid = (
1717 SELECT {context}.id
1718 FROM {context}
1719 JOIN {course_modules} ON instanceid = {course_modules}.id AND contextlevel = " . CONTEXT_MODULE . "
1720 JOIN {modules} ON {modules}.id = {course_modules}.module AND {modules}.name = '$modname'
1721 JOIN {{$modname}} ON {course_modules}.instance = {{$modname}}.id
1722 WHERE {{$modname}}.id = pageid
1723 ),
1724 pagetypepattern = 'blog-index',
1725 subpagepattern = NULL
1726 WHERE pagetypepattern = 'blog-view'");
66b10689 1727 }
1728
1729 /// Main savepoint reached
a4cdd6d2 1730 upgrade_main_savepoint(true, 2009050613);
66b10689 1731 }
1732
a4cdd6d2 1733 if ($oldversion < 2009050614) {
66b10689 1734 /// fill in any missing contextids with a dummy value, so we can add the not-null constraint.
bf659cf0 1735 $DB->execute("UPDATE {block_instances} SET contextid = 0 WHERE contextid IS NULL");
66b10689 1736
1737 /// Main savepoint reached
a4cdd6d2 1738 upgrade_main_savepoint(true, 2009050614);
66b10689 1739 }
1740
a4cdd6d2 1741 if ($oldversion < 2009050615) {
66b10689 1742 $table = new xmldb_table('block_instances');
1743
57c3a358
EL
1744 /// Arrived here, any block_instances record without blockname is one
1745 /// orphan block coming from 1.9. Just delete them. MDL-22503
1746 $DB->delete_records_select('block_instances', 'blockname IS NULL');
1747
66b10689 1748 /// Changing nullability of field blockname on table block_instances to not null
2b212777 1749 $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'id');
66b10689 1750 $dbman->change_field_notnull($table, $field);
1751
1752 /// Changing nullability of field contextid on table block_instances to not null
2b212777 1753 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'blockname');
66b10689 1754 $dbman->change_field_notnull($table, $field);
1755
1756 /// Changing nullability of field showinsubcontexts on table block_instances to not null
2b212777 1757 $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, 'contextid');
66b10689 1758 $dbman->change_field_notnull($table, $field);
1759
1760 /// Main savepoint reached
a4cdd6d2 1761 upgrade_main_savepoint(true, 2009050615);
66b10689 1762 }
1763
a4cdd6d2 1764 if ($oldversion < 2009050616) {
66b10689 1765 /// Add exiting sticky blocks.
1766 $blocks = $DB->get_records('block');
1767 $syscontext = get_context_instance(CONTEXT_SYSTEM);
1768 $newregions = array(
1769 'l' => 'side-pre',
1770 'r' => 'side-post',
1771 'c' => 'course-view-top',
1772 );
1773 $stickyblocks = $DB->get_recordset('block_pinned_old');
1774 foreach ($stickyblocks as $stickyblock) {
4751e470
EL
1775 // Only if the block exists (avoid orphaned sticky blocks)
1776 if (!isset($blocks[$stickyblock->blockid]) || empty($blocks[$stickyblock->blockid]->name)) {
1777 continue;
1778 }
93d3a250 1779 $newblock = new object();
35fb85a7 1780 $newblock->blockname = $blocks[$stickyblock->blockid]->name;
66b10689 1781 $newblock->contextid = $syscontext->id;
1782 $newblock->showinsubcontexts = 1;
1783 switch ($stickyblock->pagetype) {
1784 case 'course-view':
1785 $newblock->pagetypepattern = 'course-view-*';
1786 break;
1787 default:
1788 $newblock->pagetypepattern = $stickyblock->pagetype;
1789 }
1790 $newblock->defaultregion = $newregions[$stickyblock->position];
1791 $newblock->defaultweight = $stickyblock->weight;
1792 $newblock->configdata = $stickyblock->configdata;
01de485d 1793 $newblock->visible = 1;
66b10689 1794 $DB->insert_record('block_instances', $newblock);
1795 }
1796
1797 /// Main savepoint reached
a4cdd6d2 1798 upgrade_main_savepoint(true, 2009050616);
66b10689 1799 }
1800
a4cdd6d2 1801 if ($oldversion < 2009050617) {
66b10689 1802
1803 /// Define table block_positions to be created
1804 $table = new xmldb_table('block_positions');
1805
1806 /// Adding fields to table block_positions
2b212777 1807 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1808 $table->add_field('blockinstanceid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1809 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1810 $table->add_field('pagetype', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
1811 $table->add_field('subpage', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null);
1812 $table->add_field('visible', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '1');
1813 $table->add_field('region', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null);
1814 $table->add_field('weight', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
66b10689 1815
1816 /// Adding keys to table block_positions
1817 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1818 $table->add_key('blockinstanceid', XMLDB_KEY_FOREIGN, array('blockinstanceid'), 'block_instances', array('id'));
1819 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
1820
1821 /// Adding indexes to table block_positions
1822 $table->add_index('blockinstanceid-contextid-pagetype-subpage', XMLDB_INDEX_UNIQUE, array('blockinstanceid', 'contextid', 'pagetype', 'subpage'));
1823
1824 /// Conditionally launch create table for block_positions
1825 if (!$dbman->table_exists($table)) {
1826 $dbman->create_table($table);
1827 }
1828
1829 /// Main savepoint reached
a4cdd6d2 1830 upgrade_main_savepoint(true, 2009050617);
66b10689 1831 }
1832
a4cdd6d2 1833 if ($oldversion < 2009050618) {
66b10689 1834 /// And block instances with visible = 0, copy that information to block_positions
1835 $DB->execute("INSERT INTO {block_positions} (blockinstanceid, contextid, pagetype, subpage, visible, region, weight)
1836 SELECT id, contextid,
1837 CASE WHEN pagetypepattern = 'course-view-*' THEN
1838 (SELECT " . $DB->sql_concat("'course-view-'", 'format') . "
1839 FROM {course}
1840 JOIN {context} ON {course}.id = {context}.instanceid
1841 WHERE {context}.id = contextid)
1842 ELSE pagetypepattern END,
1843 CASE WHEN subpagepattern IS NULL THEN ''
1844 ELSE subpagepattern END,
1845 0, defaultregion, defaultweight
1846 FROM {block_instances} WHERE visible = 0 AND pagetypepattern <> 'admin-*'");
1847
1848 /// Main savepoint reached
a4cdd6d2 1849 upgrade_main_savepoint(true, 2009050618);
66b10689 1850 }
1851
a4cdd6d2 1852 if ($oldversion < 2009050619) {
66b10689 1853 $table = new xmldb_table('block_instances');
1854
1855 /// Define field blockid to be dropped from block_instances
1856 $field = new xmldb_field('blockid');
1857 if ($dbman->field_exists($table, $field)) {
4276a19a 1858 /// Before dropping the field, drop dependent indexes
1859 $index = new xmldb_index('blockid', XMLDB_INDEX_NOTUNIQUE, array('blockid'));
1860 if ($dbman->index_exists($table, $index)) {
1861 /// Launch drop index blockid
1862 $dbman->drop_index($table, $index);
1863 }
66b10689 1864 $dbman->drop_field($table, $field);
1865 }
1866
1867 /// Define field pageid to be dropped from block_instances
1868 $field = new xmldb_field('pageid');
1869 if ($dbman->field_exists($table, $field)) {
4276a19a 1870 /// Before dropping the field, drop dependent indexes
1871 $index = new xmldb_index('pageid', XMLDB_INDEX_NOTUNIQUE, array('pageid'));
1872 if ($dbman->index_exists($table, $index)) {
1873 /// Launch drop index pageid
1874 $dbman->drop_index($table, $index);
1875 }
66b10689 1876 $dbman->drop_field($table, $field);
1877 }
1878
1879 /// Define field visible to be dropped from block_instances
1880 $field = new xmldb_field('visible');
1881 if ($dbman->field_exists($table, $field)) {
1882 $dbman->drop_field($table, $field);
1883 }
1884
1885 /// Main savepoint reached
a4cdd6d2 1886 upgrade_main_savepoint(true, 2009050619);
35079f53 1887 }
1888
a4cdd6d2 1889 if ($oldversion < 2009051200) {
ecdf5d17 1890 /// Let's check the status of mandatory mnet_host records, fixing them
1891 /// and moving "orphan" users to default localhost record. MDL-16879
aa9a6867 1892 echo $OUTPUT->notification('Fixing mnet records, this may take a while...', 'notifysuccess');
ecdf5d17 1893 upgrade_fix_incorrect_mnethostids();
1894
1895 /// Main savepoint reached
a4cdd6d2 1896 upgrade_main_savepoint(true, 2009051200);
ecdf5d17 1897 }
1898
a5747cf8 1899
a4cdd6d2 1900 if ($oldversion < 2009051700) {
a5747cf8 1901 /// migrate editor settings
1902 if (empty($CFG->htmleditor)) {
1903 set_config('texteditors', 'textarea');
1904 } else {
1905 set_config('texteditors', 'tinymce,textarea');
1906 }
1907
1908 unset_config('htmleditor');
1909 unset_config('defaulthtmleditor');
1910
1911 /// Main savepoint reached
a4cdd6d2 1912 upgrade_main_savepoint(true, 2009051700);
a5747cf8 1913 }
1914
6389e70a
PS
1915 /// Repeat 2009050607 upgrade step, which Petr commented out because of XMLDB
1916 /// stupidity, so lots of people will have missed.
a4cdd6d2 1917 if ($oldversion < 2009061600) {
52902cea 1918 /// Changing precision of field defaultregion on table block_instances to (16)
1919 $table = new xmldb_table('block_instances');
1920 $field = new xmldb_field('defaultregion', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, 'configdata');
1921
1922 /// Launch change of precision for field defaultregion
1923 $dbman->change_field_precision($table, $field);
1924
1925 /// Main savepoint reached
a4cdd6d2 1926 upgrade_main_savepoint(true, 2009061600);
52902cea 1927 }
1928
a4cdd6d2 1929 if ($oldversion < 2009061702) {
17da2e6f 1930 // standardizing plugin names
1931 if ($configs = $DB->get_records_select('config_plugins', "plugin LIKE 'quizreport_%'")) {
1932 foreach ($configs as $config) {
61676608 1933 unset_config($config->name, $config->plugin); /// unset old config
17da2e6f 1934 $config->plugin = str_replace('quizreport_', 'quiz_', $config->plugin);
61676608 1935 set_config($config->name, $config->value, $config->plugin); /// set new config
17da2e6f 1936 }
1937 }
1938 unset($configs);
a4cdd6d2 1939 upgrade_main_savepoint(true, 2009061702);
17da2e6f 1940 }
1941
a4cdd6d2 1942 if ($oldversion < 2009061703) {
17da2e6f 1943 // standardizing plugin names
1944 if ($configs = $DB->get_records_select('config_plugins', "plugin LIKE 'assignment_type_%'")) {
1945 foreach ($configs as $config) {
61676608 1946 unset_config($config->name, $config->plugin); /// unset old config
17da2e6f 1947 $config->plugin = str_replace('assignment_type_', 'assignment_', $config->plugin);
61676608 1948 set_config($config->name, $config->value, $config->plugin); /// set new config
17da2e6f 1949 }
1950 }
1951 unset($configs);
a4cdd6d2 1952 upgrade_main_savepoint(true, 2009061703);
17da2e6f 1953 }
1954
a4cdd6d2 1955 if ($oldversion < 2009061704) {
13a0d3d3 1956 // change component string in capability records to new "_" format
17da2e6f 1957 if ($caps = $DB->get_records('capabilities')) {
1958 foreach ($caps as $cap) {
1959 $cap->component = str_replace('/', '_', $cap->component);
1960 $DB->update_record('capabilities', $cap);
1961 }
1962 }
1963 unset($caps);
a4cdd6d2 1964 upgrade_main_savepoint(true, 2009061704);
17da2e6f 1965 }
1966
a4cdd6d2 1967 if ($oldversion < 2009061705) {
13a0d3d3 1968 // change component string in events_handlers records to new "_" format
17da2e6f 1969 if ($handlers = $DB->get_records('events_handlers')) {
1970 foreach ($handlers as $handler) {
1971 $handler->handlermodule = str_replace('/', '_', $handler->handlermodule);
1972 $DB->update_record('events_handlers', $handler);
1973 }
1974 }
1975 unset($handlers);
a4cdd6d2 1976 upgrade_main_savepoint(true, 2009061705);
17da2e6f 1977 }
1978
a4cdd6d2 1979 if ($oldversion < 2009063000) {
adf8f3f9 1980 // upgrade format of _with_advanced settings - quiz only
1981 // note: this can be removed later, not needed for upgrades from 1.9.x
c1f58efe 1982 if ($quiz = get_config('quiz')) {
1983 foreach ($quiz as $name=>$value) {
1984 if (strpos($name, 'fix_') !== 0) {
1985 continue;
1986 }
1987 $newname = substr($name,4).'_adv';
1988 set_config($newname, $value, 'quiz');
1989 unset_config($name, 'quiz');
adf8f3f9 1990 }
13a0d3d3 1991 }
a4cdd6d2 1992 upgrade_main_savepoint(true, 2009063000);
adf8f3f9 1993 }
13a0d3d3 1994
a4cdd6d2 1995 if ($oldversion < 2009071000) {
13a0d3d3 1996
1997 /// Rename field contextid on table block_instances to parentcontextid
1998 $table = new xmldb_table('block_instances');
1999 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'blockname');
2000
2001 /// Launch rename field parentcontextid
2002 $dbman->rename_field($table, $field, 'parentcontextid');
2003
2004 /// Main savepoint reached
a4cdd6d2 2005 upgrade_main_savepoint(true, 2009071000);
13a0d3d3 2006 }
2007
a4cdd6d2 2008 if ($oldversion < 2009071600) {
cae83708 2009
2010 /// Define field summaryformat to be added to post
2011 $table = new xmldb_table('post');
2012 $field = new xmldb_field('summaryformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'format');
2013
2014 /// Conditionally launch add field summaryformat
2015 if (!$dbman->field_exists($table, $field)) {
2016 $dbman->add_field($table, $field);
2017 }
2018
2019 /// Main savepoint reached
a4cdd6d2 2020 upgrade_main_savepoint(true, 2009071600);
cae83708 2021 }
e92c286c 2022
a4cdd6d2 2023 if ($oldversion < 2009072400) {
1bcb7eb5 2024
2025 /// Define table comments to be created
2026 $table = new xmldb_table('comments');
2027
2028 /// Adding fields to table comments
2029 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2030 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2031 $table->add_field('commentarea', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
2032 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2033 $table->add_field('content', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
2034 $table->add_field('format', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2035 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2036 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2037
2038 /// Adding keys to table comments
2039 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2040
2041 /// Conditionally launch create table for comments
2042 if (!$dbman->table_exists($table)) {
2043 $dbman->create_table($table);
2044 }
0a127169 2045
1bcb7eb5 2046 /// Main savepoint reached
a4cdd6d2 2047 upgrade_main_savepoint(true, 2009072400);
1bcb7eb5 2048 }
2049
7d2a0492 2050 /**
2051 * This upgrade is to set up the new navigation blocks that have been developed
2052 * as part of Moodle 2.0
2053 * Now I [Sam Hemelryk] hit a conundrum while exploring how to go about this
2054 * as not only do we want to install the new blocks but we also want to set up
2055 * default instances of them, and at the same time remove instances of the blocks
2056 * that were/will-be outmoded by the two new navigation blocks.
2057 * After talking it through with Tim Hunt {@link http://moodle.org/mod/cvsadmin/view.php?conversationid=3112}
2058 * we decided that the best way to go about this was to put the bulk of the
2059 * upgrade operation into core upgrade `here` but to let the plugins block
2060 * still install the blocks.
2061 * This leaves one hairy end in that we will create block_instances within the
2062 * DB before the blocks themselves are created within the DB
2063 */
a4cdd6d2 2064 if ($oldversion < 2009082800) {
7d2a0492 2065
2066 echo $OUTPUT->notification(get_string('navigationupgrade', 'admin'));
2067
2068 // Get the system context so we can set the block instances to it
2069 $syscontext = get_context_instance(CONTEXT_SYSTEM);
2070
2071 // An array to contain the new block instances we will create
2072 $newblockinstances = array('globalnavigation'=>new stdClass,'settingsnavigation'=>new stdClass);
2073 // The new global navigation block instance as a stdClass
2074 $newblockinstances['globalnavigation']->blockname = 'global_navigation_tree';
2075 $newblockinstances['globalnavigation']->parentcontextid = $syscontext->id; // System context
2e5eba85 2076 $newblockinstances['globalnavigation']->showinsubcontexts = true; // Show absolutely everywhere
7d2a0492 2077 $newblockinstances['globalnavigation']->pagetypepattern = '*'; // Thats right everywhere
2078 $newblockinstances['globalnavigation']->subpagetypepattern = null;
2079 $newblockinstances['globalnavigation']->defaultregion = BLOCK_POS_LEFT;
2080 $newblockinstances['globalnavigation']->defaultweight = -10; // Try make this first
2081 $newblockinstances['globalnavigation']->configdata = '';
2082 // The new settings navigation block instance as a stdClass
2083 $newblockinstances['settingsnavigation']->blockname = 'settings_navigation_tree';
2084 $newblockinstances['settingsnavigation']->parentcontextid = $syscontext->id;
2085 $newblockinstances['settingsnavigation']->showinsubcontexts = true;
2086 $newblockinstances['settingsnavigation']->pagetypepattern = '*';
2087 $newblockinstances['settingsnavigation']->subpagetypepattern = null;
2088 $newblockinstances['settingsnavigation']->defaultregion = BLOCK_POS_LEFT;
2089 $newblockinstances['settingsnavigation']->defaultweight = -9; // Try make this second
2090 $newblockinstances['settingsnavigation']->configdata = '';
2091
2092 // Blocks that are outmoded and for whom the bells will toll... by which I
2093 // mean we will delete all instances of
2094 $outmodedblocks = array('participants','admin_tree','activity_modules','admin','course_list');
2095 $outmodedblocksstring = '\''.join('\',\'',$outmodedblocks).'\'';
2096 unset($outmodedblocks);
2097 // Retrieve the block instance id's and parent contexts, so we can join them an GREATLY
2098 // cut down the number of delete queries we will need to run
2099 $allblockinstances = $DB->get_recordset_select('block_instances', 'blockname IN ('.$outmodedblocksstring.')', array(), '', 'id, parentcontextid');
1918f7e0 2100
7d2a0492 2101 $contextids = array();
2102 $instanceids = array();
2103 // Iterate through all block instances
2104 foreach ($allblockinstances as $blockinstance) {
2105 if (!in_array($blockinstance->parentcontextid, $contextids)) {
2106 $contextids[] = $blockinstance->parentcontextid;
2107
2108 // If we have over 1000 contexts clean them up and reset the array
2109 // this ensures we don't hit any nasty memory limits or such
2110 if (count($contextids) > 1000) {
61676608 2111 upgrade_cleanup_unwanted_block_contexts($contextids);
7d2a0492 2112 $contextids = array();
2113 }
2114 }
2115 if (!in_array($blockinstance->id, $instanceids)) {
2116 $instanceids[] = $blockinstance->id;
2117 // If we have more than 1000 block instances now remove all block positions
2118 // and empty the array
2119 if (count($contextids) > 1000) {
2120 $instanceidstring = join(',',$instanceids);
61676608 2121 $DB->delete_records_select('block_positions', 'blockinstanceid IN ('.$instanceidstring.')');
7d2a0492 2122 $instanceids = array();
2123 }
2124 }
2125 }
2126
61676608 2127 upgrade_cleanup_unwanted_block_contexts($contextids);
7d2a0492 2128
2129 $instanceidstring = join(',',$instanceids);
a4cdd6d2 2130 $DB->delete_records_select('block_positions', 'blockinstanceid IN ('.$instanceidstring.')');
1918f7e0 2131
7d2a0492 2132 unset($allblockinstances);
2133 unset($contextids);
2134 unset($instanceids);
2135 unset($instanceidstring);
1918f7e0 2136
7d2a0492 2137 // Now remove the actual block instance
7874b33d 2138 $DB->delete_records_select('block_instances', 'blockname IN ('.$outmodedblocksstring.')');
7d2a0492 2139 unset($outmodedblocksstring);
2140
2141 // Insert the new block instances. Remember they have not been installed yet
2142 // however this should not be a problem
2143 foreach ($newblockinstances as $blockinstance) {
2144 $blockinstance->id= $DB->insert_record('block_instances', $blockinstance);
2145 // Ensure the block context is created.
2146 get_context_instance(CONTEXT_BLOCK, $blockinstance->id);
2147 }
2148 unset($newblockinstances);
1918f7e0 2149
a4cdd6d2 2150 upgrade_main_savepoint(true, 2009082800);
7d2a0492 2151 // The end of the navigation upgrade
2152 }
2153
a4cdd6d2 2154 if ($oldversion < 2009090800){
b89e4ad8 2155 //insert new record for log_display table
2156 //used to record tag update.
2157 if (!$DB->record_exists('log_display', array('action'=>'update', 'module'=>'tag'))) {
2158 $log_action = new object();
2159 $log_action->module = 'tag';
2160 $log_action->action = 'update';
2161 $log_action->mtable = 'tag';
2162 $log_action->field = 'name';
2163
a4cdd6d2 2164 $DB->insert_record('log_display', $log_action);
b89e4ad8 2165 }
a4cdd6d2 2166 upgrade_main_savepoint(true, 2009090800);
b89e4ad8 2167 }
4313fa89 2168
a4cdd6d2 2169 if ($oldversion < 2009100602) {
4313fa89 2170 /// Define table external_functions to be created
2171 $table = new xmldb_table('external_functions');
2172
2173 /// Adding fields to table external_functions
2174 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
5d820ca2 2175 $table->add_field('name', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
2176 $table->add_field('classname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
2177 $table->add_field('methodname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
2178 $table->add_field('classpath', XMLDB_TYPE_CHAR, '255', null, null, null, null);
4313fa89 2179 $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
4313fa89 2180
2181 /// Adding keys to table external_functions
2182 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2183
5d820ca2 2184 /// Adding indexes to table external_functions
2185 $table->add_index('name', XMLDB_INDEX_UNIQUE, array('name'));
2186
2187 /// Launch create table for external_functions
2188 $dbman->create_table($table);
4313fa89 2189
5d820ca2 2190 /// Main savepoint reached
a4cdd6d2 2191 upgrade_main_savepoint(true, 2009100602);
5d820ca2 2192 }
4313fa89 2193
a4cdd6d2 2194 if ($oldversion < 2009100603) {
f6882162 2195 /// Define table external_services to be created
4313fa89 2196 $table = new xmldb_table('external_services');
2197
2198 /// Adding fields to table external_services
2199 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
5d820ca2 2200 $table->add_field('name', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
2201 $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2202 $table->add_field('requiredcapability', XMLDB_TYPE_CHAR, '150', null, null, null, null);
2203 $table->add_field('restrictedusers', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2204 $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, null, null, null);
f6882162
PS
2205 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2206 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
4313fa89 2207
2208 /// Adding keys to table external_services
2209 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2210
5b9a70a1 2211 /// Adding indexes to table external_services
2212 $table->add_index('name', XMLDB_INDEX_UNIQUE, array('name'));
2213
5d820ca2 2214 /// Launch create table for external_services
2215 $dbman->create_table($table);
4313fa89 2216
5d820ca2 2217 /// Main savepoint reached
a4cdd6d2 2218 upgrade_main_savepoint(true, 2009100603);
5d820ca2 2219 }
4313fa89 2220
a4cdd6d2 2221 if ($oldversion < 2009100604) {
4313fa89 2222 /// Define table external_services_functions to be created
2223 $table = new xmldb_table('external_services_functions');
2224
2225 /// Adding fields to table external_services_functions
2226 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2227 $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
5d820ca2 2228 $table->add_field('functionname', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
4313fa89 2229
2230 /// Adding keys to table external_services_functions
2231 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
5d820ca2 2232 $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id'));
4313fa89 2233
5d820ca2 2234 /// Launch create table for external_services_functions
2235 $dbman->create_table($table);
2236
2237 /// Main savepoint reached
a4cdd6d2 2238 upgrade_main_savepoint(true, 2009100604);
5d820ca2 2239 }
2240
a4cdd6d2 2241 if ($oldversion < 2009100605) {
5d820ca2 2242 /// Define table external_services_users to be created
2243 $table = new xmldb_table('external_services_users');
2244
2245 /// Adding fields to table external_services_users
2246 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2247 $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2248 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
88af54fa 2249 $table->add_field('iprestriction', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2250 $table->add_field('validuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
2251 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
5d820ca2 2252
2253 /// Adding keys to table external_services_users
2254 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2255 $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id'));
2256 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
2257
2258 /// Launch create table for external_services_users
2259 $dbman->create_table($table);
4313fa89 2260
2261 /// Main savepoint reached
a4cdd6d2 2262 upgrade_main_savepoint(true, 2009100605);
4313fa89 2263 }
2264
a4cdd6d2 2265 if ($oldversion < 2009102600) {
1942103f
PS
2266
2267 /// Define table external_tokens to be created
2268 $table = new xmldb_table('external_tokens');
2269
2270 /// Adding fields to table external_tokens
2271 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2272 $table->add_field('token', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null);
2273 $table->add_field('tokentype', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2274 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2275 $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2276 $table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, null, null, null);
2277 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
0b3681a4 2278 $table->add_field('creatorid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
1942103f
PS
2279 $table->add_field('iprestriction', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2280 $table->add_field('validuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
2281 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2282 $table->add_field('lastaccess', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
2283
2284 /// Adding keys to table external_tokens
2285 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2286 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
2287 $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id'));
2288 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
0b3681a4 2289 $table->add_key('creatorid', XMLDB_KEY_FOREIGN, array('creatorid'), 'user', array('id'));
1942103f
PS
2290
2291 /// Launch create table for external_tokens
2292 $dbman->create_table($table);
2293
2294 /// Main savepoint reached
a4cdd6d2 2295 upgrade_main_savepoint(true, 2009102600);
1942103f
PS
2296 }
2297
a4cdd6d2 2298 if ($oldversion < 2009103000) {
cc82aef6
NC
2299
2300 /// Define table blog_association to be created
2301 $table = new xmldb_table('blog_association');
2302
2303 /// Adding fields to table blog_association
2304 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2305 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2306 $table->add_field('blogid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2307
2308 /// Adding keys to table blog_association
2309 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2310 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
2311 $table->add_key('blogid', XMLDB_KEY_FOREIGN, array('blogid'), 'post', array('id'));
2312
2313 /// Conditionally launch create table for blog_association
2314 if (!$dbman->table_exists($table)) {
2315 $dbman->create_table($table);
2316 }
2317
2318/// Define table blog_external to be created
2319 $table = new xmldb_table('blog_external');
2320
2321 /// Adding fields to table blog_external
2322 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2323 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2324 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
2325 $table->add_field('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
2326 $table->add_field('url', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
2327 $table->add_field('filtertags', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2328 $table->add_field('failedlastsync', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2329 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
2330 $table->add_field('timefetched', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2331
2332 /// Adding keys to table blog_external
2333 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2334 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
2335
2336 /// Conditionally launch create table for blog_external
2337 if ($dbman->table_exists($table)) {
2338 // Delete the existing one first (comes from early dev version)
2339 $dbman->drop_table($table);
2340 }
2341 $dbman->create_table($table);
2342
adf176d7 2343 // now inform admins that some settings require attention after upgrade
cc82aef6
NC
2344 if (($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL) && empty($CFG->bloglevel_upgrade_complete)) {
2345 echo $OUTPUT->notification(get_string('bloglevelupgradenotice', 'admin'));
2346
cc82aef6
NC
2347 $site = get_site();
2348
2349 $a = new StdClass;
2350 $a->sitename = $site->fullname;
2351 $a->fixurl = "$CFG->wwwroot/$CFG->admin/bloglevelupgrade.php";
2352
c01678b1
PS
2353 $subject = get_string('bloglevelupgrade', 'admin');
2354 $description = get_string('bloglevelupgradedescription', 'admin', $a);
2355
2356 // can not use messaging here because it is not configured yet!
2357 upgrade_log(UPGRADE_LOG_NOTICE, null, $subject, $description);
cc82aef6
NC
2358 }
2359 /// Main savepoint reached
a4cdd6d2 2360 upgrade_main_savepoint(true, 2009103000);
cc82aef6 2361 }
117bd748 2362
a4cdd6d2 2363 if ($oldversion < 2009110400) {
985acc93
PS
2364 // list of tables where we need to add new format field and convert texts
2365 $extendtables = array('course' => 'summary',
2366 'course_categories' => 'description',
2367 'course_categories' => 'description',
2368 'course_request' => 'summary',
2369 'grade_outcomes' => 'description',
2370 'groups' => 'description',
2371 'groupings' => 'description',
2372 'scale' => 'description',
2373 'user_info_field' => 'description',
2374 'user_info_field' => 'defaultdata',
2375 'user_info_data' => 'data');
2376
2377 foreach ($extendtables as $tablestr=>$fieldstr) {
2378 $formatfieldstr = $fieldstr.'format';
8bdc9cac 2379
8bdc9cac 2380 $table = new xmldb_table($tablestr);
985acc93
PS
2381 $field = new xmldb_field($formatfieldstr, XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', $fieldstr);
2382 // Check that the field doesn't already exists
2383 if (!$dbman->field_exists($table, $field)) {
2384 // Add the new field
2385 $dbman->add_field($table, $field);
2386 }
2387 if ($CFG->texteditors !== 'textarea') {
2388 $rs = $DB->get_recordset($tablestr, array($formatfieldstr=>FORMAT_MOODLE), '', "id,$fieldstr,$formatfieldstr");
2389 foreach ($rs as $rec) {
2390 $rec->$fieldstr = text_to_html($rec->$fieldstr, false, false, true);
2391 $rec->$formatfieldstr = FORMAT_HTML;
2392 $DB->update_record($tablestr, $rec);
2393 upgrade_set_timeout();
8bdc9cac 2394 }
985acc93 2395 $rs->close();
8bdc9cac
SH
2396 }
2397 }
2398
985acc93 2399 unset($rec);
8bdc9cac
SH
2400 unset($extendtables);
2401
a4cdd6d2 2402 upgrade_main_savepoint(true, 2009110400);
8bdc9cac
SH
2403 }
2404
985acc93
PS
2405 if ($oldversion < 2009110401) {
2406 $table = new xmldb_table('user');
2407 $field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'description');
2408 // Check that the field doesn't already exists
2409 if (!$dbman->field_exists($table, $field)) {
2410 // Add the new field
2411 $dbman->add_field($table, $field);
2412 }
2413 if ($CFG->texteditors !== 'textarea') {
2414 $rs = $DB->get_recordset('user', array('descriptionformat'=>FORMAT_MOODLE, 'deleted'=>0, 'htmleditor'=>1), '', "id,description,descriptionformat");
2415 foreach ($rs as $rec) {
2416 $rec->description = text_to_html($rec->description, false, false, true);
2417 $rec->descriptionformat = FORMAT_HTML;
2418 $DB->update_record('user', $rec);
2419 upgrade_set_timeout();
2420 }
2421 $rs->close();
2422 }
2423
2424 upgrade_main_savepoint(true, 2009110401);
2425 }
2426
a4cdd6d2 2427 if ($oldversion < 2009112400) {
57e6ce5e
PS
2428 if (empty($CFG->passwordsaltmain)) {
2429 $subject = get_string('check_passwordsaltmain_name', 'report_security');
2430 $description = get_string('check_passwordsaltmain_warning', 'report_security');;
2431 upgrade_log(UPGRADE_LOG_NOTICE, null, $subject, $description);
2432 }
a4cdd6d2 2433 upgrade_main_savepoint(true, 2009112400);
57e6ce5e 2434 }
e1b9ac3e 2435
a4cdd6d2 2436 if ($oldversion < 2010011200) {
a25bb902
AD
2437 $table = new xmldb_table('grade_categories');
2438 $field = new xmldb_field('hidden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
2439
2440 if (!$dbman->field_exists($table, $field)) {
2441 $dbman->add_field($table, $field);
2442 }
2443
a4cdd6d2 2444 upgrade_main_savepoint(true, 2010011200);
a25bb902
AD
2445 }
2446
a4cdd6d2 2447 if ($oldversion < 2010012500) {
7062a798 2448 upgrade_fix_incorrect_mnethostids();
a4cdd6d2 2449 upgrade_main_savepoint(true, 2010012500);
7062a798 2450 }
de260e0f 2451
a4cdd6d2 2452 if ($oldversion < 2010012600) {
de260e0f
PL
2453 // do stuff to the mnet table
2454 $table = new xmldb_table('mnet_rpc');
2455
2456 $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path');
2457 $dbman->rename_field($table, $field, 'plugintype');
2458
2459 $field = new xmldb_field('parent', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path');
2460 $dbman->rename_field($table, $field, 'pluginname');
2461
2462 $field = new xmldb_field('filename', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'profile');
2463 if (!$dbman->field_exists($table, $field)) {
2464 $dbman->add_field($table, $field);
2465 }
2466
2467 $field = new xmldb_field('classname', XMLDB_TYPE_CHAR, '150', null, null, null, null, 'filename');
2468 if (!$dbman->field_exists($table, $field)) {
2469 $dbman->add_field($table, $field);
2470 }
2471
2472 $field = new xmldb_field('static', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'classname');
2473 if (!$dbman->field_exists($table, $field)) {
2474 $dbman->add_field($table, $field);
2475 }
2476
2477 /// Main savepoint reached
a4cdd6d2 2478 upgrade_main_savepoint(true, 2010012600);
de260e0f
PL
2479 }
2480
a4cdd6d2 2481 if ($oldversion < 2010012900) {
8586dbe2
PL
2482
2483 /// Define table mnet_remote_rpc to be created
2484 $table = new xmldb_table('mnet_remote_rpc');
2485
2486 /// Adding fields to table mnet_remote_rpc
2487 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2488 $table->add_field('functionname', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
2489 $table->add_field('xmlrpcpath', XMLDB_TYPE_CHAR, '80', null, XMLDB_NOTNULL, null, null);
2490
2491 /// Adding keys to table mnet_remote_rpc
2492 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2493
2494 /// Conditionally launch create table for mnet_remote_rpc
2495 if (!$dbman->table_exists($table)) {
2496 $dbman->create_table($table);
2497 }
2498
2499
2500 /// Define table mnet_remote_service2rpc to be created
2501 $table = new xmldb_table('mnet_remote_service2rpc');
2502
2503 /// Adding fields to table mnet_remote_service2rpc
2504 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2505 $table->add_field('serviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2506 $table->add_field('rpcid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2507
2508 /// Adding keys to table mnet_remote_service2rpc
2509 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2510
2511 /// Adding indexes to table mnet_remote_service2rpc
2512 $table->add_index('rpcid_serviceid', XMLDB_INDEX_UNIQUE, array('rpcid', 'serviceid'));
2513
2514 /// Conditionally launch create table for mnet_remote_service2rpc
2515 if (!$dbman->table_exists($table)) {
2516 $dbman->create_table($table);
2517 }
2518
2519
2520 /// Rename field function_name on table mnet_rpc to functionname
2521 $table = new xmldb_table('mnet_rpc');
2522 $field = new xmldb_field('function_name', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'id');
2523
2524 /// Launch rename field function_name
2525 $dbman->rename_field($table, $field, 'functionname');
2526
2527
2528 /// Rename field xmlrpc_path on table mnet_rpc to xmlrpcpath
2529 $table = new xmldb_table('mnet_rpc');
2530 $field = new xmldb_field('xmlrpc_path', XMLDB_TYPE_CHAR, '80', null, XMLDB_NOTNULL, null, null, 'function_name');
2531
2532 /// Launch rename field xmlrpc_path
2533 $dbman->rename_field($table, $field, 'xmlrpcpath');
2534
2535
2536 /// Main savepoint reached
a4cdd6d2 2537 upgrade_main_savepoint(true, 2010012900);
8586dbe2 2538 }
a6e9dafe 2539
a4cdd6d2 2540 if ($oldversion < 2010012901) {
a6e9dafe
PL
2541
2542 /// Define field plugintype to be added to mnet_remote_rpc
2543 $table = new xmldb_table('mnet_remote_rpc');
2544 $field = new xmldb_field('plugintype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpcpath');
2545
2546 /// Conditionally launch add field plugintype
2547 if (!$dbman->field_exists($table, $field)) {
2548 $dbman->add_field($table, $field);
2549 }
2550
a6e9dafe
PL
2551 /// Define field pluginname to be added to mnet_remote_rpc
2552 $field = new xmldb_field('pluginname', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'plugintype');
2553
2554 /// Conditionally launch add field pluginname
2555 if (!$dbman->field_exists($table, $field)) {
2556 $dbman->add_field($table, $field);
2557 }
5b7984a5
PL
2558
2559 /// Main savepoint reached
a4cdd6d2 2560 upgrade_main_savepoint(true, 2010012901);
5b7984a5
PL
2561 }
2562
a4cdd6d2 2563 if ($oldversion < 2010012902) {
5b7984a5
PL
2564
2565 /// Define field enabled to be added to mnet_remote_rpc
2566 $table = new xmldb_table('mnet_remote_rpc');
2567 $field = new xmldb_field('enabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, 'pluginname');
2568
2569 /// Conditionally launch add field enabled
2570 if (!$dbman->field_exists($table, $field)) {
2571 $dbman->add_field($table, $field);
2572 }
2573
2574 /// Main savepoint reached
a4cdd6d2 2575 upgrade_main_savepoint(true, 2010012902);
a6e9dafe
PL
2576 }
2577
f6852f02 2578 /// MDL-17863. Increase the portno column length on mnet_host to handle any port number
a4cdd6d2 2579 if ($oldversion < 2010020100) {
f6852f02
PL
2580 /// Changing precision of field portno on table mnet_host to (5)
2581 $table = new xmldb_table('mnet_host');
2582 $field = new xmldb_field('portno', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'transport');
2583
2584 /// Launch change of precision for field portno
2585 $dbman->change_field_precision($table, $field);
2586
a4cdd6d2 2587 upgrade_main_savepoint(true, 2010020100);
f6852f02
PL
2588 }
2589
a4cdd6d2 2590 if ($oldversion < 2010020300) {
d3d393ab
RW
2591
2592 /// Define field timecreated to be added to user
2593 $table = new xmldb_table('user');
2594 $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'trackforums');
2595
2596 if (!$dbman->field_exists($table, $field)) {
2597 /// Launch add field timecreated
2598 $dbman->add_field($table, $field);
2599
2600 $DB->execute("UPDATE {user} SET timecreated = firstaccess");
2601
2602 $sql = "UPDATE {user} SET timecreated = " . time() ." where timecreated = 0";
2603 $DB->execute($sql);
2604 }
a4cdd6d2 2605 upgrade_main_savepoint(true, 2010020300);
d3d393ab 2606 }
073d3804
EL
2607
2608 // MDL-21407. Trim leading spaces from default tex latexpreamble causing problems under some confs
a4cdd6d2 2609 if ($oldversion < 2010020301) {
073d3804
EL
2610 if ($preamble = $CFG->filter_tex_latexpreamble) {
2611 $preamble = preg_replace('/^ +/m', '', $preamble);
2612 set_config('filter_tex_latexpreamble', $preamble);
2613 }
a4cdd6d2 2614 upgrade_main_savepoint(true, 2010020301);
073d3804
EL
2615 }
2616
a4cdd6d2 2617 if ($oldversion < 2010021400) {
9a9012dc
PS
2618 /// Changes to modinfo mean we need to rebuild course cache
2619 require_once($CFG->dirroot . '/course/lib.php');
2620 rebuild_course_cache(0, true);
a4cdd6d2 2621 upgrade_main_savepoint(true, 2010021400);
9a9012dc
PS
2622 }
2623
a4cdd6d2 2624 if ($oldversion < 2010021800) {
c9606565 2625 $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle'));
a4cdd6d2 2626 upgrade_main_savepoint(true, 2010021800);
c9606565
PL
2627 }
2628
a4cdd6d2 2629 if ($oldversion < 2010031900) {
cd1bca89
PS
2630 // regeneration of sessions is always enabled, no need for this setting any more
2631 unset_config('regenloginsession');
a4cdd6d2 2632 upgrade_main_savepoint(true, 2010031900);
cd1bca89 2633 }
90723839 2634
a4cdd6d2 2635 if ($oldversion < 2010033101.02) {
98da6021 2636
1dce6261
DC
2637 /// Define table license to be created
2638 $table = new xmldb_table('license');
2639
2640 /// Adding fields to table license
2641 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2642 $table->add_field('shortname', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2643 $table->add_field('fullname', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
2644 $table->add_field('source', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2645 $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
2646 $table->add_field('version', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
2647
2648 /// Adding keys to table license
2649 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2650
2651 /// Conditionally launch create table for license
2652 if (!$dbman->table_exists($table)) {
2653 $dbman->create_table($table);
2654 }
d1d4813f
DC
2655 $active_licenses = array();
2656
2657 $license = new stdclass;
2658
2659 // add unknown license
2660 $license->shortname = 'unknown';
2661 $license->fullname = 'Unknown license';
2662 $license->source = '';
2663 $license->enabled = 1;
2664 $license->version = '2010033100';
2665 $active_licenses[] = $license->shortname;
2666 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2667 if ($record->version < $license->version) {
2668 // update license record
2669 $license->enabled = $record->enabled;
2670 $license->id = $record->id;
2671 $DB->update_record('license', $license);
2672 }
2673 } else {
2674 $DB->insert_record('license', $license);
2675 }
2676
2677 // add all rights reserved license
2678 $license->shortname = 'allrightsreserved';
2679 $license->fullname = 'All rights reserved';
2680 $license->source = 'http://en.wikipedia.org/wiki/All_rights_reserved';
2681 $license->enabled = 1;
2682 $license->version = '2010033100';
2683 $active_licenses[] = $license->shortname;
2684 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2685 if ($record->version < $license->version) {
2686 // update license record
2687 $license->id = $record->id;
2688 $license->enabled = $record->enabled;
2689 $DB->update_record('license', $license);
2690 }
2691 } else {
2692 $DB->insert_record('license', $license);
2693 }
2694
2695 // add public domain license
2696 $license->shortname = 'public';
2697 $license->fullname = 'Public Domain';
2698 $license->source = 'http://creativecommons.org/licenses/publicdomain/';
2699 $license->enabled = 1;
2700 $license->version = '2010033100';
2701 $active_licenses[] = $license->shortname;
2702 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2703 if ($record->version < $license->version) {
2704 // update license record
2705 $license->enabled = $record->enabled;
2706 $license->id = $record->id;
2707 $DB->update_record('license', $license);
2708 }
2709 } else {
2710 $DB->insert_record('license', $license);
2711 }
2712
2713 // add creative commons license
2714 $license->shortname = 'cc';
2715 $license->fullname = 'Creative Commons';
2716 $license->source = 'http://creativecommons.org/licenses/by/3.0/';
2717 $license->enabled = 1;
2718 $license->version = '2010033100';
2719 $active_licenses[] = $license->shortname;
2720 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2721 if ($record->version < $license->version) {
2722 // update license record
2723 $license->enabled = $record->enabled;
2724 $license->id = $record->id;
2725 $DB->update_record('license', $license);
2726 }
2727 } else {
2728 $DB->insert_record('license', $license);
2729 }
2730
2731 // add creative commons no derivs license
2732 $license->shortname = 'cc-nd';
2733 $license->fullname = 'Creative Commons - NoDerivs';
2734 $license->source = 'http://creativecommons.org/licenses/by-nd/3.0/';
2735 $license->enabled = 1;
2736 $license->version = '2010033100';
2737 $active_licenses[] = $license->shortname;
2738 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2739 if ($record->version < $license->version) {
2740 // update license record
2741 $license->enabled = $record->enabled;
2742 $license->id = $record->id;
2743 $DB->update_record('license', $license);
2744 }
2745 } else {
2746 $DB->insert_record('license', $license);
2747 }
2748
2749 // add creative commons no commercial no derivs license
2750 $license->shortname = 'cc-nc-nd';
2751 $license->fullname = 'Creative Commons - No Commercial NoDerivs';
2752 $license->source = 'http://creativecommons.org/licenses/by-nc-nd/3.0/';
2753 $license->enabled = 1;
2754 $license->version = '2010033100';
2755 $active_licenses[] = $license->shortname;
2756 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2757 if ($record->version < $license->version) {
2758 // update license record
2759 $license->enabled = $record->enabled;
2760 $license->id = $record->id;
2761 $DB->update_record('license', $license);
2762 }
2763 } else {
2764 $DB->insert_record('license', $license);
2765 }
2766
2767 // add creative commons no commercial
2768 $license->shortname = 'cc-nc-nd';
2769 $license->shortname = 'cc-nc';
2770 $license->fullname = 'Creative Commons - No Commercial';
2771 $license->source = 'http://creativecommons.org/licenses/by-nd/3.0/';
2772 $license->enabled = 1;
2773 $license->version = '2010033100';
2774 $active_licenses[] = $license->shortname;
2775 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2776 if ($record->version < $license->version) {
2777 // update license record
2778 $license->enabled = $record->enabled;
2779 $license->id = $record->id;
2780 $DB->update_record('license', $license);
2781 }
2782 } else {
2783 $DB->insert_record('license', $license);
2784 }
2785
2786 // add creative commons no commercial sharealike
2787 $license->shortname = 'cc-nc-sa';
2788 $license->fullname = 'Creative Commons - No Commercial ShareAlike';
2789 $license->source = 'http://creativecommons.org/licenses/by-nc-sa/3.0/';
2790 $license->enabled = 1;
2791 $license->version = '2010033100';
2792 $active_licenses[] = $license->shortname;
2793 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2794 if ($record->version < $license->version) {
2795 // update license record
2796 $license->enabled = $record->enabled;
2797 $license->id = $record->id;
2798 $DB->update_record('license', $license);
2799 }
2800 } else {
2801 $DB->insert_record('license', $license);
2802 }
2803
2804 // add creative commons sharealike
2805 $license->shortname = 'cc-sa';
2806 $license->fullname = 'Creative Commons - ShareAlike';
2807 $license->source = 'http://creativecommons.org/licenses/by-sa/3.0/';
2808 $license->enabled = 1;
2809 $license->version = '2010033100';
2810 $active_licenses[] = $license->shortname;
2811 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2812 if ($record->version < $license->version) {
2813 // update license record
2814 $license->enabled = $record->enabled;
2815 $license->id = $record->id;
2816 $DB->update_record('license', $license);
2817 }
2818 } else {
2819 $DB->insert_record('license', $license);
2820 }
2821
2822 set_config('licenses', implode(',', $active_licenses));
1dce6261
DC
2823 /// set site default license
2824 set_config('sitedefaultlicense', 'allrightsreserved');
2825
2826 /// Main savepoint reached
a4cdd6d2 2827 upgrade_main_savepoint(true, 2010033101.02);
1dce6261 2828 }
4f0c2d00 2829
a4cdd6d2 2830 if ($oldversion < 2010033102.00) {
4f0c2d00
PS
2831 // rename course view capability to participate
2832 $params = array('view'=>'moodle/course:view', 'participate'=>'moodle/course:participate');
2833 $sql = "UPDATE {role_capabilities} SET capability = :participate WHERE capability = :view";
2834 $DB->execute($sql, $params);
2835 $sql = "UPDATE {capabilities} SET name = :participate WHERE name = :view";
2836 $DB->execute($sql, $params);
2837 // note: the view capability is readded again at the end of upgrade, but with different meaning
a4cdd6d2 2838 upgrade_main_savepoint(true, 2010033102.00);
4f0c2d00
PS
2839 }
2840
a4cdd6d2 2841 if ($oldversion < 2010033102.01) {
4f0c2d00
PS
2842 // Define field archetype to be added to role table
2843 $table = new xmldb_table('role');
2844 $field = new xmldb_field('archetype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, 'sortorder');
2845 $dbman->add_field($table, $field);
a4cdd6d2 2846 upgrade_main_savepoint(true, 2010033102.01);
4f0c2d00
PS
2847 }
2848
a4cdd6d2 2849 if ($oldversion < 2010033102.02) {
4f0c2d00
PS
2850 // Set archetype for existing roles and change admin role to manager role
2851 $sql = "SELECT r.*, rc.capability
2852 FROM {role} r
2853 JOIN {role_capabilities} rc ON rc.roleid = r.id
2854 WHERE rc.contextid = :syscontextid AND rc.capability LIKE :legacycaps
2855 ORDER BY r.id";
2856 $params = array('syscontextid'=>SYSCONTEXTID, 'legacycaps'=>'moodle/legacy:%');
2857 $substart = strlen('moodle/legacy:');
2858 $roles = $DB->get_recordset_sql($sql, $params); // in theory could be multiple legacy flags in one role
2859 foreach ($roles as $role) {
2860 $role->archetype = substr($role->capability, $substart);
2861 unset($role->capability);
2862 if ($role->archetype === 'admin') {
2863 $role->archetype = 'manager';
2864 if ($role->shortname === 'admin') {
2865 $role->shortname = 'manager';
2866 $role->name = get_string('manager', 'role');
2867 $role->description = get_string('managerdescription', 'role');
2868 }
2869 }
2870 $DB->update_record('role', $role);
2871 }
2872 $roles->close();
2873
a4cdd6d2 2874 upgrade_main_savepoint(true, 2010033102.02);
4f0c2d00
PS
2875 }
2876
a4cdd6d2 2877 if ($oldversion < 2010033102.03) {
4f0c2d00
PS
2878 // Now pick site admins (===have manager role assigned at the system context)
2879 // and store them in the new $CFG->siteadmins setting as comma separated list
2880 $sql = "SELECT ra.id, ra.userid
2881 FROM {role_assignments} ra
2882 JOIN {role} r ON r.id = ra.roleid
2883 JOIN {user} u ON u.id = ra.userid
2884 WHERE ra.contextid = :syscontext AND r.archetype = 'manager' AND u.deleted = 0
2885 ORDER BY ra.id";
2886 $ras = $DB->get_records_sql($sql, array('syscontext'=>SYSCONTEXTID));
2887 $admins = array();
2888 foreach ($ras as $ra) {
2889 $admins[$ra->userid] = $ra->userid;
2890 set_config('siteadmins', implode(',', $admins)); // better to save it repeatedly, we do need at least one admin
2891 $DB->delete_records('role_assignments', array('id'=>$ra->id));
2892 }
2893
a4cdd6d2 2894 upgrade_main_savepoint(true, 2010033102.03);
4f0c2d00
PS
2895 }
2896
a4cdd6d2 2897 if ($oldversion < 2010033102.04) {
4f0c2d00
PS
2898 // clean up the manager roles
2899 $managers = $DB->get_records('role', array('archetype'=>'manager'));
2900 foreach ($managers as $manager) {
2901 // now sanitize the capabilities and overrides
2902 $DB->delete_records('role_capabilities', array('capability'=>'moodle/site:config', 'roleid'=>$manager->id)); // only site admins may configure servers
2903 // note: doanything and legacy caps are deleted automatically, they get moodle/course:view later at the end of the upgrade
2904
4f0c2d00
PS
2905 // remove manager role assignments bellow the course context level - admin role was never intended for activities and blocks,
2906 // the problem is that those assignments would not be visible after upgrade and old style admins in activities make no sense anyway
2907 $DB->delete_records_select('role_assignments', "roleid = :manager AND contextid IN (SELECT id FROM {context} WHERE contextlevel > 50)", array('manager'=>$manager->id));
2908
2909 // allow them to assign all roles except default user, guest and frontpage - users get these roles automatically on the fly when needed
2910 $DB->delete_records('role_allow_assign', array('roleid'=>$manager->id));
2911 $roles = $DB->get_records_sql("SELECT * FROM {role} WHERE archetype <> 'user' AND archetype <> 'guest' AND archetype <> 'frontpage'");
2912 foreach ($roles as $role) {
2913 $record = (object)array('roleid'=>$manager->id, 'allowassign'=>$role->id);
2914 $DB->insert_record('role_allow_assign', $record);
2915 }
2916
2917 // allow them to override all roles
2918 $DB->delete_records('role_allow_override', array('roleid'=>$manager->id));
2919 $roles = $DB->get_records_sql("SELECT * FROM {role}");
2920 foreach ($roles as $role) {
2921 $record = (object)array('roleid'=>$manager->id, 'allowoverride'=>$role->id);
2922 $DB->insert_record('role_allow_override', $record);
2923 }
2924
2925 // allow them to switch to all following roles
2926 $DB->delete_records('role_allow_switch', array('roleid'=>$manager->id));
2927 $roles = $DB->get_records_sql("SELECT * FROM {role} WHERE archetype IN ('student', 'teacher', 'editingteacher')");
2928 foreach ($roles as $role) {
2929 $record = (object)array('roleid'=>$manager->id, 'allowswitch'=>$role->id);
2930 $DB->insert_record('role_allow_switch', $record);
2931 }
2932 }
2933
a4cdd6d2 2934 upgrade_main_savepoint(true, 2010033102.04);
4f0c2d00
PS
2935 }
2936
a4cdd6d2 2937 if ($oldversion < 2010033102.05) {
4f0c2d00
PS
2938 // remove course:view from all roles that are not used for enrolment, it does NOT belong there because it really means user is enrolled!
2939 $noenrolroles = $DB->get_records_select('role', "archetype IN ('guest', 'user', 'manager', 'coursecreator', 'frontpage')");
2940 foreach ($noenrolroles as $role) {
2941 $DB->delete_records('role_capabilities', array('roleid'=>$role->id, 'capability'=>'moodle/course:participate'));
2942 }
a4cdd6d2 2943 upgrade_main_savepoint(true, 2010033102.05);
4f0c2d00
PS
2944 }
2945
a4cdd6d2 2946 if ($oldversion < 2010033102.06) {
4f0c2d00
PS
2947 // make sure there is nothing weird in default user role
2948 if (!empty($CFG->defaultuserroleid)) {
2949 if ($role = $DB->get_record('role', array('id'=>$CFG->defaultuserroleid))) {
2950 if ($role->archetype !== '' and $role->archetype !== 'user') {
2951 upgrade_log(UPGRADE_LOG_NOTICE, null, 'Default authenticated user role (defaultuserroleid) value is invalid, setting cleared.');
2952 unset_config('defaultuserroleid');
2953 }
2954 } else {
2955 unset_config('defaultuserroleid');
2956 }
2957 }
a4cdd6d2 2958 upgrade_main_savepoint(true, 2010033102.06);
4f0c2d00
PS
2959 }
2960
a4cdd6d2 2961 if ($oldversion < 2010033102.07) {
4f0c2d00
PS
2962 if (!empty($CFG->displayloginfailures) and $CFG->displayloginfailures === 'teacher') {
2963 upgrade_log(UPGRADE_LOG_NOTICE, null, 'Displaying of login failuters to teachers is not supported any more.');
2964 unset_config('displayloginfailures');
2965 }
a4cdd6d2 2966 upgrade_main_savepoint(true, 2010033102.07);
4f0c2d00
PS
2967 }
2968
a4cdd6d2 2969 if ($oldversion < 2010033102.08) {
4f0c2d00
PS
2970 // make sure there are no problems in default guest role settings
2971 if (!empty($CFG->guestroleid)) {
2972 if ($role = $DB->get_record('role', array('id'=>$CFG->guestroleid))) {
2973 if ($role->archetype !== '' and $role->archetype !== 'guest') {
2974 upgrade_log(UPGRADE_LOG_NOTICE, null, 'Default guest role (guestroleid) value is invalid, setting cleared.');
2975 unset_config('guestroleid');
2976 }
2977 } else {
df997f84 2978 upgrade_log(UPGRADE_LOG_NOTICE, null, 'Role specified in Default guest role (guestroleid) does not exist, setting cleared.');
4f0c2d00
PS
2979 unset_config('guestroleid');
2980 }
2981 }
2982 // remove all roles of the guest account - the only way to change it is to override the guest role, sorry
df997f84 2983 // the guest account gets all the role assignments on the fly which works fine in has_capability(),
4f0c2d00
PS
2984 $DB->delete_records_select('role_assignments', "userid IN (SELECT id FROM {user} WHERE username = 'guest')");
2985
a4cdd6d2 2986 upgrade_main_savepoint(true, 2010033102.08);
4f0c2d00
PS
2987 }
2988
df997f84 2989 /// New table for storing which roles can be assigned in which contexts.
a4cdd6d2 2990 if ($oldversion < 2010033102.09) {
4f0c2d00 2991
df997f84
PS
2992 /// Define table role_context_levels to be created
2993 $table = new xmldb_table('role_context_levels');
2994
2995 /// Adding fields to table role_context_levels
2996 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2997 $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2998 $table->add_field('contextlevel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2999
3000 /// Adding keys to table role_context_levels
3001 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3002 $table->add_key('contextlevel-roleid', XMLDB_KEY_UNIQUE, array('contextlevel', 'roleid'));
3003 $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
3004
3005 /// Conditionally launch create table for role_context_levels
3006 if (!$dbman->table_exists($table)) {
3007 $dbman->create_table($table);
3008 }
3009
3010 /// Main savepoint reached
a4cdd6d2 3011 upgrade_main_savepoint(true, 2010033102.09);
df997f84
PS
3012 }
3013
a4cdd6d2 3014 if ($oldversion < 2010033102.10) {
df997f84
PS
3015 // Now populate the role_context_levels table with the default values
3016 // NOTE: do not use accesslib methods here
3017
3018 $rolecontextlevels = array();
3019 $defaults = array('manager' => array(CONTEXT_SYSTEM, CONTEXT_COURSECAT, CONTEXT_COURSE),
3020 'coursecreator' => array(CONTEXT_SYSTEM, CONTEXT_COURSECAT),
3021 'editingteacher' => array(CONTEXT_COURSE, CONTEXT_MODULE),
3022 'teacher' => array(CONTEXT_COURSE, CONTEXT_MODULE),
3023 'student' => array(CONTEXT_COURSE, CONTEXT_MODULE),
3024 'guest' => array(),
3025 'user' => array(),
3026 'frontpage' => array());
3027
3028 $roles = $DB->get_records('role', array(), '', 'id, archetype');
4f0c2d00 3029 foreach ($roles as $role) {
df997f84
PS
3030 if (isset($defaults[$role->archetype])) {
3031 $rolecontextlevels[$role->id] = $defaults[$role->archetype];
3032 }
3033 }
3034
3035 // add roles without archetypes, it may contain weird things, but we can not fix them
3db2ddbd 3036 list($narsql, $params) = $DB->get_in_or_equal(array_keys($defaults), SQL_PARAMS_NAMED, 'ar000', false);
df997f84
PS
3037 $sql = "SELECT DISTINCT ra.roleid, con.contextlevel
3038 FROM {role_assignments} ra
3db2ddbd
PS
3039 JOIN {context} con ON ra.contextid = con.id
3040 JOIN {role} r ON r.id = ra.roleid
3041 WHERE r.archetype $narsql";
3042 $existingrolecontextlevels = $DB->get_recordset_sql($sql, $params);
df997f84 3043 foreach ($existingrolecontextlevels as $rcl) {
df997f84 3044 if (!isset($rolecontextlevels[$rcl->roleid])) {
3db2ddbd 3045 $rolecontextlevels[$rcl->roleid] = array();
df997f84 3046 }
3db2ddbd 3047 $rolecontextlevels[$rcl->roleid][] = $rcl->contextlevel;
df997f84
PS
3048 }
3049 $existingrolecontextlevels->close();
3050
3051 // Put the data into the database.
3052 $rcl = new object();
3053 foreach ($rolecontextlevels as $roleid => $contextlevels) {
3054 $rcl->roleid = $roleid;
3055 foreach ($contextlevels as $level) {
3056 $rcl->contextlevel = $level;
3057 $DB->insert_record('role_context_levels', $rcl, false);
3058 }
4f0c2d00
PS
3059 }
3060
df997f84
PS
3061 // release memory!!
3062 unset($roles);
3063 unset($defaults);
3064 unset($rcl);
3065 unset($existingrolecontextlevels);
3066 unset($rolecontextlevels);
4f0c2d00
PS
3067
3068 // Main savepoint reached
a4cdd6d2 3069 upgrade_main_savepoint(true, 2010033102.10);
4f0c2d00
PS
3070 }
3071
a4cdd6d2 3072 if ($oldversion < 2010040700) {
98da6021
PS
3073 // migrate old groupings --> groupmembersonly setting
3074 if (isset($CFG->enablegroupings)) {
3075 set_config('enablegroupmembersonly', $CFG->enablegroupings);
3076 unset_config('enablegroupings');
3077 }
3078
3079 // Main savepoint reached
a4cdd6d2 3080 upgrade_main_savepoint(true, 2010040700);
98da6021
PS
3081 }
3082
a4cdd6d2 3083 if ($oldversion < 2010040900) {
3a915b06
PS
3084
3085 // Changing the default of field lang on table user to good old "en"
3086 $table = new xmldb_table('user');
3087 $field = new xmldb_field('lang', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, 'en', 'country');
3088
3089 // Launch change of default for field lang
3090 $dbman->change_field_default($table, $field);
3091
3092 // update main site lang
3093 if (strpos($CFG->lang, '_utf8') !== false) {
3094 $lang = str_replace('_utf8', '', $CFG->lang);
3095 set_config('lang', $lang);
3096 }
3097
2357ab49
PS
3098 // tweak langlist
3099 if (!empty($CFG->langlist)) {
3100 $langs = explode(',', $CFG->langlist);
3101 foreach ($langs as $key=>$lang) {
3102 $lang = str_replace('_utf8', '', $lang);
3103 $langs[$key] = $lang;
3104 }
3105 set_config('langlist', implode(',', $langs));
3106 }
3107
3a915b06 3108 // Main savepoint reached
a4cdd6d2 3109 upgrade_main_savepoint(true, 2010040900);
3a915b06
PS
3110 }
3111
a4cdd6d2 3112 if ($oldversion < 2010040901) {
3a915b06
PS
3113
3114 // Remove "_utf8" suffix from all langs in user table
3115 $langs = $DB->get_records_sql("SELECT DISTINCT lang FROM {user} WHERE lang LIKE ?", array('%_utf8'));
3116
3117 foreach ($langs as $lang=>$unused) {
3118 $newlang = str_replace('_utf8', '', $lang);
3119 $sql = "UPDATE {user} SET lang = :newlang WHERE lang = :lang";
3120 $DB->execute($sql, array('newlang'=>$newlang, 'lang'=>$lang));
3121 }
3122
3123 // Main savepoint reached
a4cdd6d2 3124 upgrade_main_savepoint(true, 2010040901);
3a915b06
PS
3125 }
3126
a4cdd6d2 3127 if ($oldversion < 2010041301) {
3406acde
SH
3128 $sql = "UPDATE {block} SET name=? WHERE name=?";
3129 $DB->execute($sql, array('navigation', 'global_navigation_tree'));
3130 $DB->execute($sql, array('settings', 'settings_navigation_tree'));
3131
3132 $sql = "UPDATE {block_instances} SET blockname=? WHERE blockname=?";
3133 $DB->execute($sql, array('navigation', 'global_navigation_tree'));
3134 $DB->execute($sql, array('settings', 'settings_navigation_tree'));
a4cdd6d2 3135 upgrade_main_savepoint(true, 2010041301);
3406acde
SH
3136 }
3137
a4cdd6d2 3138 if ($oldversion < 2010042100) {
ee4d3dee
EL
3139
3140 /// Define table backup_controllers to be created
3141 $table = new xmldb_table('backup_controllers');
3142
3143 /// Adding fields to table backup_controllers
3144 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3145 $table->add_field('backupid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
3146 $table->add_field('type', XMLDB_TYPE_CHAR, '6', null, XMLDB_NOTNULL, null, null);
3147 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3148 $table->add_field('format', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null);
3149 $table->add_field('interactive', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3150 $table->add_field('purpose', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3151 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3152 $table->add_field('status', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3153 $table->add_field('execution', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3154 $table->add_field('executiontime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3155 $table->add_field('checksum', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
3156 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3157 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3158 $table->add_field('controller', XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null);
3159
3160 /// Adding keys to table backup_controllers
3161 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3162 $table->add_key('backupid_uk', XMLDB_KEY_UNIQUE, array('backupid'));
3163 $table->add_key('userid_fk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
3164
3165 /// Adding indexes to table backup_controllers
3166 $table->add_index('typeitem_ix', XMLDB_INDEX_NOTUNIQUE, array('type', 'itemid'));
3167
3168 /// Conditionally launch create table for backup_controllers
3169 if (!$dbman->table_exists($table)) {
3170 $dbman->create_table($table);
3171 }
3172
3173 /// Define table backup_ids_template to be created
3174 $table = new xmldb_table('backup_ids_template');
3175
3176 /// Adding fields to table backup_ids_template
3177 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3178 $table->add_field('backupid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
3179 $table->add_field('itemname', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
3180 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3181 $table->add_field('parentitemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
3182
3183 /// Adding keys to table backup_ids_template
3184 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3185 $table->add_key('backupid_itemname_itemid_uk', XMLDB_KEY_UNIQUE, array('backupid', 'itemname', 'itemid'));
3186
3187 /// Adding indexes to table backup_ids_template
3188 $table->add_index('backupid_parentitemid_ix', XMLDB_INDEX_NOTUNIQUE, array('backupid', 'itemname', 'parentitemid'));
3189
3190 /// Conditionally launch create table for backup_controllers
3191 if (!$dbman->table_exists($table)) {
3192 $dbman->create_table($table);
3193 }
3194
3195 /// Main savepoint reached
a4cdd6d2 3196 upgrade_main_savepoint(true, 2010042100);
ee4d3dee
EL
3197 }
3198
a4cdd6d2 3199 if ($oldversion < 2010042301) {
0f4ab67d
SH
3200
3201 $table = new xmldb_table('course_sections');
3202 $field = new xmldb_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'section');
3203
3204 if (!$dbman->field_exists($table, $field)) {
3205 $dbman->add_field($table, $field);
3206 }
3207
a4cdd6d2 3208 upgrade_main_savepoint(true, 2010042301);
0f4ab67d
SH
3209 }
3210
a4cdd6d2 3211 if ($oldversion < 2010042302) {
74180df2
PS
3212 // Define table cohort to be created
3213 $table = new xmldb_table('cohort');
3214
3215 // Adding fields to table cohort
3216 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3217 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3218 $table->add_field('name', XMLDB_TYPE_CHAR, '254', null, XMLDB_NOTNULL, null, null);
3219 $table->add_field('idnumber', XMLDB_TYPE_CHAR, '100', null, null, null, null);
3220 $table->add_field('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
3221 $table->add_field('descriptionformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
df997f84 3222 $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
74180df2
PS
3223 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3224 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3225
3226 // Adding keys to table cohort
3227 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3228 $table->add_key('context', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
3229
3230 // Conditionally launch create table for cohort
3231 if (!$dbman->table_exists($table)) {
3232 $dbman->create_table($table);
3233 }
3234
a4cdd6d2 3235 upgrade_main_savepoint(true, 2010042302);
74180df2
PS
3236 }
3237
a4cdd6d2 3238 if ($oldversion < 2010042303) {
74180df2
PS
3239 // Define table cohort_members to be created
3240 $table = new xmldb_table('cohort_members');
3241
3242 // Adding fields to table cohort_members
3243 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3244 $table->add_field('cohortid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3245 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3246 $table->add_field('timeadded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3247
3248 // Adding keys to table cohort_members
3249 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3250 $table->add_key('cohortid', XMLDB_KEY_FOREIGN, array('cohortid'), 'cohort', array('id'));
3251 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
3252
3253 // Adding indexes to table cohort_members
3254 $table->add_index('cohortid-userid', XMLDB_INDEX_UNIQUE, array('cohortid', 'userid'));
3255
3256 // Conditionally launch create table for cohort_members
3257 if (!$dbman->table_exists($table)) {
3258 $dbman->create_table($table);
3259 }
3260
3261 // Main savepoint reached
a4cdd6d2 3262 upgrade_main_savepoint(true, 2010042303);
cc3b3fae 3263 }