3 // This file keeps track of upgrades to Moodle.
5 // Sometimes, changes between versions involve
6 // alterations to database structures and other
7 // major things that may break installations.
9 // The upgrade function in this file will attempt
10 // to perform all the necessary actions to upgrade
11 // your older installation to the current version.
13 // If there's something it cannot do itself, it
14 // will tell you what you need to do.
16 // The commands in here will all be database-neutral,
17 // using the methods of database_manager class
19 // Please do not forget to use upgrade_set_timeout()
20 // before any action that may take longer time to finish.
24 * @global stdClass $CFG
25 * @global stdClass $USER
26 * @global moodle_database $DB
27 * @global core_renderer $OUTPUT
28 * @param int $oldversion
31 function xmldb_main_upgrade($oldversion) {
32 global $CFG, $USER, $DB, $OUTPUT;
34 require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions
36 $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
38 ////////////////////////////////////////
39 ///upgrade supported only from 1.9.x ///
40 ////////////////////////////////////////
42 if ($oldversion < 2008030600) {
43 //NOTE: this table was added much later later in dev cycle, but we need it here, upgrades from pre PR1 not supported
45 /// Define table upgrade_log to be created
46 $table = new xmldb_table('upgrade_log');
48 /// Adding fields to table upgrade_log
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);
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'));
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'));
67 /// Create table for upgrade_log
68 $dbman->create_table($table);
70 /// Main savepoint reached
71 upgrade_main_savepoint(true, 2008030600);
74 if ($oldversion < 2008030601) {
75 //NOTE: this table was added much later later in dev cycle, but we need it here, upgrades from pre PR1 not supported
77 /// Define table log_queries to be created
78 $table = new xmldb_table('log_queries');
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);
91 /// Adding keys to table log_queries
92 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
94 /// Conditionally launch create table for log_queries
95 $dbman->create_table($table);
97 /// Main savepoint reached
98 upgrade_main_savepoint(true, 2008030601);
101 if ($oldversion < 2008030602) {
102 @unlink($CFG->dataroot.'/cache/languages');
104 // rename old lang directory so that the new and old langs do not mix
105 if (rename("$CFG->dataroot/lang", "$CFG->dataroot/oldlang")) {
106 $oldlang = "$CFG->dataroot/oldlang";
108 $oldlang = "$CFG->dataroot/lang";
110 // TODO: fetch previously installed languages ("*_utf8") found in $oldlang from moodle.org
111 upgrade_set_timeout(60*20); // this may take a while
114 // TODO: add some info file to $oldlang describing what to do with "$oldlang/*_utf8_local" dirs
117 // Main savepoint reached
118 upgrade_main_savepoint(true, 2008030602);
121 if ($oldversion < 2008030700) {
122 upgrade_set_timeout(60*20); // this may take a while
124 /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters
125 $table = new xmldb_table('grade_letters');
126 $index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
128 /// Launch drop index contextid-lowerboundary
129 if ($dbman->index_exists($table, $index)) {
130 $dbman->drop_index($table, $index);
133 /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
134 $table = new xmldb_table('grade_letters');
135 $index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
137 /// Launch add index contextid-lowerboundary-letter
138 $dbman->add_index($table, $index);
140 /// Main savepoint reached
141 upgrade_main_savepoint(true, 2008030700);
144 if ($oldversion < 2008050100) {
145 // Update courses that used weekscss to weeks
146 $DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss'));
147 upgrade_main_savepoint(true, 2008050100);
150 if ($oldversion < 2008050200) {
151 // remove unused config options
152 unset_config('statsrolesupgraded');
153 upgrade_main_savepoint(true, 2008050200);
156 if ($oldversion < 2008050700) {
157 upgrade_set_timeout(60*20); // this may take a while
159 /// Fix minor problem caused by MDL-5482.
160 require_once($CFG->dirroot . '/question/upgrade.php');
161 question_fix_random_question_parents();
162 upgrade_main_savepoint(true, 2008050700);
165 if ($oldversion < 2008051201) {
166 echo $OUTPUT->notification('Increasing size of user idnumber field, this may take a while...', 'notifysuccess');
167 upgrade_set_timeout(60*20); // this may take a while
169 /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859
170 $dbfamily = $DB->get_dbfamily();
171 if ($dbfamily === 'mysql' || $dbfamily === 'postgres') {
172 $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL");
175 /// Define index idnumber (not unique) to be dropped form user
176 $table = new xmldb_table('user');
177 $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
179 /// Launch drop index idnumber
180 if ($dbman->index_exists($table, $index)) {
181 $dbman->drop_index($table, $index);
184 /// Changing precision of field idnumber on table user to (255)
185 $table = new xmldb_table('user');
186 $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'password');
188 /// Launch change of precision for field idnumber
189 $dbman->change_field_precision($table, $field);
191 /// Launch add index idnumber again
192 $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
193 $dbman->add_index($table, $index);
195 /// Main savepoint reached
196 upgrade_main_savepoint(true, 2008051201);
199 if ($oldversion < 2008051202) {
200 $log_action = new object();
201 $log_action->module = 'course';
202 $log_action->action = 'unenrol';
203 $log_action->mtable = 'course';
204 $log_action->field = 'fullname';
205 if (!$DB->record_exists('log_display', array('action'=>'unenrol', 'module'=>'course'))) {
206 $DB->insert_record('log_display', $log_action);
208 upgrade_main_savepoint(true, 2008051202);
211 if ($oldversion < 2008051203) {
212 $table = new xmldb_table('mnet_enrol_course');
213 $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
214 $dbman->change_field_precision($table, $field);
215 upgrade_main_savepoint(true, 2008051203);
218 if ($oldversion < 2008063001) {
219 upgrade_set_timeout(60*20); // this may take a while
221 // table to be modified
222 $table = new xmldb_table('tag_instance');
224 $field = new xmldb_field('tiuserid');
225 if (!$dbman->field_exists($table, $field)) {
226 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'itemid');
227 $dbman->add_field($table, $field);
230 $index = new xmldb_index('itemtype-itemid-tagid');
231 $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));
232 if ($dbman->index_exists($table, $index)) {
233 $dbman->drop_index($table, $index);
235 $index = new xmldb_index('itemtype-itemid-tagid-tiuserid');
236 $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
237 if (!$dbman->index_exists($table, $index)) {
238 $dbman->add_index($table, $index);
241 /// Main savepoint reached
242 upgrade_main_savepoint(true, 2008063001);
245 if ($oldversion < 2008070300) {
246 $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false));
247 upgrade_main_savepoint(true, 2008070300);
250 if ($oldversion < 2008070701) {
252 /// Define table portfolio_instance to be created
253 $table = new xmldb_table('portfolio_instance');
255 /// Adding fields to table portfolio_instance
256 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
257 $table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
258 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
259 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
261 /// Adding keys to table portfolio_instance
262 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
264 /// Conditionally launch create table for portfolio_instance
265 if (!$dbman->table_exists($table)) {
266 $dbman->create_table($table);
268 /// Define table portfolio_instance_config to be created
269 $table = new xmldb_table('portfolio_instance_config');
271 /// Adding fields to table portfolio_instance_config
272 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
273 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
274 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
275 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
277 /// Adding keys to table portfolio_instance_config
278 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
279 $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
281 /// Adding indexes to table portfolio_instance_config
282 $table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name'));
284 /// Conditionally launch create table for portfolio_instance_config
285 if (!$dbman->table_exists($table)) {
286 $dbman->create_table($table);
289 /// Define table portfolio_instance_user to be created
290 $table = new xmldb_table('portfolio_instance_user');
292 /// Adding fields to table portfolio_instance_user
293 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
294 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
295 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
296 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
297 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
299 /// Adding keys to table portfolio_instance_user
300 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
301 $table->add_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
302 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
304 /// Conditionally launch create table for portfolio_instance_user
305 if (!$dbman->table_exists($table)) {
306 $dbman->create_table($table);
309 /// Main savepoint reached
310 upgrade_main_savepoint(true, 2008070701);
313 if ($oldversion < 2008072400) {
314 /// Create the database tables for message_processors
315 $table = new xmldb_table('message_processors');
316 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
317 $table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null);
318 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
319 $dbman->create_table($table);
321 /// delete old and create new fields
322 $table = new xmldb_table('message');
323 $field = new xmldb_field('messagetype');
324 $dbman->drop_field($table, $field);
327 $field = new xmldb_field('message');
328 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
329 $dbman->rename_field($table, $field, 'fullmessage');
330 $field = new xmldb_field('format');
331 $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null);
332 $dbman->rename_field($table, $field, 'fullmessageformat');
334 /// new message fields
335 $field = new xmldb_field('subject');
336 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
337 $dbman->add_field($table, $field);
338 $field = new xmldb_field('fullmessagehtml');
339 $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null);
340 $dbman->add_field($table, $field);
341 $field = new xmldb_field('smallmessage');
342 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
343 $dbman->add_field($table, $field);
346 $table = new xmldb_table('message_read');
347 $field = new xmldb_field('messagetype');
348 $dbman->drop_field($table, $field);
349 $field = new xmldb_field('mailed');
350 $dbman->drop_field($table, $field);
353 $field = new xmldb_field('message');
354 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
355 $dbman->rename_field($table, $field, 'fullmessage');
356 $field = new xmldb_field('format');
357 $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null);
358 $dbman->rename_field($table, $field, 'fullmessageformat');
361 /// new message fields
362 $field = new xmldb_field('subject');
363 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
364 $dbman->add_field($table, $field);
365 $field = new xmldb_field('fullmessagehtml');
366 $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null);
367 $dbman->add_field($table, $field);
368 $field = new xmldb_field('smallmessage');
369 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
370 $dbman->add_field($table, $field);
373 $table = new xmldb_table('message_working');
374 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
375 $table->add_field('unreadmessageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
376 $table->add_field('processorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
377 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
378 $dbman->create_table($table);
381 upgrade_main_savepoint(true, 2008072400);
384 if ($oldversion < 2008072800) {
386 /// Define field enablecompletion to be added to course
387 $table = new xmldb_table('course');
388 $field = new xmldb_field('enablecompletion');
389 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'defaultrole');
391 /// Launch add field enablecompletion
392 if (!$dbman->field_exists($table,$field)) {
393 $dbman->add_field($table, $field);
396 /// Define field completion to be added to course_modules
397 $table = new xmldb_table('course_modules');
398 $field = new xmldb_field('completion');
399 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'groupmembersonly');
401 /// Launch add field completion
402 if (!$dbman->field_exists($table,$field)) {
403 $dbman->add_field($table, $field);
406 /// Define field completiongradeitemnumber to be added to course_modules
407 $field = new xmldb_field('completiongradeitemnumber');
408 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'completion');
410 /// Launch add field completiongradeitemnumber
411 if (!$dbman->field_exists($table,$field)) {
412 $dbman->add_field($table, $field);
415 /// Define field completionview to be added to course_modules
416 $field = new xmldb_field('completionview');
417 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completiongradeitemnumber');
419 /// Launch add field completionview
420 if (!$dbman->field_exists($table,$field)) {
421 $dbman->add_field($table, $field);
424 /// Define field completionexpected to be added to course_modules
425 $field = new xmldb_field('completionexpected');
426 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionview');
428 /// Launch add field completionexpected
429 if (!$dbman->field_exists($table,$field)) {
430 $dbman->add_field($table, $field);
433 /// Define table course_modules_completion to be created
434 $table = new xmldb_table('course_modules_completion');
435 if (!$dbman->table_exists($table)) {
437 /// Adding fields to table course_modules_completion
438 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
439 $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
440 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
441 $table->add_field('completionstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
442 $table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null);
443 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
445 /// Adding keys to table course_modules_completion
446 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
448 /// Adding indexes to table course_modules_completion
449 $table->add_index('coursemoduleid', XMLDB_INDEX_NOTUNIQUE, array('coursemoduleid'));
450 $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
452 /// Launch create table for course_modules_completion
453 $dbman->create_table($table);
456 /// Main savepoint reached
457 upgrade_main_savepoint(true, 2008072800);
460 if ($oldversion < 2008073000) {
462 /// Define table portfolio_log to be created
463 $table = new xmldb_table('portfolio_log');
465 /// Adding fields to table portfolio_log
466 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
467 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
468 $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
469 $table->add_field('portfolio', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
470 $table->add_field('caller_class', XMLDB_TYPE_CHAR, '150', null, XMLDB_NOTNULL, null, null);
471 $table->add_field('caller_file', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
472 $table->add_field('caller_sha1', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
473 $table->add_field('tempdataid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
474 $table->add_field('returnurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
475 $table->add_field('continueurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
477 /// Adding keys to table portfolio_log
478 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
479 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
480 $table->add_key('portfoliofk', XMLDB_KEY_FOREIGN, array('portfolio'), 'portfolio_instance', array('id'));
482 /// Conditionally launch create table for portfolio_log
483 if (!$dbman->table_exists($table)) {
484 $dbman->create_table($table);
487 /// Main savepoint reached
488 upgrade_main_savepoint(true, 2008073000);
491 if ($oldversion < 2008073104) {
492 /// Drop old table that might exist for some people
493 $table = new xmldb_table('message_providers');
494 if ($dbman->table_exists($table)) {
495 $dbman->drop_table($table);
498 /// Define table message_providers to be created
499 $table = new xmldb_table('message_providers');
501 /// Adding fields to table message_providers
502 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
503 $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
504 $table->add_field('component', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
505 $table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null);
507 /// Adding keys to table message_providers
508 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
510 /// Adding indexes to table message_providers
511 $table->add_index('componentname', XMLDB_INDEX_UNIQUE, array('component', 'name'));
513 /// Create table for message_providers
514 $dbman->create_table($table);
516 upgrade_main_savepoint(true, 2008073104);
519 if ($oldversion < 2008073111) {
520 /// Define table files to be created
521 $table = new xmldb_table('files');
523 /// Adding fields to table files
524 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
525 $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
526 $table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
527 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
528 $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
529 $table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
530 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
531 $table->add_field('filepath', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
532 $table->add_field('filename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
533 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
534 $table->add_field('filesize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
535 $table->add_field('mimetype', XMLDB_TYPE_CHAR, '100', null, null, null, null);
536 $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
537 $table->add_field('source', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
538 $table->add_field('author', XMLDB_TYPE_CHAR, '255', null, null, null, null);
539 $table->add_field('license', XMLDB_TYPE_CHAR, '255', null, null, null, null);
540 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
541 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
543 /// Adding keys to table files
544 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
545 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
546 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
548 /// Adding indexes to table files
549 $table->add_index('component-filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('component', 'filearea', 'contextid', 'itemid'));
550 $table->add_index('contenthash', XMLDB_INDEX_NOTUNIQUE, array('contenthash'));
551 $table->add_index('pathnamehash', XMLDB_INDEX_UNIQUE, array('pathnamehash'));
553 /// Conditionally launch create table for files
554 $dbman->create_table($table);
556 /// Main savepoint reached
557 upgrade_main_savepoint(true, 2008073111);
560 if ($oldversion < 2008073112) {
561 // Define field legacyfiles to be added to course
562 $table = new xmldb_table('course');
563 $field = new xmldb_field('legacyfiles', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'maxbytes');
565 // Launch add field legacyfiles
566 $dbman->add_field($table, $field);
567 // enable legacy files in all courses
568 $DB->execute("UPDATE {course} SET legacyfiles = 2");
570 // Main savepoint reached
571 upgrade_main_savepoint(true, 2008073112);
574 if ($oldversion < 2008073113) {
575 /// move all course, backup and other files to new filepool based storage
576 upgrade_migrate_files_courses();
577 /// Main savepoint reached
578 upgrade_main_savepoint(true, 2008073113);
581 if ($oldversion < 2008073114) {
582 /// move all course, backup and other files to new filepool based storage
583 upgrade_migrate_files_blog();
584 /// Main savepoint reached
585 upgrade_main_savepoint(true, 2008073114);
588 if ($oldversion < 2008080400) {
589 // Add field ssl_jump_url to mnet application, and populate existing default applications
590 $table = new xmldb_table('mnet_application');
591 $field = new xmldb_field('sso_jump_url');
592 if (!$dbman->field_exists($table, $field)) {
593 $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
594 $dbman->add_field($table, $field);
595 $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle'));
596 $DB->set_field('mnet_application', 'sso_jump_url', '/auth/xmlrpc/jump.php', array('name' => 'mahara'));
599 /// Main savepoint reached
600 upgrade_main_savepoint(true, 2008080400);
603 if ($oldversion < 2008080500) {
605 /// Define table portfolio_tempdata to be created
606 $table = new xmldb_table('portfolio_tempdata');
608 /// Adding fields to table portfolio_tempdata
609 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
610 $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
611 $table->add_field('expirytime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
612 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
613 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', null, null, null, '0');
615 /// Adding keys to table portfolio_tempdata
616 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
617 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
618 $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
620 /// Conditionally launch create table for portfolio_tempdata
621 if (!$dbman->table_exists($table)) {
622 $dbman->create_table($table);
625 /// Main savepoint reached
626 upgrade_main_savepoint(true, 2008080500);
629 if ($oldversion < 2008081500) {
630 /// Changing the type of all the columns that the question bank uses to store grades to be NUMBER(12, 7).
631 $table = new xmldb_table('question');
632 $field = new xmldb_field('defaultgrade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'generalfeedback');
633 $dbman->change_field_type($table, $field);
634 upgrade_main_savepoint(true, 2008081500);
637 if ($oldversion < 2008081501) {
638 $table = new xmldb_table('question');
639 $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'defaultgrade');
640 $dbman->change_field_type($table, $field);
641 upgrade_main_savepoint(true, 2008081501);
644 if ($oldversion < 2008081502) {
645 $table = new xmldb_table('question_answers');
646 $field = new xmldb_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'answer');
647 $dbman->change_field_type($table, $field);
648 upgrade_main_savepoint(true, 2008081502);
651 if ($oldversion < 2008081503) {
652 $table = new xmldb_table('question_sessions');
653 $field = new xmldb_field('sumpenalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'newgraded');
654 $dbman->change_field_type($table, $field);
655 upgrade_main_savepoint(true, 2008081503);
658 if ($oldversion < 2008081504) {
659 $table = new xmldb_table('question_states');
660 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'event');
661 $dbman->change_field_type($table, $field);
662 upgrade_main_savepoint(true, 2008081504);
665 if ($oldversion < 2008081505) {
666 $table = new xmldb_table('question_states');
667 $field = new xmldb_field('raw_grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'grade');
668 $dbman->change_field_type($table, $field);
669 upgrade_main_savepoint(true, 2008081505);
672 if ($oldversion < 2008081506) {
673 $table = new xmldb_table('question_states');
674 $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'raw_grade');
675 $dbman->change_field_type($table, $field);
676 upgrade_main_savepoint(true, 2008081506);
679 if ($oldversion < 2008081600) {
681 /// all 1.9 sites and fresh installs must already be unicode, not needed anymore
682 unset_config('unicodedb');
684 /// Main savepoint reached
685 upgrade_main_savepoint(true, 2008081600);
688 if ($oldversion < 2008082602) {
690 /// Define table repository to be dropped
691 $table = new xmldb_table('repository');
693 /// Conditionally launch drop table for repository
694 if ($dbman->table_exists($table)) {
695 $dbman->drop_table($table);
698 /// Define table repository to be created
699 $table = new xmldb_table('repository');
701 /// Adding fields to table repository
702 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
703 $table->add_field('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
704 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '1');
705 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
707 /// Adding keys to table repository
708 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
710 /// Conditionally launch create table for repository
711 if (!$dbman->table_exists($table)) {
712 $dbman->create_table($table);
715 /// Define table repository_instances to be created
716 $table = new xmldb_table('repository_instances');
718 /// Adding fields to table repository_instances
719 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
720 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
721 $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
722 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
723 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
724 $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null);
725 $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null);
726 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
727 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
728 $table->add_field('readonly', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
730 /// Adding keys to table repository_instances
731 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
733 /// Conditionally launch create table for repository_instances
734 if (!$dbman->table_exists($table)) {
735 $dbman->create_table($table);
738 /// Define table repository_instance_config to be created
739 $table = new xmldb_table('repository_instance_config');
741 /// Adding fields to table repository_instance_config
742 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
743 $table->add_field('instanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
744 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
745 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
747 /// Adding keys to table repository_instance_config
748 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
750 /// Conditionally launch create table for repository_instance_config
751 if (!$dbman->table_exists($table)) {
752 $dbman->create_table($table);
755 /// Main savepoint reached
756 upgrade_main_savepoint(true, 2008082602);
759 if ($oldversion < 2008082700) {
760 /// Add a new column to the question sessions table to record whether a
761 /// question has been flagged.
763 /// Define field flagged to be added to question_sessions
764 $table = new xmldb_table('question_sessions');
765 $field = new xmldb_field('flagged', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'manualcomment');
767 /// Conditionally launch add field flagged
768 if (!$dbman->field_exists($table, $field)) {
769 $dbman->add_field($table, $field);
772 /// Main savepoint reached
773 upgrade_main_savepoint(true, 2008082700);
776 if ($oldversion < 2008082900) {
778 /// Changing precision of field parent_type on table mnet_rpc to (20)
779 $table = new xmldb_table('mnet_rpc');
780 $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path');
782 /// Launch change of precision for field parent_type
783 $dbman->change_field_precision($table, $field);
785 /// Main savepoint reached
786 upgrade_main_savepoint(true, 2008082900);
789 // MDL-16411 Move all plugintype_pluginname_version values from config to config_plugins.
790 if ($oldversion < 2008091000) {
791 foreach (get_object_vars($CFG) as $name => $value) {
792 if (substr($name, strlen($name) - 8) !== '_version') {
795 $pluginname = substr($name, 0, strlen($name) - 8);
796 if (!strpos($pluginname, '_')) {
797 // Skip things like backup_version that don't contain an extra _
800 if ($pluginname == 'enrol_ldap_version') {
801 // Special case - this is something different from a plugin version number.
804 if (!preg_match('/^\d{10}$/', $value)) {
805 // Extra safety check, skip anything that does not look like a Moodle
806 // version number (10 digits).
809 set_config('version', $value, $pluginname);
812 upgrade_main_savepoint(true, 2008091000);
815 if ($oldversion < 2008092300) {
816 unset_config('editorspelling');
817 unset_config('editordictionary');
818 /// Main savepoint reached
819 upgrade_main_savepoint(true, 2008092300);
822 if ($oldversion < 2008101300) {
824 if (!get_config(NULL, 'statsruntimedays')) {
825 set_config('statsruntimedays', '31');
828 /// Main savepoint reached
829 upgrade_main_savepoint(true, 2008101300);
832 /// Drop the deprecated teacher, teachers, student and students columns from the course table.
833 if ($oldversion < 2008111200) {
834 $table = new xmldb_table('course');
836 /// Conditionally launch drop field teacher
837 $field = new xmldb_field('teacher');
838 if ($dbman->field_exists($table, $field)) {
839 $dbman->drop_field($table, $field);
842 /// Conditionally launch drop field teacher
843 $field = new xmldb_field('teachers');
844 if ($dbman->field_exists($table, $field)) {
845 $dbman->drop_field($table, $field);
848 /// Conditionally launch drop field teacher
849 $field = new xmldb_field('student');
850 if ($dbman->field_exists($table, $field)) {
851 $dbman->drop_field($table, $field);
854 /// Conditionally launch drop field teacher
855 $field = new xmldb_field('students');
856 if ($dbman->field_exists($table, $field)) {
857 $dbman->drop_field($table, $field);
860 /// Main savepoint reached
861 upgrade_main_savepoint(true, 2008111200);
864 /// Add a unique index to the role.name column.
865 if ($oldversion < 2008111800) {
867 /// Define index name (unique) to be added to role
868 $table = new xmldb_table('role');
869 $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name'));
871 /// Conditionally launch add index name
872 if (!$dbman->index_exists($table, $index)) {
873 $dbman->add_index($table, $index);
876 /// Main savepoint reached
877 upgrade_main_savepoint(true, 2008111800);
880 /// Add a unique index to the role.shortname column.
881 if ($oldversion < 2008111801) {
883 /// Define index shortname (unique) to be added to role
884 $table = new xmldb_table('role');
885 $index = new xmldb_index('shortname', XMLDB_INDEX_UNIQUE, array('shortname'));
887 /// Conditionally launch add index shortname
888 if (!$dbman->index_exists($table, $index)) {
889 $dbman->add_index($table, $index);
892 /// Main savepoint reached
893 upgrade_main_savepoint(true, 2008111801);
896 if ($oldversion < 2008120700) {
898 /// Changing precision of field shortname on table course_request to (100)
899 $table = new xmldb_table('course_request');
900 $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname');
902 /// Before changing the field, drop dependent indexes
903 /// Define index shortname (not unique) to be dropped form course_request
904 $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname'));
905 /// Conditionally launch drop index shortname
906 if ($dbman->index_exists($table, $index)) {
907 $dbman->drop_index($table, $index);
910 /// Launch change of precision for field shortname
911 $dbman->change_field_precision($table, $field);
913 /// After changing the field, recreate dependent indexes
914 /// Define index shortname (not unique) to be added to course_request
915 $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname'));
916 /// Conditionally launch add index shortname
917 if (!$dbman->index_exists($table, $index)) {
918 $dbman->add_index($table, $index);
921 /// Main savepoint reached
922 upgrade_main_savepoint(true, 2008120700);
925 if ($oldversion < 2008120801) {
927 /// Changing precision of field shortname on table mnet_enrol_course to (100)
928 $table = new xmldb_table('mnet_enrol_course');
929 $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname');
931 /// Launch change of precision for field shortname
932 $dbman->change_field_precision($table, $field);
934 /// Main savepoint reached
935 upgrade_main_savepoint(true, 2008120801);
938 if ($oldversion < 2008121701) {
940 /// Define field availablefrom to be added to course_modules
941 $table = new xmldb_table('course_modules');
942 $field = new xmldb_field('availablefrom', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionexpected');
944 /// Conditionally launch add field availablefrom
945 if (!$dbman->field_exists($table, $field)) {
946 $dbman->add_field($table, $field);
949 /// Define field availableuntil to be added to course_modules
950 $field = new xmldb_field('availableuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availablefrom');
952 /// Conditionally launch add field availableuntil
953 if (!$dbman->field_exists($table, $field)) {
954 $dbman->add_field($table, $field);
957 /// Define field showavailability to be added to course_modules
958 $field = new xmldb_field('showavailability', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availableuntil');
960 /// Conditionally launch add field showavailability
961 if (!$dbman->field_exists($table, $field)) {
962 $dbman->add_field($table, $field);
965 /// Define table course_modules_availability to be created
966 $table = new xmldb_table('course_modules_availability');
968 /// Adding fields to table course_modules_availability
969 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
970 $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
971 $table->add_field('sourcecmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
972 $table->add_field('requiredcompletion', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null);
973 $table->add_field('gradeitemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
974 $table->add_field('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
975 $table->add_field('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
977 /// Adding keys to table course_modules_availability
978 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
979 $table->add_key('coursemoduleid', XMLDB_KEY_FOREIGN, array('coursemoduleid'), 'course_modules', array('id'));
980 $table->add_key('sourcecmid', XMLDB_KEY_FOREIGN, array('sourcecmid'), 'course_modules', array('id'));
981 $table->add_key('gradeitemid', XMLDB_KEY_FOREIGN, array('gradeitemid'), 'grade_items', array('id'));
983 /// Conditionally launch create table for course_modules_availability
984 if (!$dbman->table_exists($table)) {
985 $dbman->create_table($table);
988 /// Changes to modinfo mean we need to rebuild course cache
989 require_once($CFG->dirroot . '/course/lib.php');
990 rebuild_course_cache(0, true);
992 /// Main savepoint reached
993 upgrade_main_savepoint(true, 2008121701);
996 if ($oldversion < 2009010500) {
997 /// clean up config table a bit
998 unset_config('session_error_counter');
1000 /// Main savepoint reached
1001 upgrade_main_savepoint(true, 2009010500);
1004 if ($oldversion < 2009010600) {
1006 /// Define field originalquestion to be dropped from question_states
1007 $table = new xmldb_table('question_states');
1008 $field = new xmldb_field('originalquestion');
1010 /// Conditionally launch drop field originalquestion
1011 if ($dbman->field_exists($table, $field)) {
1012 $dbman->drop_field($table, $field);
1015 /// Main savepoint reached
1016 upgrade_main_savepoint(true, 2009010600);
1019 if ($oldversion < 2009010601) {
1021 /// Changing precision of field ip on table log to (45)
1022 $table = new xmldb_table('log');
1023 $field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'userid');
1025 /// Launch change of precision for field ip
1026 $dbman->change_field_precision($table, $field);
1028 /// Main savepoint reached
1029 upgrade_main_savepoint(true, 2009010601);
1032 if ($oldversion < 2009010602) {
1034 /// Changing precision of field lastip on table user to (45)
1035 $table = new xmldb_table('user');
1036 $field = new xmldb_field('lastip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'currentlogin');
1038 /// Launch change of precision for field lastip
1039 $dbman->change_field_precision($table, $field);
1041 /// Main savepoint reached
1042 upgrade_main_savepoint(true, 2009010602);
1045 if ($oldversion < 2009010603) {
1047 /// Changing precision of field ip_address on table mnet_host to (45)
1048 $table = new xmldb_table('mnet_host');
1049 $field = new xmldb_field('ip_address', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'wwwroot');
1051 /// Launch change of precision for field ip_address
1052 $dbman->change_field_precision($table, $field);
1054 /// Main savepoint reached
1055 upgrade_main_savepoint(true, 2009010603);
1058 if ($oldversion < 2009010604) {
1060 /// Changing precision of field ip on table mnet_log to (45)
1061 $table = new xmldb_table('mnet_log');
1062 $field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'userid');
1064 /// Launch change of precision for field ip
1065 $dbman->change_field_precision($table, $field);
1067 /// Main savepoint reached
1068 upgrade_main_savepoint(true, 2009010604);
1071 if ($oldversion < 2009011000) {
1073 /// Changing nullability of field configdata on table block_instance to null
1074 $table = new xmldb_table('block_instance');
1075 $field = new xmldb_field('configdata');
1076 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'visible');
1078 /// Launch change of nullability for field configdata
1079 $dbman->change_field_notnull($table, $field);
1081 /// Main savepoint reached
1082 upgrade_main_savepoint(true, 2009011000);
1085 if ($oldversion < 2009011100) {
1086 /// Remove unused settings
1087 unset_config('zip');
1088 unset_config('unzip');
1089 unset_config('adminblocks_initialised');
1091 /// Main savepoint reached
1092 upgrade_main_savepoint(true, 2009011100);
1095 if ($oldversion < 2009011101) {
1096 /// Migrate backup settings to core plugin config table
1097 $configs = $DB->get_records('backup_config');
1098 foreach ($configs as $config) {
1099 set_config($config->name, $config->value, 'backup');
1102 /// Define table to be dropped
1103 $table = new xmldb_table('backup_config');
1105 /// Launch drop table for old backup config
1106 $dbman->drop_table($table);
1108 /// Main savepoint reached
1109 upgrade_main_savepoint(true, 2009011101);
1112 if ($oldversion < 2009011303) {
1114 /// Define table config_log to be created
1115 $table = new xmldb_table('config_log');
1117 /// Adding fields to table config_log
1118 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1119 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1120 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1121 $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null);
1122 $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
1123 $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
1124 $table->add_field('oldvalue', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
1126 /// Adding keys to table config_log
1127 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1128 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1130 /// Adding indexes to table config_log
1131 $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
1133 /// Launch create table for config_log
1134 $dbman->create_table($table);
1136 /// Main savepoint reached
1137 upgrade_main_savepoint(true, 2009011303);
1140 if ($oldversion < 2009011900) {
1142 /// Define table sessions2 to be dropped
1143 $table = new xmldb_table('sessions2');
1145 /// Conditionally launch drop table for sessions
1146 if ($dbman->table_exists($table)) {
1147 $dbman->drop_table($table);
1150 /// Define table sessions to be dropped
1151 $table = new xmldb_table('sessions');
1153 /// Conditionally launch drop table for sessions
1154 if ($dbman->table_exists($table)) {
1155 $dbman->drop_table($table);
1158 /// Define table sessions to be created
1159 $table = new xmldb_table('sessions');
1161 /// Adding fields to table sessions
1162 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1163 $table->add_field('state', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
1164 $table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null);
1165 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1166 $table->add_field('sessdata', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
1167 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1168 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1169 $table->add_field('firstip', XMLDB_TYPE_CHAR, '45', null, null, null, null);
1170 $table->add_field('lastip', XMLDB_TYPE_CHAR, '45', null, null, null, null);
1172 /// Adding keys to table sessions
1173 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1174 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1176 /// Adding indexes to table sessions
1177 $table->add_index('state', XMLDB_INDEX_NOTUNIQUE, array('state'));
1178 $table->add_index('sid', XMLDB_INDEX_UNIQUE, array('sid'));
1179 $table->add_index('timecreated', XMLDB_INDEX_NOTUNIQUE, array('timecreated'));
1180 $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
1182 /// Launch create table for sessions
1183 $dbman->create_table($table);
1185 /// Main savepoint reached
1186 upgrade_main_savepoint(true, 2009011900);
1189 if ($oldversion < 2009021800) {
1190 // Converting format of grade conditions, if any exist, to percentages.
1192 UPDATE {course_modules_availability} SET grademin=(
1193 SELECT 100.0*({course_modules_availability}.grademin-gi.grademin)
1194 /(gi.grademax-gi.grademin)
1195 FROM {grade_items} gi
1196 WHERE gi.id={course_modules_availability}.gradeitemid)
1197 WHERE gradeitemid IS NOT NULL AND grademin IS NOT NULL");
1199 UPDATE {course_modules_availability} SET grademax=(
1200 SELECT 100.0*({course_modules_availability}.grademax-gi.grademin)
1201 /(gi.grademax-gi.grademin)
1202 FROM {grade_items} gi
1203 WHERE gi.id={course_modules_availability}.gradeitemid)
1204 WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
1206 /// Main savepoint reached
1207 upgrade_main_savepoint(true, 2009021800);
1210 if ($oldversion < 2009021801) {
1211 /// Define field backuptype to be added to backup_log
1212 $table = new xmldb_table('backup_log');
1213 $field = new xmldb_field('backuptype', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, 'info');
1214 /// Conditionally Launch add field backuptype and set all old records as 'scheduledbackup' records.
1215 if (!$dbman->field_exists($table, $field)) {
1216 $dbman->add_field($table, $field);
1217 $DB->execute("UPDATE {backup_log} SET backuptype='scheduledbackup'");
1220 /// Main savepoint reached
1221 upgrade_main_savepoint(true, 2009021801);
1224 /// Add default sort order for question types.
1225 if ($oldversion < 2009030300) {
1226 set_config('multichoice_sortorder', 1, 'question');
1227 set_config('truefalse_sortorder', 2, 'question');
1228 set_config('shortanswer_sortorder', 3, 'question');
1229 set_config('numerical_sortorder', 4, 'question');
1230 set_config('calculated_sortorder', 5, 'question');
1231 set_config('essay_sortorder', 6, 'question');
1232 set_config('match_sortorder', 7, 'question');
1233 set_config('randomsamatch_sortorder', 8, 'question');
1234 set_config('multianswer_sortorder', 9, 'question');
1235 set_config('description_sortorder', 10, 'question');
1236 set_config('random_sortorder', 11, 'question');
1237 set_config('missingtype_sortorder', 12, 'question');
1239 upgrade_main_savepoint(true, 2009030300);
1242 /// MDL-18132 replace the use a new Role allow switch settings page, instead of
1243 /// $CFG->allowuserswitchrolestheycantassign
1244 if ($oldversion < 2009032000) {
1245 /// First create the new table.
1246 $table = new xmldb_table('role_allow_switch');
1248 /// Adding fields to table role_allow_switch
1249 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1250 $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1251 $table->add_field('allowswitch', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1253 /// Adding keys to table role_allow_switch
1254 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1255 $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
1256 $table->add_key('allowswitch', XMLDB_KEY_FOREIGN, array('allowswitch'), 'role', array('id'));
1258 /// Adding indexes to table role_allow_switch
1259 $table->add_index('roleid-allowoverride', XMLDB_INDEX_UNIQUE, array('roleid', 'allowswitch'));
1261 /// Conditionally launch create table for role_allow_switch
1262 if (!$dbman->table_exists($table)) {
1263 $dbman->create_table($table);
1266 /// Main savepoint reached
1267 upgrade_main_savepoint(true, 2009032000);
1270 if ($oldversion < 2009032001) {
1271 /// Copy from role_allow_assign into the new table.
1272 $DB->execute('INSERT INTO {role_allow_switch} (roleid, allowswitch)
1273 SELECT roleid, allowassign FROM {role_allow_assign}');
1275 /// Unset the config variable used in 1.9.
1276 unset_config('allowuserswitchrolestheycantassign');
1278 /// Main savepoint reached
1279 upgrade_main_savepoint(true, 2009032001);
1282 if ($oldversion < 2009033100) {
1283 require_once("$CFG->dirroot/filter/tex/lib.php");
1284 filter_tex_updatedcallback(null);
1285 /// Main savepoint reached
1286 upgrade_main_savepoint(true, 2009033100);
1289 if ($oldversion < 2009040300) {
1291 /// Define table filter_active to be created
1292 $table = new xmldb_table('filter_active');
1294 /// Adding fields to table filter_active
1295 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1296 $table->add_field('filter', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
1297 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1298 $table->add_field('active', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null);
1299 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
1301 /// Adding keys to table filter_active
1302 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1303 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
1305 /// Adding indexes to table filter_active
1306 $table->add_index('contextid-filter', XMLDB_INDEX_UNIQUE, array('contextid', 'filter'));
1308 /// Conditionally launch create table for filter_active
1309 if (!$dbman->table_exists($table)) {
1310 $dbman->create_table($table);
1313 /// Main savepoint reached
1314 upgrade_main_savepoint(true, 2009040300);
1317 if ($oldversion < 2009040301) {
1319 /// Define table filter_config to be created
1320 $table = new xmldb_table('filter_config');
1322 /// Adding fields to table filter_config
1323 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1324 $table->add_field('filter', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
1325 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1326 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
1327 $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
1329 /// Adding keys to table filter_config
1330 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1331 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
1333 /// Adding indexes to table filter_config
1334 $table->add_index('contextid-filter-name', XMLDB_INDEX_UNIQUE, array('contextid', 'filter', 'name'));
1336 /// Conditionally launch create table for filter_config
1337 if (!$dbman->table_exists($table)) {
1338 $dbman->create_table($table);
1341 /// Main savepoint reached
1342 upgrade_main_savepoint(true, 2009040301);
1345 if ($oldversion < 2009040302) {
1346 /// Transfer current settings from $CFG->textfilters
1347 $disabledfilters = filter_get_all_installed();
1348 if (empty($CFG->textfilters)) {
1349 $activefilters = array();
1351 $activefilters = explode(',', $CFG->textfilters);
1353 $syscontext = get_context_instance(CONTEXT_SYSTEM);
1355 foreach ($activefilters as $filter) {
1356 filter_set_global_state($filter, TEXTFILTER_ON, $sortorder);
1358 unset($disabledfilters[$filter]);
1360 foreach ($disabledfilters as $filter => $notused) {
1361 filter_set_global_state($filter, TEXTFILTER_DISABLED, $sortorder);
1365 /// Main savepoint reached
1366 upgrade_main_savepoint(true, 2009040302);
1369 if ($oldversion < 2009040600) {
1370 /// Ensure that $CFG->stringfilters is set.
1371 if (empty($CFG->stringfilters)) {
1372 if (!empty($CFG->filterall)) {
1373 set_config('stringfilters', $CFG->textfilters);
1375 set_config('stringfilters', '');
1379 set_config('filterall', !empty($CFG->stringfilters));
1380 unset_config('textfilters');
1382 /// Main savepoint reached
1383 upgrade_main_savepoint(true, 2009040600);
1386 if ($oldversion < 2009041700) {
1387 /// To ensure the UI remains consistent with no behaviour change, any
1388 /// 'until' date in an activity condition should have 1 second subtracted
1389 /// (to go from 0:00 on the following day to 23:59 on the previous one).
1390 $DB->execute('UPDATE {course_modules} SET availableuntil = availableuntil - 1 WHERE availableuntil <> 0');
1391 require_once($CFG->dirroot . '/course/lib.php');
1392 rebuild_course_cache(0, true);
1394 /// Main savepoint reached
1395 upgrade_main_savepoint(true, 2009041700);
1398 if ($oldversion < 2009042600) {
1399 /// Deleting orphaned messages from deleted users.
1400 require_once($CFG->dirroot.'/message/lib.php');
1401 /// Detect deleted users with messages sent(useridfrom) and not read
1402 if ($deletedusers = $DB->get_records_sql('SELECT DISTINCT u.id
1404 JOIN {message} m ON m.useridfrom = u.id
1405 WHERE u.deleted = ?', array(1))) {
1406 foreach ($deletedusers as $deleteduser) {
1407 message_move_userfrom_unread2read($deleteduser->id); // move messages
1410 /// Main savepoint reached
1411 upgrade_main_savepoint(true, 2009042600);
1414 /// Dropping all enums/check contraints from core. MDL-18577
1415 if ($oldversion < 2009042700) {
1417 /// Changing list of values (enum) of field stattype on table stats_daily to none
1418 $table = new xmldb_table('stats_daily');
1419 $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
1421 /// Launch change of list of values for field stattype
1422 $dbman->drop_enum_from_field($table, $field);
1424 /// Changing list of values (enum) of field stattype on table stats_weekly to none
1425 $table = new xmldb_table('stats_weekly');
1426 $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
1428 /// Launch change of list of values for field stattype
1429 $dbman->drop_enum_from_field($table, $field);
1431 /// Changing list of values (enum) of field stattype on table stats_monthly to none
1432 $table = new xmldb_table('stats_monthly');
1433 $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
1435 /// Launch change of list of values for field stattype
1436 $dbman->drop_enum_from_field($table, $field);
1438 /// Changing list of values (enum) of field publishstate on table post to none
1439 $table = new xmldb_table('post');
1440 $field = new xmldb_field('publishstate', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'draft', 'attachment');
1442 /// Launch change of list of values for field publishstate
1443 $dbman->drop_enum_from_field($table, $field);
1445 /// Main savepoint reached
1446 upgrade_main_savepoint(true, 2009042700);
1449 if ($oldversion < 2009043000) {
1450 unset_config('grade_report_showgroups');
1451 upgrade_main_savepoint(true, 2009043000);
1454 if ($oldversion < 2009050600) {
1455 /// Site front page blocks need to be moved due to page name change.
1456 $DB->set_field('block_instance', 'pagetype', 'site-index', array('pagetype' => 'course-view', 'pageid' => SITEID));
1458 /// Main savepoint reached
1459 upgrade_main_savepoint(true, 2009050600);
1462 if ($oldversion < 2009050601) {
1464 /// Define table block_instance to be renamed to block_instances
1465 $table = new xmldb_table('block_instance');
1467 /// Launch rename table for block_instance
1468 $dbman->rename_table($table, 'block_instances');
1470 /// Main savepoint reached
1471 upgrade_main_savepoint(true, 2009050601);
1474 if ($oldversion < 2009050602) {
1476 /// Define table block_instance to be renamed to block_instance_old
1477 $table = new xmldb_table('block_pinned');
1479 /// Launch rename table for block_instance
1480 $dbman->rename_table($table, 'block_pinned_old');
1482 /// Main savepoint reached
1483 upgrade_main_savepoint(true, 2009050602);
1486 if ($oldversion < 2009050603) {
1488 /// Define table block_instance_old to be created
1489 $table = new xmldb_table('block_instance_old');
1491 /// Adding fields to table block_instance_old
1492 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1493 $table->add_field('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1494 $table->add_field('blockid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
1495 $table->add_field('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
1496 $table->add_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null);
1497 $table->add_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null);
1498 $table->add_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0');
1499 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
1500 $table->add_field('configdata', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
1502 /// Adding keys to table block_instance_old
1503 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1504 $table->add_key('blockid', XMLDB_KEY_FOREIGN, array('blockid'), 'block', array('id'));
1506 /// Adding indexes to table block_instance_old
1507 $table->add_index('pageid', XMLDB_INDEX_NOTUNIQUE, array('pageid'));
1508 $table->add_index('pagetype', XMLDB_INDEX_NOTUNIQUE, array('pagetype'));
1510 /// Conditionally launch create table for block_instance_old
1511 if (!$dbman->table_exists($table)) {
1512 $dbman->create_table($table);
1515 /// Main savepoint reached
1516 upgrade_main_savepoint(true, 2009050603);
1519 if ($oldversion < 2009050604) {
1520 /// Copy current blocks data from block_instances to block_instance_old
1521 $DB->execute('INSERT INTO {block_instance_old} (oldid, blockid, pageid, pagetype, position, weight, visible, configdata)
1522 SELECT id, blockid, pageid, pagetype, position, weight, visible, configdata FROM {block_instances} ORDER BY id');
1524 upgrade_main_savepoint(true, 2009050604);
1527 if ($oldversion < 2009050605) {
1529 /// Define field multiple to be dropped from block
1530 $table = new xmldb_table('block');
1531 $field = new xmldb_field('multiple');
1533 /// Conditionally launch drop field multiple
1534 if ($dbman->field_exists($table, $field)) {
1535 $dbman->drop_field($table, $field);
1538 /// Main savepoint reached
1539 upgrade_main_savepoint(true, 2009050605);
1542 if ($oldversion < 2009050606) {
1543 $table = new xmldb_table('block_instances');
1545 /// Rename field weight on table block_instances to defaultweight
1546 $field = new xmldb_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0', 'position');
1547 $dbman->rename_field($table, $field, 'defaultweight');
1549 /// Rename field position on table block_instances to defaultregion
1550 $field = new xmldb_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, 'pagetype');
1551 $dbman->rename_field($table, $field, 'defaultregion');
1553 /// Main savepoint reached
1554 upgrade_main_savepoint(true, 2009050606);
1557 if ($oldversion < 2009050607) {
1558 /// Changing precision of field defaultregion on table block_instances to (16)
1559 $table = new xmldb_table('block_instances');
1560 $field = new xmldb_field('defaultregion', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, 'pagetype');
1562 /// Launch change of precision for field defaultregion
1563 $dbman->change_field_precision($table, $field);
1565 /// Main savepoint reached
1566 upgrade_main_savepoint(true, 2009050607);
1569 if ($oldversion < 2009050608) {
1570 /// Change regions to the new notation
1571 $DB->set_field('block_instances', 'defaultregion', 'side-pre', array('defaultregion' => 'l'));
1572 $DB->set_field('block_instances', 'defaultregion', 'side-post', array('defaultregion' => 'r'));
1573 $DB->set_field('block_instances', 'defaultregion', 'course-view-top', array('defaultregion' => 'c'));
1574 // This third one is a custom value from contrib/patches/center_blocks_position_patch and the
1575 // flex page course format. Hopefully this new value is an adequate alternative.
1577 /// Main savepoint reached
1578 upgrade_main_savepoint(true, 2009050608);
1581 if ($oldversion < 2009050609) {
1583 /// Define key blockname (unique) to be added to block
1584 $table = new xmldb_table('block');
1585 $key = new xmldb_key('blockname', XMLDB_KEY_UNIQUE, array('name'));
1587 /// Launch add key blockname
1588 $dbman->add_key($table, $key);
1590 /// Main savepoint reached
1591 upgrade_main_savepoint(true, 2009050609);
1594 if ($oldversion < 2009050610) {
1595 $table = new xmldb_table('block_instances');
1597 /// Define field blockname to be added to block_instances
1598 $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, null, null, null, 'blockid');
1599 if (!$dbman->field_exists($table, $field)) {
1600 $dbman->add_field($table, $field);
1603 /// Define field contextid to be added to block_instances
1604 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'blockname');
1605 if (!$dbman->field_exists($table, $field)) {
1606 $dbman->add_field($table, $field);
1609 /// Define field showinsubcontexts to be added to block_instances
1610 $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, null, null, null, 'contextid');
1611 if (!$dbman->field_exists($table, $field)) {
1612 $dbman->add_field($table, $field);
1615 /// Define field subpagepattern to be added to block_instances
1616 $field = new xmldb_field('subpagepattern', XMLDB_TYPE_CHAR, '16', null, null, null, null, 'pagetype');
1617 if (!$dbman->field_exists($table, $field)) {
1618 $dbman->add_field($table, $field);
1621 /// Main savepoint reached
1622 upgrade_main_savepoint(true, 2009050610);
1625 if ($oldversion < 2009050611) {
1626 $table = new xmldb_table('block_instances');
1628 /// Fill in blockname from blockid
1629 $DB->execute("UPDATE {block_instances} SET blockname = (SELECT name FROM {block} WHERE id = blockid)");
1631 /// Set showinsubcontexts = 0 for all rows.
1632 $DB->execute("UPDATE {block_instances} SET showinsubcontexts = 0");
1634 /// Main savepoint reached
1635 upgrade_main_savepoint(true, 2009050611);
1638 if ($oldversion < 2009050612) {
1640 /// Rename field pagetype on table block_instances to pagetypepattern
1641 $table = new xmldb_table('block_instances');
1642 $field = new xmldb_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'pageid');
1644 /// Launch rename field pagetype
1645 $dbman->rename_field($table, $field, 'pagetypepattern');
1647 /// Main savepoint reached
1648 upgrade_main_savepoint(true, 2009050612);
1651 if ($oldversion < 2009050613) {
1652 /// fill in contextid and subpage, and update pagetypepattern from pagetype and pageid
1655 $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
1656 $DB->execute("UPDATE {block_instances} SET contextid = " . $frontpagecontext->id . ",
1657 pagetypepattern = 'site-index',
1658 subpagepattern = NULL
1659 WHERE pagetypepattern = 'site-index'");
1662 $DB->execute("UPDATE {block_instances} SET
1666 JOIN {course} ON instanceid = {course}.id AND contextlevel = " . CONTEXT_COURSE . "
1667 WHERE {course}.id = pageid
1669 pagetypepattern = 'course-view-*',
1670 subpagepattern = NULL
1671 WHERE pagetypepattern = 'course-view'");
1674 $syscontext = get_context_instance(CONTEXT_SYSTEM);
1675 $DB->execute("UPDATE {block_instances} SET
1676 contextid = " . $syscontext->id . ",
1677 pagetypepattern = 'admin-*',
1678 subpagepattern = NULL
1679 WHERE pagetypepattern = 'admin'");
1682 $DB->execute("UPDATE {block_instances} SET
1686 JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . "
1687 WHERE {user}.id = pageid
1689 pagetypepattern = 'my-index',
1690 subpagepattern = NULL
1691 WHERE pagetypepattern = 'my-index'");
1694 $DB->execute("UPDATE {block_instances} SET
1695 contextid = " . $syscontext->id . ",
1696 pagetypepattern = 'tag-index',
1697 subpagepattern = pageid
1698 WHERE pagetypepattern = 'tag-index'");
1701 $DB->execute("UPDATE {block_instances} SET
1705 JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . "
1706 WHERE {user}.id = pageid
1708 pagetypepattern = 'blog-index',
1709 subpagepattern = NULL
1710 WHERE pagetypepattern = 'blog-view'");
1713 $moduleswithblocks = array('chat', 'data', 'lesson', 'quiz', 'dimdim', 'game', 'wiki', 'oublog');
1714 foreach ($moduleswithblocks as $modname) {
1715 if (!$dbman->table_exists($modname)) {
1718 $DB->execute("UPDATE {block_instances} SET
1722 JOIN {course_modules} ON instanceid = {course_modules}.id AND contextlevel = " . CONTEXT_MODULE . "
1723 JOIN {modules} ON {modules}.id = {course_modules}.module AND {modules}.name = '$modname'
1724 JOIN {{$modname}} ON {course_modules}.instance = {{$modname}}.id
1725 WHERE {{$modname}}.id = pageid
1727 pagetypepattern = 'blog-index',
1728 subpagepattern = NULL
1729 WHERE pagetypepattern = 'blog-view'");
1732 /// Main savepoint reached
1733 upgrade_main_savepoint(true, 2009050613);
1736 if ($oldversion < 2009050614) {
1737 /// fill in any missing contextids with a dummy value, so we can add the not-null constraint.
1738 $DB->execute("UPDATE {block_instances} SET contextid = 0 WHERE contextid IS NULL");
1740 /// Main savepoint reached
1741 upgrade_main_savepoint(true, 2009050614);
1744 if ($oldversion < 2009050615) {
1745 $table = new xmldb_table('block_instances');
1747 /// Arrived here, any block_instances record without blockname is one
1748 /// orphan block coming from 1.9. Just delete them. MDL-22503
1749 $DB->delete_records_select('block_instances', 'blockname IS NULL');
1751 /// Changing nullability of field blockname on table block_instances to not null
1752 $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'id');
1753 $dbman->change_field_notnull($table, $field);
1755 /// Changing nullability of field contextid on table block_instances to not null
1756 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'blockname');
1757 $dbman->change_field_notnull($table, $field);
1759 /// Changing nullability of field showinsubcontexts on table block_instances to not null
1760 $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, 'contextid');
1761 $dbman->change_field_notnull($table, $field);
1763 /// Main savepoint reached
1764 upgrade_main_savepoint(true, 2009050615);
1767 if ($oldversion < 2009050616) {
1768 /// Add exiting sticky blocks.
1769 $blocks = $DB->get_records('block');
1770 $syscontext = get_context_instance(CONTEXT_SYSTEM);
1771 $newregions = array(
1774 'c' => 'course-view-top',
1776 $stickyblocks = $DB->get_recordset('block_pinned_old');
1777 foreach ($stickyblocks as $stickyblock) {
1778 // Only if the block exists (avoid orphaned sticky blocks)
1779 if (!isset($blocks[$stickyblock->blockid]) || empty($blocks[$stickyblock->blockid]->name)) {
1782 $newblock = new object();
1783 $newblock->blockname = $blocks[$stickyblock->blockid]->name;
1784 $newblock->contextid = $syscontext->id;
1785 $newblock->showinsubcontexts = 1;
1786 switch ($stickyblock->pagetype) {
1788 $newblock->pagetypepattern = 'course-view-*';
1791 $newblock->pagetypepattern = $stickyblock->pagetype;
1793 $newblock->defaultregion = $newregions[$stickyblock->position];
1794 $newblock->defaultweight = $stickyblock->weight;
1795 $newblock->configdata = $stickyblock->configdata;
1796 $newblock->visible = 1;
1797 $DB->insert_record('block_instances', $newblock);
1800 /// Main savepoint reached
1801 upgrade_main_savepoint(true, 2009050616);
1804 if ($oldversion < 2009050617) {
1806 /// Define table block_positions to be created
1807 $table = new xmldb_table('block_positions');
1809 /// Adding fields to table block_positions
1810 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1811 $table->add_field('blockinstanceid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1812 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
1813 $table->add_field('pagetype', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
1814 $table->add_field('subpage', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null);
1815 $table->add_field('visible', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '1');
1816 $table->add_field('region', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null);
1817 $table->add_field('weight', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1819 /// Adding keys to table block_positions
1820 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1821 $table->add_key('blockinstanceid', XMLDB_KEY_FOREIGN, array('blockinstanceid'), 'block_instances', array('id'));
1822 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
1824 /// Adding indexes to table block_positions
1825 $table->add_index('blockinstanceid-contextid-pagetype-subpage', XMLDB_INDEX_UNIQUE, array('blockinstanceid', 'contextid', 'pagetype', 'subpage'));
1827 /// Conditionally launch create table for block_positions
1828 if (!$dbman->table_exists($table)) {
1829 $dbman->create_table($table);
1832 /// Main savepoint reached
1833 upgrade_main_savepoint(true, 2009050617);
1836 if ($oldversion < 2009050618) {
1837 /// And block instances with visible = 0, copy that information to block_positions
1838 $DB->execute("INSERT INTO {block_positions} (blockinstanceid, contextid, pagetype, subpage, visible, region, weight)
1839 SELECT id, contextid,
1840 CASE WHEN pagetypepattern = 'course-view-*' THEN
1841 (SELECT " . $DB->sql_concat("'course-view-'", 'format') . "
1843 JOIN {context} ON {course}.id = {context}.instanceid
1844 WHERE {context}.id = contextid)
1845 ELSE pagetypepattern END,
1846 CASE WHEN subpagepattern IS NULL THEN ''
1847 ELSE subpagepattern END,
1848 0, defaultregion, defaultweight
1849 FROM {block_instances} WHERE visible = 0 AND pagetypepattern <> 'admin-*'");
1851 /// Main savepoint reached
1852 upgrade_main_savepoint(true, 2009050618);
1855 if ($oldversion < 2009050619) {
1856 $table = new xmldb_table('block_instances');
1858 /// Define field blockid to be dropped from block_instances
1859 $field = new xmldb_field('blockid');
1860 if ($dbman->field_exists($table, $field)) {
1861 /// Before dropping the field, drop dependent indexes
1862 $index = new xmldb_index('blockid', XMLDB_INDEX_NOTUNIQUE, array('blockid'));
1863 if ($dbman->index_exists($table, $index)) {
1864 /// Launch drop index blockid
1865 $dbman->drop_index($table, $index);
1867 $dbman->drop_field($table, $field);
1870 /// Define field pageid to be dropped from block_instances
1871 $field = new xmldb_field('pageid');
1872 if ($dbman->field_exists($table, $field)) {
1873 /// Before dropping the field, drop dependent indexes
1874 $index = new xmldb_index('pageid', XMLDB_INDEX_NOTUNIQUE, array('pageid'));
1875 if ($dbman->index_exists($table, $index)) {
1876 /// Launch drop index pageid
1877 $dbman->drop_index($table, $index);
1879 $dbman->drop_field($table, $field);
1882 /// Define field visible to be dropped from block_instances
1883 $field = new xmldb_field('visible');
1884 if ($dbman->field_exists($table, $field)) {
1885 $dbman->drop_field($table, $field);
1888 /// Main savepoint reached
1889 upgrade_main_savepoint(true, 2009050619);
1892 if ($oldversion < 2009051200) {
1893 /// Let's check the status of mandatory mnet_host records, fixing them
1894 /// and moving "orphan" users to default localhost record. MDL-16879
1895 echo $OUTPUT->notification('Fixing mnet records, this may take a while...', 'notifysuccess');
1896 upgrade_fix_incorrect_mnethostids();
1898 /// Main savepoint reached
1899 upgrade_main_savepoint(true, 2009051200);
1903 if ($oldversion < 2009051700) {
1904 /// migrate editor settings
1905 if (empty($CFG->htmleditor)) {
1906 set_config('texteditors', 'textarea');
1908 set_config('texteditors', 'tinymce,textarea');
1911 unset_config('htmleditor');
1912 unset_config('defaulthtmleditor');
1914 /// Main savepoint reached
1915 upgrade_main_savepoint(true, 2009051700);
1918 /// Repeat 2009050607 upgrade step, which Petr commented out because of XMLDB
1919 /// stupidity, so lots of people will have missed.
1920 if ($oldversion < 2009061600) {
1921 /// Changing precision of field defaultregion on table block_instances to (16)
1922 $table = new xmldb_table('block_instances');
1923 $field = new xmldb_field('defaultregion', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, 'configdata');
1925 /// Launch change of precision for field defaultregion
1926 $dbman->change_field_precision($table, $field);
1928 /// Main savepoint reached
1929 upgrade_main_savepoint(true, 2009061600);
1932 if ($oldversion < 2009061702) {
1933 // standardizing plugin names
1934 if ($configs = $DB->get_records_select('config_plugins', "plugin LIKE 'quizreport_%'")) {
1935 foreach ($configs as $config) {
1936 unset_config($config->name, $config->plugin); /// unset old config
1937 $config->plugin = str_replace('quizreport_', 'quiz_', $config->plugin);
1938 set_config($config->name, $config->value, $config->plugin); /// set new config
1942 upgrade_main_savepoint(true, 2009061702);
1945 if ($oldversion < 2009061703) {
1946 // standardizing plugin names
1947 if ($configs = $DB->get_records_select('config_plugins', "plugin LIKE 'assignment_type_%'")) {
1948 foreach ($configs as $config) {
1949 unset_config($config->name, $config->plugin); /// unset old config
1950 $config->plugin = str_replace('assignment_type_', 'assignment_', $config->plugin);
1951 set_config($config->name, $config->value, $config->plugin); /// set new config
1955 upgrade_main_savepoint(true, 2009061703);
1958 if ($oldversion < 2009061704) {
1959 // change component string in capability records to new "_" format
1960 if ($caps = $DB->get_records('capabilities')) {
1961 foreach ($caps as $cap) {
1962 $cap->component = str_replace('/', '_', $cap->component);
1963 $DB->update_record('capabilities', $cap);
1967 upgrade_main_savepoint(true, 2009061704);
1970 if ($oldversion < 2009061705) {
1971 // change component string in events_handlers records to new "_" format
1972 if ($handlers = $DB->get_records('events_handlers')) {
1973 foreach ($handlers as $handler) {
1974 $handler->handlermodule = str_replace('/', '_', $handler->handlermodule);
1975 $DB->update_record('events_handlers', $handler);
1979 upgrade_main_savepoint(true, 2009061705);
1982 if ($oldversion < 2009063000) {
1983 // upgrade format of _with_advanced settings - quiz only
1984 // note: this can be removed later, not needed for upgrades from 1.9.x
1985 if ($quiz = get_config('quiz')) {
1986 foreach ($quiz as $name=>$value) {
1987 if (strpos($name, 'fix_') !== 0) {
1990 $newname = substr($name,4).'_adv';
1991 set_config($newname, $value, 'quiz');
1992 unset_config($name, 'quiz');
1995 upgrade_main_savepoint(true, 2009063000);
1998 if ($oldversion < 2009071000) {
2000 /// Rename field contextid on table block_instances to parentcontextid
2001 $table = new xmldb_table('block_instances');
2002 $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'blockname');
2004 /// Launch rename field parentcontextid
2005 $dbman->rename_field($table, $field, 'parentcontextid');
2007 /// Main savepoint reached
2008 upgrade_main_savepoint(true, 2009071000);
2011 if ($oldversion < 2009071300) {
2013 /// Create contexts for every block. In the past, only non-sticky course block had contexts.
2014 /// This is a copy of the code in create_contexts.
2015 $sql = "INSERT INTO {context} (contextlevel, instanceid)
2016 SELECT " . CONTEXT_BLOCK . ", bi.id
2017 FROM {block_instances} bi
2018 WHERE NOT EXISTS (SELECT 'x'
2020 WHERE bi.id = ctx.instanceid AND ctx.contextlevel=" . CONTEXT_BLOCK . ")";
2023 /// TODO MDL-19776 We should not really use API funcitons in upgrade.
2024 /// If MDL-19776 is done, we can remove this whole upgrade block.
2025 build_context_path();
2027 /// Main savepoint reached
2028 upgrade_main_savepoint(true, 2009071300);
2031 if ($oldversion < 2009071600) {
2033 /// Define field summaryformat to be added to post
2034 $table = new xmldb_table('post');
2035 $field = new xmldb_field('summaryformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'format');
2037 /// Conditionally launch add field summaryformat
2038 if (!$dbman->field_exists($table, $field)) {
2039 $dbman->add_field($table, $field);
2042 /// Main savepoint reached
2043 upgrade_main_savepoint(true, 2009071600);
2046 if ($oldversion < 2009072400) {
2048 /// Define table comments to be created
2049 $table = new xmldb_table('comments');
2051 /// Adding fields to table comments
2052 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2053 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2054 $table->add_field('commentarea', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
2055 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2056 $table->add_field('content', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
2057 $table->add_field('format', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2058 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2059 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2061 /// Adding keys to table comments
2062 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2064 /// Conditionally launch create table for comments
2065 if (!$dbman->table_exists($table)) {
2066 $dbman->create_table($table);
2069 /// Main savepoint reached
2070 upgrade_main_savepoint(true, 2009072400);
2074 * This upgrade is to set up the new navigation blocks that have been developed
2075 * as part of Moodle 2.0
2076 * Now I [Sam Hemelryk] hit a conundrum while exploring how to go about this
2077 * as not only do we want to install the new blocks but we also want to set up
2078 * default instances of them, and at the same time remove instances of the blocks
2079 * that were/will-be outmoded by the two new navigation blocks.
2080 * After talking it through with Tim Hunt {@link http://moodle.org/mod/cvsadmin/view.php?conversationid=3112}
2081 * we decided that the best way to go about this was to put the bulk of the
2082 * upgrade operation into core upgrade `here` but to let the plugins block
2083 * still install the blocks.
2084 * This leaves one hairy end in that we will create block_instances within the
2085 * DB before the blocks themselves are created within the DB
2087 if ($oldversion < 2009082800) {
2089 echo $OUTPUT->notification(get_string('navigationupgrade', 'admin'));
2091 // Get the system context so we can set the block instances to it
2092 $syscontext = get_context_instance(CONTEXT_SYSTEM);
2094 // An array to contain the new block instances we will create
2095 $newblockinstances = array('globalnavigation'=>new stdClass,'settingsnavigation'=>new stdClass);
2096 // The new global navigation block instance as a stdClass
2097 $newblockinstances['globalnavigation']->blockname = 'global_navigation_tree';
2098 $newblockinstances['globalnavigation']->parentcontextid = $syscontext->id; // System context
2099 $newblockinstances['globalnavigation']->showinsubcontexts = true; // Show absolutly everywhere
2100 $newblockinstances['globalnavigation']->pagetypepattern = '*'; // Thats right everywhere
2101 $newblockinstances['globalnavigation']->subpagetypepattern = null;
2102 $newblockinstances['globalnavigation']->defaultregion = BLOCK_POS_LEFT;
2103 $newblockinstances['globalnavigation']->defaultweight = -10; // Try make this first
2104 $newblockinstances['globalnavigation']->configdata = '';
2105 // The new settings navigation block instance as a stdClass
2106 $newblockinstances['settingsnavigation']->blockname = 'settings_navigation_tree';
2107 $newblockinstances['settingsnavigation']->parentcontextid = $syscontext->id;
2108 $newblockinstances['settingsnavigation']->showinsubcontexts = true;
2109 $newblockinstances['settingsnavigation']->pagetypepattern = '*';
2110 $newblockinstances['settingsnavigation']->subpagetypepattern = null;
2111 $newblockinstances['settingsnavigation']->defaultregion = BLOCK_POS_LEFT;
2112 $newblockinstances['settingsnavigation']->defaultweight = -9; // Try make this second
2113 $newblockinstances['settingsnavigation']->configdata = '';
2115 // Blocks that are outmoded and for whom the bells will toll... by which I
2116 // mean we will delete all instances of
2117 $outmodedblocks = array('participants','admin_tree','activity_modules','admin','course_list');
2118 $outmodedblocksstring = '\''.join('\',\'',$outmodedblocks).'\'';
2119 unset($outmodedblocks);
2120 // Retrieve the block instance id's and parent contexts, so we can join them an GREATLY
2121 // cut down the number of delete queries we will need to run
2122 $allblockinstances = $DB->get_recordset_select('block_instances', 'blockname IN ('.$outmodedblocksstring.')', array(), '', 'id, parentcontextid');
2124 $contextids = array();
2125 $instanceids = array();
2126 // Iterate through all block instances
2127 foreach ($allblockinstances as $blockinstance) {
2128 if (!in_array($blockinstance->parentcontextid, $contextids)) {
2129 $contextids[] = $blockinstance->parentcontextid;
2131 // If we have over 1000 contexts clean them up and reset the array
2132 // this ensures we don't hit any nasty memory limits or such
2133 if (count($contextids) > 1000) {
2134 upgrade_cleanup_unwanted_block_contexts($contextids);
2135 $contextids = array();
2138 if (!in_array($blockinstance->id, $instanceids)) {
2139 $instanceids[] = $blockinstance->id;
2140 // If we have more than 1000 block instances now remove all block positions
2141 // and empty the array
2142 if (count($contextids) > 1000) {
2143 $instanceidstring = join(',',$instanceids);
2144 $DB->delete_records_select('block_positions', 'blockinstanceid IN ('.$instanceidstring.')');
2145 $instanceids = array();
2150 upgrade_cleanup_unwanted_block_contexts($contextids);
2152 $instanceidstring = join(',',$instanceids);
2153 $DB->delete_records_select('block_positions', 'blockinstanceid IN ('.$instanceidstring.')');
2155 unset($allblockinstances);
2157 unset($instanceids);
2158 unset($instanceidstring);
2160 // Now remove the actual block instance
2161 $DB->delete_records_select('block_instances', 'blockname IN ('.$outmodedblocksstring.')');
2162 unset($outmodedblocksstring);
2164 // Insert the new block instances. Remember they have not been installed yet
2165 // however this should not be a problem
2166 foreach ($newblockinstances as $blockinstance) {
2167 $blockinstance->id= $DB->insert_record('block_instances', $blockinstance);
2168 // Ensure the block context is created.
2169 get_context_instance(CONTEXT_BLOCK, $blockinstance->id);
2171 unset($newblockinstances);
2173 upgrade_main_savepoint(true, 2009082800);
2174 // The end of the navigation upgrade
2177 if ($oldversion < 2009090800){
2178 //insert new record for log_display table
2179 //used to record tag update.
2180 if (!$DB->record_exists('log_display', array('action'=>'update', 'module'=>'tag'))) {
2181 $log_action = new object();
2182 $log_action->module = 'tag';
2183 $log_action->action = 'update';
2184 $log_action->mtable = 'tag';
2185 $log_action->field = 'name';
2187 $DB->insert_record('log_display', $log_action);
2189 upgrade_main_savepoint(true, 2009090800);
2192 if ($oldversion < 2009100602) {
2193 /// Define table external_functions to be created
2194 $table = new xmldb_table('external_functions');
2196 /// Adding fields to table external_functions
2197 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2198 $table->add_field('name', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
2199 $table->add_field('classname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
2200 $table->add_field('methodname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
2201 $table->add_field('classpath', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2202 $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
2204 /// Adding keys to table external_functions
2205 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2207 /// Adding indexes to table external_functions
2208 $table->add_index('name', XMLDB_INDEX_UNIQUE, array('name'));
2210 /// Launch create table for external_functions
2211 $dbman->create_table($table);
2213 /// Main savepoint reached
2214 upgrade_main_savepoint(true, 2009100602);
2217 if ($oldversion < 2009100603) {
2218 /// Define table external_services to be created
2219 $table = new xmldb_table('external_services');
2221 /// Adding fields to table external_services
2222 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2223 $table->add_field('name', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
2224 $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2225 $table->add_field('requiredcapability', XMLDB_TYPE_CHAR, '150', null, null, null, null);
2226 $table->add_field('restrictedusers', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2227 $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, null, null, null);
2228 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2229 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
2231 /// Adding keys to table external_services
2232 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2234 /// Adding indexes to table external_services
2235 $table->add_index('name', XMLDB_INDEX_UNIQUE, array('name'));
2237 /// Launch create table for external_services
2238 $dbman->create_table($table);
2240 /// Main savepoint reached
2241 upgrade_main_savepoint(true, 2009100603);
2244 if ($oldversion < 2009100604) {
2245 /// Define table external_services_functions to be created
2246 $table = new xmldb_table('external_services_functions');
2248 /// Adding fields to table external_services_functions
2249 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2250 $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2251 $table->add_field('functionname', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
2253 /// Adding keys to table external_services_functions
2254 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2255 $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id'));
2257 /// Launch create table for external_services_functions
2258 $dbman->create_table($table);
2260 /// Main savepoint reached
2261 upgrade_main_savepoint(true, 2009100604);
2264 if ($oldversion < 2009100605) {
2265 /// Define table external_services_users to be created
2266 $table = new xmldb_table('external_services_users');
2268 /// Adding fields to table external_services_users
2269 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2270 $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2271 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2272 $table->add_field('iprestriction', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2273 $table->add_field('validuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
2274 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
2276 /// Adding keys to table external_services_users
2277 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2278 $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id'));
2279 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
2281 /// Launch create table for external_services_users
2282 $dbman->create_table($table);
2284 /// Main savepoint reached
2285 upgrade_main_savepoint(true, 2009100605);
2288 if ($oldversion < 2009102600) {
2290 /// Define table external_tokens to be created
2291 $table = new xmldb_table('external_tokens');
2293 /// Adding fields to table external_tokens
2294 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2295 $table->add_field('token', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null);
2296 $table->add_field('tokentype', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2297 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2298 $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2299 $table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, null, null, null);
2300 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2301 $table->add_field('creatorid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
2302 $table->add_field('iprestriction', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2303 $table->add_field('validuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
2304 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2305 $table->add_field('lastaccess', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
2307 /// Adding keys to table external_tokens
2308 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2309 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
2310 $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id'));
2311 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
2312 $table->add_key('creatorid', XMLDB_KEY_FOREIGN, array('creatorid'), 'user', array('id'));
2314 /// Launch create table for external_tokens
2315 $dbman->create_table($table);
2317 /// Main savepoint reached
2318 upgrade_main_savepoint(true, 2009102600);
2321 if ($oldversion < 2009103000) {
2323 /// Define table blog_association to be created
2324 $table = new xmldb_table('blog_association');
2326 /// Adding fields to table blog_association
2327 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2328 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2329 $table->add_field('blogid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2331 /// Adding keys to table blog_association
2332 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2333 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
2334 $table->add_key('blogid', XMLDB_KEY_FOREIGN, array('blogid'), 'post', array('id'));
2336 /// Conditionally launch create table for blog_association
2337 if (!$dbman->table_exists($table)) {
2338 $dbman->create_table($table);
2341 /// Define table blog_external to be created
2342 $table = new xmldb_table('blog_external');
2344 /// Adding fields to table blog_external
2345 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2346 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
2347 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
2348 $table->add_field('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
2349 $table->add_field('url', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
2350 $table->add_field('filtertags', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2351 $table->add_field('failedlastsync', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2352 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
2353 $table->add_field('timefetched', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2355 /// Adding keys to table blog_external
2356 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2357 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
2359 /// Conditionally launch create table for blog_external
2360 if ($dbman->table_exists($table)) {
2361 // Delete the existing one first (comes from early dev version)
2362 $dbman->drop_table($table);
2364 $dbman->create_table($table);
2366 // now inform admins that some settings require attention after upgrade
2367 if (($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL) && empty($CFG->bloglevel_upgrade_complete)) {
2368 echo $OUTPUT->notification(get_string('bloglevelupgradenotice', 'admin'));
2373 $a->sitename = $site->fullname;
2374 $a->fixurl = "$CFG->wwwroot/$CFG->admin/bloglevelupgrade.php";
2376 $subject = get_string('bloglevelupgrade', 'admin');
2377 $description = get_string('bloglevelupgradedescription', 'admin', $a);
2379 // can not use messaging here because it is not configured yet!
2380 upgrade_log(UPGRADE_LOG_NOTICE, null, $subject, $description);
2382 /// Main savepoint reached
2383 upgrade_main_savepoint(true, 2009103000);
2386 if ($oldversion < 2009110400) {
2388 // An array used to store the table name and keys of summary and trust fields
2390 $extendtables = array();
2391 $extendtables['course'] = array('summaryformat');
2392 $extendtables['course_categories'] = array('descriptionformat');
2393 $extendtables['course_request'] = array('summaryformat');
2394 $extendtables['grade_outcomes'] = array('descriptionformat');
2395 $extendtables['groups'] = array('descriptionformat');
2396 $extendtables['groupings'] = array('descriptionformat');
2397 $extendtables['scale'] = array('descriptionformat');
2398 $extendtables['user'] = array('descriptionformat');
2399 $extendtables['user_info_field'] = array('descriptionformat', 'defaultdataformat');
2400 $extendtables['user_info_data'] = array('dataformat');
2402 foreach ($extendtables as $tablestr=>$newfields) {
2403 $table = new xmldb_table($tablestr);
2404 foreach ($newfields as $fieldstr) {
2405 $field = new xmldb_field($fieldstr, XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
2406 // Check that the field doesn't already exists
2407 if (!$dbman->field_exists($table, $field)) {
2408 // Add the new field
2409 $dbman->add_field($table, $field);
2410 // Update the field if the text contains the default FORMAT_MOODLE to FORMAT_HTML
2411 if (($pos = strpos($fieldstr, 'format'))>0) {
2412 upgrade_set_timeout(60*20); // this may take a little while
2413 $params = array(FORMAT_HTML, '<p%', '%<br />%', FORMAT_MOODLE);
2414 $textfield = substr($fieldstr, 0, $pos);
2415 $DB->execute('UPDATE {'.$tablestr.'} SET '.$fieldstr.'=? WHERE ('.$textfield.' LIKE ? OR '.$textfield.' LIKE ?) AND '.$fieldstr.'=?', $params);
2421 unset($extendtables);
2423 upgrade_main_savepoint(true, 2009110400);
2426 if ($oldversion < 2009112400) {
2427 if (empty($CFG->passwordsaltmain)) {
2428 $subject = get_string('check_passwordsaltmain_name', 'report_security');
2429 $description = get_string('check_passwordsaltmain_warning', 'report_security');;
2430 upgrade_log(UPGRADE_LOG_NOTICE, null, $subject, $description);
2432 upgrade_main_savepoint(true, 2009112400);
2435 if ($oldversion < 2010011200) {
2436 $table = new xmldb_table('grade_categories');
2437 $field = new xmldb_field('hidden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
2439 if (!$dbman->field_exists($table, $field)) {
2440 $dbman->add_field($table, $field);
2443 upgrade_main_savepoint(true, 2010011200);
2447 if ($oldversion < 2010012500) {
2448 upgrade_fix_incorrect_mnethostids();
2449 upgrade_main_savepoint(true, 2010012500);
2452 if ($oldversion < 2010012600) {
2453 // do stuff to the mnet table
2454 $table = new xmldb_table('mnet_rpc');
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');
2459 $field = new xmldb_field('parent', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path');
2460 $dbman->rename_field($table, $field, 'pluginname');
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);
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);
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);
2477 /// Main savepoint reached
2478 upgrade_main_savepoint(true, 2010012600);
2481 if ($oldversion < 2010012900) {
2483 /// Define table mnet_remote_rpc to be created
2484 $table = new xmldb_table('mnet_remote_rpc');
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);
2491 /// Adding keys to table mnet_remote_rpc
2492 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2494 /// Conditionally launch create table for mnet_remote_rpc
2495 if (!$dbman->table_exists($table)) {
2496 $dbman->create_table($table);
2500 /// Define table mnet_remote_service2rpc to be created
2501 $table = new xmldb_table('mnet_remote_service2rpc');
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');
2508 /// Adding keys to table mnet_remote_service2rpc
2509 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2511 /// Adding indexes to table mnet_remote_service2rpc
2512 $table->add_index('rpcid_serviceid', XMLDB_INDEX_UNIQUE, array('rpcid', 'serviceid'));
2514 /// Conditionally launch create table for mnet_remote_service2rpc
2515 if (!$dbman->table_exists($table)) {
2516 $dbman->create_table($table);
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');
2524 /// Launch rename field function_name
2525 $dbman->rename_field($table, $field, 'functionname');
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');
2532 /// Launch rename field xmlrpc_path
2533 $dbman->rename_field($table, $field, 'xmlrpcpath');
2536 /// Main savepoint reached
2537 upgrade_main_savepoint(true, 2010012900);
2540 if ($oldversion < 2010012901) {
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');
2546 /// Conditionally launch add field plugintype
2547 if (!$dbman->field_exists($table, $field)) {
2548 $dbman->add_field($table, $field);
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');
2554 /// Conditionally launch add field pluginname
2555 if (!$dbman->field_exists($table, $field)) {
2556 $dbman->add_field($table, $field);
2559 /// Main savepoint reached
2560 upgrade_main_savepoint(true, 2010012901);
2563 if ($oldversion < 2010012902) {
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');
2569 /// Conditionally launch add field enabled
2570 if (!$dbman->field_exists($table, $field)) {
2571 $dbman->add_field($table, $field);
2574 /// Main savepoint reached
2575 upgrade_main_savepoint(true, 2010012902);
2578 /// MDL-17863. Increase the portno column length on mnet_host to handle any port number
2579 if ($oldversion < 2010020100) {
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');
2584 /// Launch change of precision for field portno
2585 $dbman->change_field_precision($table, $field);
2587 upgrade_main_savepoint(true, 2010020100);
2590 if ($oldversion < 2010020300) {
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');
2596 if (!$dbman->field_exists($table, $field)) {
2597 /// Launch add field timecreated
2598 $dbman->add_field($table, $field);
2600 $DB->execute("UPDATE {user} SET timecreated = firstaccess");
2602 $sql = "UPDATE {user} SET timecreated = " . time() ." where timecreated = 0";
2605 upgrade_main_savepoint(true, 2010020300);
2608 // MDL-21407. Trim leading spaces from default tex latexpreamble causing problems under some confs
2609 if ($oldversion < 2010020301) {
2610 if ($preamble = $CFG->filter_tex_latexpreamble) {
2611 $preamble = preg_replace('/^ +/m', '', $preamble);
2612 set_config('filter_tex_latexpreamble', $preamble);
2614 upgrade_main_savepoint(true, 2010020301);
2617 if ($oldversion < 2010021400) {
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);
2621 upgrade_main_savepoint(true, 2010021400);
2624 if ($oldversion < 2010021800) {
2625 $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle'));
2626 upgrade_main_savepoint(true, 2010021800);
2629 if ($oldversion < 2010031900) {
2630 // regeneration of sessions is always enabled, no need for this setting any more
2631 unset_config('regenloginsession');
2632 upgrade_main_savepoint(true, 2010031900);
2636 if ($oldversion < 2010032400) {
2637 // Upgrade all of those using the standardold theme to the use the standard
2639 if ($CFG->theme == 'standardold') {
2640 // The config setting that affects the whole site
2641 set_config('theme', 'standard');
2643 // Course Categories
2644 $DB->execute('UPDATE {course_categories} SET theme=? WHERE theme=?', array('standard', 'standardold'));
2646 $DB->execute('UPDATE {course} SET theme=? WHERE theme=?', array('standard', 'standardold'));
2648 $DB->execute('UPDATE {user} SET theme=? WHERE theme=?', array('standard', 'standardold'));
2649 upgrade_main_savepoint(true, 2010032400);
2652 if ($oldversion < 2010033101.01) {
2654 /// Define field source to be added to files
2655 $table = new xmldb_table('files');
2657 $field = new xmldb_field('source', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'status');
2659 /// Conditionally launch add field source
2660 if (!$dbman->field_exists($table, $field)) {
2661 $dbman->add_field($table, $field);
2664 $field = new xmldb_field('author', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'source');
2666 /// Conditionally launch add field author
2667 if (!$dbman->field_exists($table, $field)) {
2668 $dbman->add_field($table, $field);
2671 $field = new xmldb_field('license', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'author');
2673 /// Conditionally launch add field license
2674 if (!$dbman->field_exists($table, $field)) {
2675 $dbman->add_field($table, $field);
2678 upgrade_main_savepoint(true, 2010033101.01);
2681 if ($oldversion < 2010033101.02) {
2683 /// Define table license to be created
2684 $table = new xmldb_table('license');
2686 /// Adding fields to table license
2687 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2688 $table->add_field('shortname', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2689 $table->add_field('fullname', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
2690 $table->add_field('source', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2691 $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
2692 $table->add_field('version', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
2694 /// Adding keys to table license
2695 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2697 /// Conditionally launch create table for license
2698 if (!$dbman->table_exists($table)) {
2699 $dbman->create_table($table);
2701 $active_licenses = array();
2703 $license = new stdclass;
2705 // add unknown license
2706 $license->shortname = 'unknown';
2707 $license->fullname = 'Unknown license';
2708 $license->source = '';
2709 $license->enabled = 1;
2710 $license->version = '2010033100';
2711 $active_licenses[] = $license->shortname;
2712 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2713 if ($record->version < $license->version) {
2714 // update license record
2715 $license->enabled = $record->enabled;
2716 $license->id = $record->id;
2717 $DB->update_record('license', $license);
2720 $DB->insert_record('license', $license);
2723 // add all rights reserved license
2724 $license->shortname = 'allrightsreserved';
2725 $license->fullname = 'All rights reserved';
2726 $license->source = 'http://en.wikipedia.org/wiki/All_rights_reserved';
2727 $license->enabled = 1;
2728 $license->version = '2010033100';
2729 $active_licenses[] = $license->shortname;
2730 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2731 if ($record->version < $license->version) {
2732 // update license record
2733 $license->id = $record->id;
2734 $license->enabled = $record->enabled;
2735 $DB->update_record('license', $license);
2738 $DB->insert_record('license', $license);
2741 // add public domain license
2742 $license->shortname = 'public';
2743 $license->fullname = 'Public Domain';
2744 $license->source = 'http://creativecommons.org/licenses/publicdomain/';
2745 $license->enabled = 1;
2746 $license->version = '2010033100';
2747 $active_licenses[] = $license->shortname;
2748 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2749 if ($record->version < $license->version) {
2750 // update license record
2751 $license->enabled = $record->enabled;
2752 $license->id = $record->id;
2753 $DB->update_record('license', $license);
2756 $DB->insert_record('license', $license);
2759 // add creative commons license
2760 $license->shortname = 'cc';
2761 $license->fullname = 'Creative Commons';
2762 $license->source = 'http://creativecommons.org/licenses/by/3.0/';
2763 $license->enabled = 1;
2764 $license->version = '2010033100';
2765 $active_licenses[] = $license->shortname;
2766 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2767 if ($record->version < $license->version) {
2768 // update license record
2769 $license->enabled = $record->enabled;
2770 $license->id = $record->id;
2771 $DB->update_record('license', $license);
2774 $DB->insert_record('license', $license);
2777 // add creative commons no derivs license
2778 $license->shortname = 'cc-nd';
2779 $license->fullname = 'Creative Commons - NoDerivs';
2780 $license->source = 'http://creativecommons.org/licenses/by-nd/3.0/';
2781 $license->enabled = 1;
2782 $license->version = '2010033100';
2783 $active_licenses[] = $license->shortname;
2784 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2785 if ($record->version < $license->version) {
2786 // update license record
2787 $license->enabled = $record->enabled;
2788 $license->id = $record->id;
2789 $DB->update_record('license', $license);
2792 $DB->insert_record('license', $license);
2795 // add creative commons no commercial no derivs license
2796 $license->shortname = 'cc-nc-nd';
2797 $license->fullname = 'Creative Commons - No Commercial NoDerivs';
2798 $license->source = 'http://creativecommons.org/licenses/by-nc-nd/3.0/';
2799 $license->enabled = 1;
2800 $license->version = '2010033100';
2801 $active_licenses[] = $license->shortname;
2802 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2803 if ($record->version < $license->version) {
2804 // update license record
2805 $license->enabled = $record->enabled;
2806 $license->id = $record->id;
2807 $DB->update_record('license', $license);
2810 $DB->insert_record('license', $license);
2813 // add creative commons no commercial
2814 $license->shortname = 'cc-nc-nd';
2815 $license->shortname = 'cc-nc';
2816 $license->fullname = 'Creative Commons - No Commercial';
2817 $license->source = 'http://creativecommons.org/licenses/by-nd/3.0/';
2818 $license->enabled = 1;
2819 $license->version = '2010033100';
2820 $active_licenses[] = $license->shortname;
2821 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2822 if ($record->version < $license->version) {
2823 // update license record
2824 $license->enabled = $record->enabled;
2825 $license->id = $record->id;
2826 $DB->update_record('license', $license);
2829 $DB->insert_record('license', $license);
2832 // add creative commons no commercial sharealike
2833 $license->shortname = 'cc-nc-sa';
2834 $license->fullname = 'Creative Commons - No Commercial ShareAlike';
2835 $license->source = 'http://creativecommons.org/licenses/by-nc-sa/3.0/';
2836 $license->enabled = 1;
2837 $license->version = '2010033100';
2838 $active_licenses[] = $license->shortname;
2839 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2840 if ($record->version < $license->version) {
2841 // update license record
2842 $license->enabled = $record->enabled;
2843 $license->id = $record->id;
2844 $DB->update_record('license', $license);
2847 $DB->insert_record('license', $license);
2850 // add creative commons sharealike
2851 $license->shortname = 'cc-sa';
2852 $license->fullname = 'Creative Commons - ShareAlike';
2853 $license->source = 'http://creativecommons.org/licenses/by-sa/3.0/';
2854 $license->enabled = 1;
2855 $license->version = '2010033100';
2856 $active_licenses[] = $license->shortname;
2857 if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
2858 if ($record->version < $license->version) {
2859 // update license record
2860 $license->enabled = $record->enabled;
2861 $license->id = $record->id;
2862 $DB->update_record('license', $license);
2865 $DB->insert_record('license', $license);
2868 set_config('licenses', implode(',', $active_licenses));
2869 /// set site default license
2870 set_config('sitedefaultlicense', 'allrightsreserved');
2872 /// Main savepoint reached
2873 upgrade_main_savepoint(true, 2010033101.02);
2876 if ($oldversion < 2010033102.00) {
2877 // rename course view capability to participate
2878 $params = array('view'=>'moodle/course:view', 'participate'=>'moodle/course:participate');
2879 $sql = "UPDATE {role_capabilities} SET capability = :participate WHERE capability = :view";
2880 $DB->execute($sql, $params);
2881 $sql = "UPDATE {capabilities} SET name = :participate WHERE name = :view";
2882 $DB->execute($sql, $params);
2883 // note: the view capability is readded again at the end of upgrade, but with different meaning
2884 upgrade_main_savepoint(true, 2010033102.00);
2887 if ($oldversion < 2010033102.01) {
2888 // Define field archetype to be added to role table
2889 $table = new xmldb_table('role');
2890 $field = new xmldb_field('archetype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, 'sortorder');
2891 $dbman->add_field($table, $field);
2892 upgrade_main_savepoint(true, 2010033102.01);
2895 if ($oldversion < 2010033102.02) {
2896 // Set archetype for existing roles and change admin role to manager role
2897 $sql = "SELECT r.*, rc.capability
2899 JOIN {role_capabilities} rc ON rc.roleid = r.id
2900 WHERE rc.contextid = :syscontextid AND rc.capability LIKE :legacycaps
2902 $params = array('syscontextid'=>SYSCONTEXTID, 'legacycaps'=>'moodle/legacy:%');
2903 $substart = strlen('moodle/legacy:');
2904 $roles = $DB->get_recordset_sql($sql, $params); // in theory could be multiple legacy flags in one role
2905 foreach ($roles as $role) {
2906 $role->archetype = substr($role->capability, $substart);
2907 unset($role->capability);
2908 if ($role->archetype === 'admin') {
2909 $role->archetype = 'manager';
2910 if ($role->shortname === 'admin') {
2911 $role->shortname = 'manager';
2912 $role->name = get_string('manager', 'role');
2913 $role->description = get_string('managerdescription', 'role');
2916 $DB->update_record('role', $role);
2920 upgrade_main_savepoint(true, 2010033102.02);
2923 if ($oldversion < 2010033102.03) {
2924 // Now pick site admins (===have manager role assigned at the system context)
2925 // and store them in the new $CFG->siteadmins setting as comma separated list
2926 $sql = "SELECT ra.id, ra.userid
2927 FROM {role_assignments} ra
2928 JOIN {role} r ON r.id = ra.roleid
2929 JOIN {user} u ON u.id = ra.userid
2930 WHERE ra.contextid = :syscontext AND r.archetype = 'manager' AND u.deleted = 0
2932 $ras = $DB->get_records_sql($sql, array('syscontext'=>SYSCONTEXTID));
2934 foreach ($ras as $ra) {
2935 $admins[$ra->userid] = $ra->userid;
2936 set_config('siteadmins', implode(',', $admins)); // better to save it repeatedly, we do need at least one admin
2937 $DB->delete_records('role_assignments', array('id'=>$ra->id));
2940 upgrade_main_savepoint(true, 2010033102.03);
2943 if ($oldversion < 2010033102.04) {
2944 // clean up the manager roles
2945 $managers = $DB->get_records('role', array('archetype'=>'manager'));
2946 foreach ($managers as $manager) {
2947 // now sanitize the capabilities and overrides
2948 $DB->delete_records('role_capabilities', array('capability'=>'moodle/site:config', 'roleid'=>$manager->id)); // only site admins may configure servers
2949 // note: doanything and legacy caps are deleted automatically, they get moodle/course:view later at the end of the upgrade
2951 // remove manager role assignments bellow the course context level - admin role was never intended for activities and blocks,
2952 // the problem is that those assignments would not be visible after upgrade and old style admins in activities make no sense anyway
2953 $DB->delete_records_select('role_assignments', "roleid = :manager AND contextid IN (SELECT id FROM {context} WHERE contextlevel > 50)", array('manager'=>$manager->id));
2955 // allow them to assign all roles except default user, guest and frontpage - users get these roles automatically on the fly when needed
2956 $DB->delete_records('role_allow_assign', array('roleid'=>$manager->id));
2957 $roles = $DB->get_records_sql("SELECT * FROM {role} WHERE archetype <> 'user' AND archetype <> 'guest' AND archetype <> 'frontpage'");
2958 foreach ($roles as $role) {
2959 $record = (object)array('roleid'=>$manager->id, 'allowassign'=>$role->id);
2960 $DB->insert_record('role_allow_assign', $record);
2963 // allow them to override all roles
2964 $DB->delete_records('role_allow_override', array('roleid'=>$manager->id));
2965 $roles = $DB->get_records_sql("SELECT * FROM {role}");
2966 foreach ($roles as $role) {
2967 $record = (object)array('roleid'=>$manager->id, 'allowoverride'=>$role->id);
2968 $DB->insert_record('role_allow_override', $record);
2971 // allow them to switch to all following roles
2972 $DB->delete_records('role_allow_switch', array('roleid'=>$manager->id));
2973 $roles = $DB->get_records_sql("SELECT * FROM {role} WHERE archetype IN ('student', 'teacher', 'editingteacher')");
2974 foreach ($roles as $role) {
2975 $record = (object)array('roleid'=>$manager->id, 'allowswitch'=>$role->id);
2976 $DB->insert_record('role_allow_switch', $record);
2980 upgrade_main_savepoint(true, 2010033102.04);
2983 if ($oldversion < 2010033102.05) {
2984 // remove course:view from all roles that are not used for enrolment, it does NOT belong there because it really means user is enrolled!
2985 $noenrolroles = $DB->get_records_select('role', "archetype IN ('guest', 'user', 'manager', 'coursecreator', 'frontpage')");
2986 foreach ($noenrolroles as $role) {
2987 $DB->delete_records('role_capabilities', array('roleid'=>$role->id, 'capability'=>'moodle/course:participate'));
2989 upgrade_main_savepoint(true, 2010033102.05);
2992 if ($oldversion < 2010033102.06) {
2993 // make sure there is nothing weird in default user role
2994 if (!empty($CFG->defaultuserroleid)) {
2995 if ($role = $DB->get_record('role', array('id'=>$CFG->defaultuserroleid))) {
2996 if ($role->archetype !== '' and $role->archetype !== 'user') {
2997 upgrade_log(UPGRADE_LOG_NOTICE, null, 'Default authenticated user role (defaultuserroleid) value is invalid, setting cleared.');
2998 unset_config('defaultuserroleid');
3001 unset_config('defaultuserroleid');
3004 upgrade_main_savepoint(true, 2010033102.06);
3007 if ($oldversion < 2010033102.07) {
3008 if (!empty($CFG->displayloginfailures) and $CFG->displayloginfailures === 'teacher') {
3009 upgrade_log(UPGRADE_LOG_NOTICE, null, 'Displaying of login failuters to teachers is not supported any more.');
3010 unset_config('displayloginfailures');
3012 upgrade_main_savepoint(true, 2010033102.07);
3015 if ($oldversion < 2010033102.08) {
3016 // make sure there are no problems in default guest role settings
3017 if (!empty($CFG->guestroleid)) {
3018 if ($role = $DB->get_record('role', array('id'=>$CFG->guestroleid))) {
3019 if ($role->archetype !== '' and $role->archetype !== 'guest') {
3020 upgrade_log(UPGRADE_LOG_NOTICE, null, 'Default guest role (guestroleid) value is invalid, setting cleared.');
3021 unset_config('guestroleid');
3024 upgrade_log(UPGRADE_LOG_NOTICE, null, 'Role specified in Default guest role (guestroleid) does not exist, setting cleared.');
3025 unset_config('guestroleid');
3028 // remove all roles of the guest account - the only way to change it is to override the guest role, sorry
3029 // the guest account gets all the role assignments on the fly which works fine in has_capability(),
3030 $DB->delete_records_select('role_assignments', "userid IN (SELECT id FROM {user} WHERE username = 'guest')");
3032 upgrade_main_savepoint(true, 2010033102.08);
3035 /// New table for storing which roles can be assigned in which contexts.
3036 if ($oldversion < 2010033102.09) {
3038 /// Define table role_context_levels to be created
3039 $table = new xmldb_table('role_context_levels');
3041 /// Adding fields to table role_context_levels
3042 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3043 $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3044 $table->add_field('contextlevel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3046 /// Adding keys to table role_context_levels
3047 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3048 $table->add_key('contextlevel-roleid', XMLDB_KEY_UNIQUE, array('contextlevel', 'roleid'));
3049 $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
3051 /// Conditionally launch create table for role_context_levels
3052 if (!$dbman->table_exists($table)) {
3053 $dbman->create_table($table);
3056 /// Main savepoint reached
3057 upgrade_main_savepoint(true, 2010033102.09);
3060 if ($oldversion < 2010033102.10) {
3061 // Now populate the role_context_levels table with the default values
3062 // NOTE: do not use accesslib methods here
3064 $rolecontextlevels = array();
3065 $defaults = array('manager' => array(CONTEXT_SYSTEM, CONTEXT_COURSECAT, CONTEXT_COURSE),
3066 'coursecreator' => array(CONTEXT_SYSTEM, CONTEXT_COURSECAT),
3067 'editingteacher' => array(CONTEXT_COURSE, CONTEXT_MODULE),
3068 'teacher' => array(CONTEXT_COURSE, CONTEXT_MODULE),
3069 'student' => array(CONTEXT_COURSE, CONTEXT_MODULE),
3072 'frontpage' => array());
3074 $roles = $DB->get_records('role', array(), '', 'id, archetype');
3075 foreach ($roles as $role) {
3076 if (isset($defaults[$role->archetype])) {
3077 $rolecontextlevels[$role->id] = $defaults[$role->archetype];
3081 // add roles without archetypes, it may contain weird things, but we can not fix them
3082 $sql = "SELECT DISTINCT ra.roleid, con.contextlevel
3083 FROM {role_assignments} ra
3084 JOIN {context} con ON ra.contextid = con.id";
3085 $existingrolecontextlevels = $DB->get_recordset_sql($sql);
3086 foreach ($existingrolecontextlevels as $rcl) {
3087 if (isset($roleids[$rcl->roleid])) {
3090 if (!isset($rolecontextlevels[$rcl->roleid])) {
3091 $rolecontextlevels[$rcl->roleid] = array($rcl->contextlevel);
3092 } else if (!in_array($rcl->contextlevel, $rolecontextlevels[$rcl->roleid])) {
3093 $rolecontextlevels[$rcl->roleid][] = $rcl->contextlevel;
3096 $existingrolecontextlevels->close();
3098 // Put the data into the database.
3099 $rcl = new object();
3100 foreach ($rolecontextlevels as $roleid => $contextlevels) {
3101 $rcl->roleid = $roleid;
3102 foreach ($contextlevels as $level) {
3103 $rcl->contextlevel = $level;
3104 $DB->insert_record('role_context_levels', $rcl, false);
3112 unset($existingrolecontextlevels);
3113 unset($rolecontextlevels);
3115 // Main savepoint reached
3116 upgrade_main_savepoint(true, 2010033102.10);
3119 if ($oldversion < 2010040700) {
3120 // migrate old groupings --> groupmembersonly setting
3121 if (isset($CFG->enablegroupings)) {
3122 set_config('enablegroupmembersonly', $CFG->enablegroupings);
3123 unset_config('enablegroupings');
3126 // Main savepoint reached
3127 upgrade_main_savepoint(true, 2010040700);
3130 if ($oldversion < 2010040900) {
3132 // Changing the default of field lang on table user to good old "en"
3133 $table = new xmldb_table('user');
3134 $field = new xmldb_field('lang', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, 'en', 'country');
3136 // Launch change of default for field lang
3137 $dbman->change_field_default($table, $field);
3139 // update main site lang
3140 if (strpos($CFG->lang, '_utf8') !== false) {
3141 $lang = str_replace('_utf8', '', $CFG->lang);
3142 set_config('lang', $lang);
3146 if (!empty($CFG->langlist)) {
3147 $langs = explode(',', $CFG->langlist);
3148 foreach ($langs as $key=>$lang) {
3149 $lang = str_replace('_utf8', '', $lang);
3150 $langs[$key] = $lang;
3152 set_config('langlist', implode(',', $langs));
3155 // Main savepoint reached
3156 upgrade_main_savepoint(true, 2010040900);
3159 if ($oldversion < 2010040901) {
3161 // Remove "_utf8" suffix from all langs in user table
3162 $langs = $DB->get_records_sql("SELECT DISTINCT lang FROM {user} WHERE lang LIKE ?", array('%_utf8'));
3164 foreach ($langs as $lang=>$unused) {
3165 $newlang = str_replace('_utf8', '', $lang);
3166 $sql = "UPDATE {user} SET lang = :newlang WHERE lang = :lang";
3167 $DB->execute($sql, array('newlang'=>$newlang, 'lang'=>$lang));
3170 // Main savepoint reached
3171 upgrade_main_savepoint(true, 2010040901);
3174 if ($oldversion < 2010041301) {
3175 $sql = "UPDATE {block} SET name=? WHERE name=?";
3176 $DB->execute($sql, array('navigation', 'global_navigation_tree'));
3177 $DB->execute($sql, array('settings', 'settings_navigation_tree'));
3179 $sql = "UPDATE {block_instances} SET blockname=? WHERE blockname=?";
3180 $DB->execute($sql, array('navigation', 'global_navigation_tree'));
3181 $DB->execute($sql, array('settings', 'settings_navigation_tree'));
3182 upgrade_main_savepoint(true, 2010041301);
3185 if ($oldversion < 2010042100) {
3187 /// Define table backup_controllers to be created
3188 $table = new xmldb_table('backup_controllers');
3190 /// Adding fields to table backup_controllers
3191 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3192 $table->add_field('backupid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
3193 $table->add_field('type', XMLDB_TYPE_CHAR, '6', null, XMLDB_NOTNULL, null, null);
3194 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3195 $table->add_field('format', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null);
3196 $table->add_field('interactive', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3197 $table->add_field('purpose', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3198 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3199 $table->add_field('status', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3200 $table->add_field('execution', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3201 $table->add_field('executiontime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3202 $table->add_field('checksum', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
3203 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3204 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3205 $table->add_field('controller', XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null);
3207 /// Adding keys to table backup_controllers
3208 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3209 $table->add_key('backupid_uk', XMLDB_KEY_UNIQUE, array('backupid'));
3210 $table->add_key('userid_fk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
3212 /// Adding indexes to table backup_controllers
3213 $table->add_index('typeitem_ix', XMLDB_INDEX_NOTUNIQUE, array('type', 'itemid'));
3215 /// Conditionally launch create table for backup_controllers
3216 if (!$dbman->table_exists($table)) {
3217 $dbman->create_table($table);
3220 /// Define table backup_ids_template to be created
3221 $table = new xmldb_table('backup_ids_template');
3223 /// Adding fields to table backup_ids_template
3224 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3225 $table->add_field('backupid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
3226 $table->add_field('itemname', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
3227 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3228 $table->add_field('parentitemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
3230 /// Adding keys to table backup_ids_template
3231 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3232 $table->add_key('backupid_itemname_itemid_uk', XMLDB_KEY_UNIQUE, array('backupid', 'itemname', 'itemid'));
3234 /// Adding indexes to table backup_ids_template
3235 $table->add_index('backupid_parentitemid_ix', XMLDB_INDEX_NOTUNIQUE, array('backupid', 'itemname', 'parentitemid'));
3237 /// Conditionally launch create table for backup_controllers
3238 if (!$dbman->table_exists($table)) {
3239 $dbman->create_table($table);
3242 /// Main savepoint reached
3243 upgrade_main_savepoint(true, 2010042100);
3246 if ($oldversion < 2010042301) {
3248 $table = new xmldb_table('course_sections');
3249 $field = new xmldb_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'section');
3251 if (!$dbman->field_exists($table, $field)) {
3252 $dbman->add_field($table, $field);
3255 upgrade_main_savepoint(true, 2010042301);
3258 if ($oldversion < 2010042302) {
3259 // Define table cohort to be created
3260 $table = new xmldb_table('cohort');
3262 // Adding fields to table cohort
3263 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3264 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3265 $table->add_field('name', XMLDB_TYPE_CHAR, '254', null, XMLDB_NOTNULL, null, null);
3266 $table->add_field('idnumber', XMLDB_TYPE_CHAR, '100', null, null, null, null);
3267 $table->add_field('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
3268 $table->add_field('descriptionformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3269 $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
3270 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3271 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3273 // Adding keys to table cohort
3274 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3275 $table->add_key('context', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
3277 // Conditionally launch create table for cohort
3278 if (!$dbman->table_exists($table)) {
3279 $dbman->create_table($table);
3282 upgrade_main_savepoint(true, 2010042302);
3285 if ($oldversion < 2010042303) {
3286 // Define table cohort_members to be created
3287 $table = new xmldb_table('cohort_members');
3289 // Adding fields to table cohort_members
3290 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3291 $table->add_field('cohortid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3292 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3293 $table->add_field('timeadded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3295 // Adding keys to table cohort_members
3296 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3297 $table->add_key('cohortid', XMLDB_KEY_FOREIGN, array('cohortid'), 'cohort', array('id'));
3298 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
3300 // Adding indexes to table cohort_members
3301 $table->add_index('cohortid-userid', XMLDB_INDEX_UNIQUE, array('cohortid', 'userid'));
3303 // Conditionally launch create table for cohort_members
3304 if (!$dbman->table_exists($table)) {
3305 $dbman->create_table($table);
3308 // Main savepoint reached
3309 upgrade_main_savepoint(true, 2010042303);
3312 if ($oldversion < 2010042800) {
3313 //drop the previously created ratings table
3314 $table = new xmldb_table('ratings');
3315 if ($dbman->table_exists($table)) {
3316 $dbman->drop_table($table);
3319 //create the rating table (replaces module specific rating implementations)
3320 $table = new xmldb_table('rating');
3321 if ($dbman->table_exists($table)) {
3322 $dbman->drop_table($table);
3325 /// Adding fields to table rating
3326 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3327 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3329 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3330 $table->add_field('scaleid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
3331 $table->add_field('rating', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3332 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3334 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3335 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3337 /// Adding keys to table rating
3338 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3339 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
3340 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
3342 /// Adding indexes to table rating
3343 $table->add_index('itemid', XMLDB_INDEX_NOTUNIQUE, array('itemid'));
3345 /// Create table for ratings
3346 if (!$dbman->table_exists($table)) {
3347 $dbman->create_table($table);
3350 upgrade_main_savepoint(true, 2010042800);
3353 if ($oldversion < 2010042801) {
3354 // migrating old comments block content
3355 $DB->execute("UPDATE {comments}
3356 SET contextid = (SELECT parentcontextid
3357 FROM {block_instances}
3358 WHERE id = {comments}.itemid AND blockname = 'comments'),
3359 commentarea = 'page_comments',
3361 WHERE commentarea = 'block_comments'
3363 AND EXISTS (SELECT 'x'
3364 FROM {block_instances}
3365 WHERE id = {comments}.itemid
3366 AND blockname = 'comments')");
3368 // remove all orphaned record
3369 $DB->delete_records('comments', array('commentarea'=>'block_comments'));
3370 upgrade_main_savepoint(true, 2010042801);
3373 if ($oldversion < 2010042802) { // Change backup_controllers->type to varchar10 (recreate dep. index)
3375 /// Define index typeitem_ix (not unique) to be dropped form backup_controllers
3376 $table = new xmldb_table('backup_controllers');
3377 $index = new xmldb_index('typeitem_ix', XMLDB_INDEX_NOTUNIQUE, array('type', 'itemid'));
3379 /// Conditionally launch drop index typeitem_ix
3380 if ($dbman->index_exists($table, $index)) {
3381 $dbman->drop_index($table, $index);
3384 /// Changing precision of field type on table backup_controllers to (10)
3385 $table = new xmldb_table('backup_controllers');
3386 $field = new xmldb_field('type', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, 'backupid');
3388 /// Launch change of precision for field type
3389 $dbman->change_field_precision($table, $field);
3391 /// Define index typeitem_ix (not unique) to be added to backup_controllers
3392 $table = new xmldb_table('backup_controllers');
3393 $index = new xmldb_index('typeitem_ix', XMLDB_INDEX_NOTUNIQUE, array('type', 'itemid'));
3395 /// Conditionally launch add index typeitem_ix
3396 if (!$dbman->index_exists($table, $index)) {
3397 $dbman->add_index($table, $index);
3400 /// Main savepoint reached
3401 upgrade_main_savepoint(true, 2010042802);
3404 if ($oldversion < 2010043000) { // Adding new course completion feature
3406 /// Add course completion tables
3407 /// Define table course_completion_aggr_methd to be created
3408 $table = new xmldb_table('course_completion_aggr_methd');
3410 /// Adding fields to table course_completion_aggr_methd
3411 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3412 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3413 $table->add_field('criteriatype', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, null, null, null);
3414 $table->add_field('method', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3415 $table->add_field('value', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
3417 /// Adding keys to table course_completion_aggr_methd
3418 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3420 /// Adding indexes to table course_completion_aggr_methd
3421 $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
3422 $table->add_index('criteriatype', XMLDB_INDEX_NOTUNIQUE, array('criteriatype'));
3424 /// Conditionally launch create table for course_completion_aggr_methd
3425 if (!$dbman->table_exists($table)) {
3426 $dbman->create_table($table);
3430 /// Define table course_completion_criteria to be created
3431 $table = new xmldb_table('course_completion_criteria');
3433 /// Adding fields to table course_completion_criteria
3434 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3435 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3436 $table->add_field('criteriatype', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3437 $table->add_field('module', XMLDB_TYPE_CHAR, '100', null, null, null, null);
3438 $table->add_field('moduleinstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
3439 $table->add_field('courseinstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
3440 $table->add_field('enrolperiod', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
3441 $table->add_field('timeend', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
3442 $table->add_field('gradepass', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
3443 $table->add_field('role', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
3445 /// Adding keys to table course_completion_criteria
3446 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3448 /// Adding indexes to table course_completion_criteria
3449 $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
3451 /// Conditionally launch create table for course_completion_criteria
3452 if (!$dbman->table_exists($table)) {
3453 $dbman->create_table($table);
3457 /// Define table course_completion_crit_compl to be created
3458 $table = new xmldb_table('course_completion_crit_compl');
3460 /// Adding fields to table course_completion_crit_compl
3461 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3462 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3463 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3464 $table->add_field('criteriaid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3465 $table->add_field('gradefinal', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
3466 $table->add_field('unenroled', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
3467 $table->add_field('deleted', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null);
3468 $table->add_field('timecompleted', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
3470 /// Adding keys to table course_completion_crit_compl
3471 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3473 /// Adding indexes to table course_completion_crit_compl
3474 $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
3475 $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
3476 $table->add_index('criteriaid', XMLDB_INDEX_NOTUNIQUE, array('criteriaid'));
3477 $table->add_index('timecompleted', XMLDB_INDEX_NOTUNIQUE, array('timecompleted'));
3479 /// Conditionally launch create table for course_completion_crit_compl
3480 if (!$dbman->table_exists($table)) {
3481 $dbman->create_table($table);
3485 /// Define table course_completion_notify to be created
3486 $table = new xmldb_table('course_completion_notify');
3488 /// Adding fields to table course_completion_notify
3489 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3490 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3491 $table->add_field('role', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3492 $table->add_field('message', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
3493 $table->add_field('timesent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3495 /// Adding keys to table course_completion_notify
3496 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3498 /// Adding indexes to table course_completion_notify
3499 $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
3501 /// Conditionally launch create table for course_completion_notify
3502 if (!$dbman->table_exists($table)) {
3503 $dbman->create_table($table);
3506 /// Define table course_completions to be created
3507 $table = new xmldb_table('course_completions');
3509 /// Adding fields to table course_completions
3510 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3511 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3512 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3513 $table->add_field('deleted', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null);
3514 $table->add_field('timenotified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
3515 $table->add_field('timeenrolled', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3516 $table->add_field('timestarted', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3517 $table->add_field('timecompleted', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
3518 $table->add_field('reaggregate', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3520 /// Adding keys to table course_completions
3521 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3523 /// Adding indexes to table course_completions
3524 $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
3525 $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
3526 $table->add_index('timecompleted', XMLDB_INDEX_NOTUNIQUE, array('timecompleted'));
3528 /// Conditionally launch create table for course_completions
3529 if (!$dbman->table_exists($table)) {
3530 $dbman->create_table($table);
3534 /// Add cols to course table
3535 /// Define field enablecompletion to be added to course
3536 $table = new xmldb_table('course');
3537 $field = new xmldb_field('enablecompletion', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'defaultrole');
3539 /// Conditionally launch add field enablecompletion
3540 if (!$dbman->field_exists($table, $field)) {
3541 $dbman->add_field($table, $field);
3544 /// Define field completionstartonenrol to be added to course
3545 $field = new xmldb_field('completionstartonenrol', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'enablecompletion');
3547 /// Conditionally launch add field completionstartonenrol
3548 if (!$dbman->field_exists($table, $field)) {
3549 $dbman->add_field($table, $field);
3552 /// Define field completionnotify to be added to course
3553 $field = new xmldb_field('completionnotify', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'enablecompletion');
3555 /// Conditionally launch add field completionnotify
3556 if (!$dbman->field_exists($table, $field)) {
3557 $dbman->add_field($table, $field);
3560 upgrade_main_savepoint(true, 2010043000);
3563 if ($oldversion < 2010043001) {
3565 /// Define table registration_hubs to be created
3566 $table = new xmldb_table('registration_hubs');
3568 /// Adding fields to table registration_hubs
3569 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3570 $table->add_field('token', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
3571 $table->add_field('hubname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
3572 $table->add_field('huburl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
3573 $table->add_field('confirmed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3575 /// Adding keys to table registration_hubs
3576 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3578 /// Conditionally launch create table for registration_hubs
3579 if (!$dbman->table_exists($table)) {
3580 $dbman->create_table($table);
3583 /// Main savepoint reached
3584 upgrade_main_savepoint(true, 2010043001);
3587 if ($oldversion < 2010050200) {
3589 /// Define table backup_logs to be created
3590 $table = new xmldb_table('backup_logs');
3592 /// Adding fields to table backup_logs
3593 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3594 $table->add_field('backupid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null);
3595 $table->add_field('loglevel', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3596 $table->add_field('message', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
3597 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3599 /// Adding keys to table backup_logs
3600 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3601 $table->add_key('backupid', XMLDB_KEY_FOREIGN, array('backupid'), 'backup_controllers', array('backupid'));
3603 /// Adding indexes to table backup_logs
3604 $table->add_index('backupid-id', XMLDB_INDEX_UNIQUE, array('backupid', 'id'));
3606 /// Conditionally launch create table for backup_logs
3607 if (!$dbman->table_exists($table)) {
3608 $dbman->create_table($table);
3611 /// Drop some old backup tables, not used anymore
3613 /// Define table backup_files to be dropped
3614 $table = new xmldb_table('backup_files');
3616 /// Conditionally launch drop table for backup_files
3617 if ($dbman->table_exists($table)) {
3618 $dbman->drop_table($table);
3621 /// Define table backup_ids to be dropped
3622 $table = new xmldb_table('backup_ids');
3624 /// Conditionally launch drop table for backup_ids
3625 if ($dbman->table_exists($table)) {
3626 $dbman->drop_table($table);
3629 /// Main savepoint reached
3630 upgrade_main_savepoint(true, 2010050200);
3633 if ($oldversion < 2010050403) { // my_pages for My Moodle and Public Profile pages
3635 /// Define table my_pages to be created
3636 $table = new xmldb_table('my_pages');
3638 /// Adding fields to table my_pages
3639 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3640 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, 0);
3641 $table->add_field('name', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
3642 $table->add_field('private', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
3643 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3646 /// Adding keys to table my_pages
3647 $table->add_key('id', XMLDB_KEY_PRIMARY, array('id'));
3649 /// Adding indexes to table my_pages
3650 $table->add_index('useridprivate', XMLDB_INDEX_NOTUNIQUE, array('userid', 'private'));
3652 /// Conditionally launch create table for my_pages
3653 if (!$dbman->table_exists($table)) {
3654 $dbman->create_table($table);
3657 /// Add two lines of data into this new table. These are the default pages.
3658 $mypage = new object();
3659 $mypage->userid = NULL;
3660 $mypage->name = '__default';
3661 $mypage->private = 0;
3662 $mypage->sortorder = 0;
3663 if (!$DB->record_exists('my_pages', array('userid'=>NULL, 'private'=>0))) {
3664 $DB->insert_record('my_pages', $mypage);
3666 $mypage->private = 1;
3667 if (!$DB->record_exists('my_pages', array('userid'=>NULL, 'private'=>1))) {
3668 $DB->insert_record('my_pages', $mypage);
3671 /// This bit is a "illegal" hack, unfortunately, but there is not a better way to install default
3672 /// blocks right now, since the upgrade function need to be called after core AND plugins upgrade,
3673 /// and there is no such hook yet. Sigh.
3675 if ($mypage = $DB->get_record('my_pages', array('userid'=>NULL, 'private'=>1))) {
3676 if (!$DB->record_exists('block_instances', array('pagetypepattern'=>'my-index', 'parentcontextid'=>SITEID, 'subpagepattern'=>$mypage->id))) {
3678 // No default exist there yet, let's put a few into My Moodle so it's useful.
3680 $blockinstance = new stdClass;
3681 $blockinstance->parentcontextid = SITEID;
3682 $blockinstance->showinsubcontexts = 0;
3683 $blockinstance->pagetypepattern = 'my-index';
3684 $blockinstance->subpagepattern = $mypage->id;
3685 $blockinstance->configdata = '';
3687 $blockinstance->blockname = 'private_files';
3688 $blockinstance->defaultregion = 'side-post';
3689 $blockinstance->defaultweight = 0;
3690 $blockinstanceid = $DB->insert_record('block_instances', $blockinstance);
3691 get_context_instance(CONTEXT_BLOCK, $blockinstanceid);
3693 $blockinstance->blockname = 'online_users';
3694 $blockinstance->defaultregion = 'side-post';
3695 $blockinstance->defaultweight = 1;
3696 $blockinstanceid = $DB->insert_record('block_instances', $blockinstance);
3697 get_context_instance(CONTEXT_BLOCK, $blockinstanceid);
3699 $blockinstance->blockname = 'course_overview';
3700 $blockinstance->defaultregion = 'content';
3701 $blockinstance->defaultweight = 0;
3702 $blockinstanceid = $DB->insert_record('block_instances', $blockinstance);
3703 get_context_instance(CONTEXT_BLOCK, $blockinstanceid);
3707 /// Main savepoint reached
3708 upgrade_main_savepoint(true, 2010050403);
3711 if ($oldversion < 2010051500) {
3713 /// Fix a bad table name that existed for a few days in HEAD
3714 $table = new xmldb_table('published_courses');
3715 if ($dbman->table_exists($table)) {
3716 $dbman->drop_table($table);
3719 /// Define table course_published to be created
3720 $table = new xmldb_table('course_published');
3722 /// Adding fields to table course_published
3723 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3724 $table->add_field('hubid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3725 $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3726 $table->add_field('timepublished', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3727 $table->add_field('enrollable', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
3728 $table->add_field('hubcourseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3730 /// Adding keys to table course_published
3731 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3733 /// Conditionally launch create table for course_published
3734 if (!$dbman->table_exists($table)) {
3735 $dbman->create_table($table);
3738 /// Main savepoint reached
3739 upgrade_main_savepoint(true, 2010051500);
3742 if ($oldversion < 2010051600) {
3744 /// Delete the blocks completely. All the contexts, instances etc were cleaned up above in 2009082800
3745 $DB->delete_records('block', array('name'=>'admin'));
3746 $DB->delete_records('block', array('name'=>'admin_tree'));
3748 /// Main savepoint reached
3749 upgrade_main_savepoint(true, 2010051600);
3752 if ($oldversion < 2010051800) {
3753 // switching to userid in config settings because user names are not unique and reliable enough
3754 if (!empty($CFG->courserequestnotify) and $CFG->courserequestnotify !== '$@NONE@$' and $CFG->courserequestnotify !== '$@ALL@$') {
3755 list($where, $params) = $DB->get_in_or_equal(explode(',', $CFG->courserequestnotify));
3756 $params[] = $CFG->mnet_localhost_id;
3757 $users = $DB->get_fieldset_select('user', 'id', "username $where AND mnethostid = ?", $params);
3759 set_config('courserequestnotify', implode(',', $users));
3761 set_config('courserequestnotify', '$@NONE@$');
3764 upgrade_main_savepoint(true, 2010051800);
3767 if ($oldversion < 2010051801) {
3768 // Update the notifyloginfailures setting.
3769 if ($CFG->notifyloginfailures == 'mainadmin') {
3770 if ($admins = explode(',', $CFG->siteadmins)) {
3771 $adminid = reset($admins);
3772 set_config('notifyloginfailures', $adminid);
3774 unset_config('notifyloginfailures'); // let them choose
3778 } else if ($CFG->notifyloginfailures == 'alladmins') {
3779 set_config('notifyloginfailures', '$@ALL@$');
3782 set_config('notifyloginfailures', '$@NONE@$');
3785 upgrade_main_savepoint(true, 2010051801);
3788 if ($oldversion < 2010052100) {
3789 // Switch to html purifier as default cleaning engine - KSES is really very bad
3790 if (empty($CFG->enablehtmlpurifier)) {
3791 unset_config('enablehtmlpurifier');
3793 upgrade_main_savepoint(true, 2010052100);
3796 if ($oldversion < 2010052200) {
3797 // Define field legacyfiles to be added to course - just in case we are upgrading from PR1
3798 $table = new xmldb_table('course');
3799 $field = new xmldb_field('legacyfiles', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'maxbytes');
3801 // Conditionally launch add field legacyfiles
3802 if (!$dbman->field_exists($table, $field)) {
3803 $dbman->add_field($table, $field);
3804 // enable legacy files in all courses
3805 $DB->execute("UPDATE {course} SET legacyfiles = 2");
3808 // Main savepoint reached
3809 upgrade_main_savepoint(true, 2010052200);
3812 if ($oldversion < 2010052401) {
3814 /// Define field status to be added to course_published
3815 $table = new xmldb_table('course_published');
3816 $field = new xmldb_field('status', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0', 'hubcourseid');
3818 /// Conditionally launch add field status
3819 if (!$dbman->field_exists($table, $field)) {
3820 $dbman->add_field($table, $field);
3823 /// Define field timechecked to be added to course_published
3824 $table = new xmldb_table('course_published');
3825 $field = new xmldb_field('timechecked', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'status');
3827 /// Conditionally launch add field timechecked
3828 if (!$dbman->field_exists($table, $field)) {
3829 $dbman->add_field($table, $field);
3832 /// Main savepoint reached
3833 upgrade_main_savepoint(true, 2010052401);
3836 if ($oldversion < 2010052700) {
3838 /// Define field summaryformat to be added to course sections table
3839 $table = new xmldb_table('course_sections');
3840 $field = new xmldb_field('summaryformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'summary');
3842 /// Conditionally launch add field summaryformat
3843 if (!$dbman->field_exists($table, $field)) {
3844 $dbman->add_field($table, $field);
3847 /// Main savepoint reached
3848 upgrade_main_savepoint(true, 2010052700);
3851 if ($oldversion < 2010052800) {
3852 /// Changes to modinfo mean we need to rebuild course cache
3853 require_once($CFG->dirroot . '/course/lib.php');
3854 rebuild_course_cache(0, true);
3855 upgrade_main_savepoint(true, 2010052800);
3858 if ($oldversion < 2010052801) {
3860 /// Define field sortorder to be added to files
3861 $table = new xmldb_table('files');
3862 $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timemodified');
3864 /// Conditionally launch add field sortorder
3865 if (!$dbman->field_exists($table, $field)) {
3866 $dbman->add_field($table, $field);
3869 /// Main savepoint reached
3870 upgrade_main_savepoint(true, 2010052801);
3873 if ($oldversion < 2010061900.01) {
3874 // Define table enrol to be created
3875 $table = new xmldb_table('enrol');
3877 // Adding fields to table enrol
3878 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3879 $table->add_field('enrol', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null);
3880 $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3881 $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3882 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3883 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null);
3884 $table->add_field('enrolperiod', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
3885 $table->add_field('enrolstartdate', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
3886 $table->add_field('enrolenddate', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
3887 $table->add_field('expirynotify', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0');
3888 $table->add_field('expirythreshold', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
3889 $table->add_field('notifyall', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0');
3890 $table->add_field('password', XMLDB_TYPE_CHAR, '50', null, null, null, null);
3891 $table->add_field('cost', XMLDB_TYPE_CHAR, '20', null, null, null, null);
3892 $table->add_field('currency', XMLDB_TYPE_CHAR, '3', null, null, null, null);
3893 $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
3894 $table->add_field('customint1', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
3895 $table->add_field('customint2', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
3896 $table->add_field('customint3', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
3897 $table->add_field('customint4', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
3898 $table->add_field('customchar1', XMLDB_TYPE_CHAR, '255', null, null, null, null);
3899 $table->add_field('customchar2', XMLDB_TYPE_CHAR, '255', null, null, null, null);
3900 $table->add_field('customdec1', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null);
3901 $table->add_field('customdec2', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null);
3902 $table->add_field('customtext1', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
3903 $table->add_field('customtext2', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
3904 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3905 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3907 // Adding keys to table enrol
3908 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3909 $table->add_key('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
3911 // Adding indexes to table enrol
3912 $table->add_index('enrol', XMLDB_INDEX_NOTUNIQUE, array('enrol'));
3914 // launch create table for enrol
3915 $dbman->create_table($table);
3917 // Main savepoint reached
3918 upgrade_main_savepoint(true, 2010061900.01);
3921 if ($oldversion < 2010061900.02) {
3922 // Define table course_participant to be created
3923 $table = new xmldb_table('user_enrolments');
3925 // Adding fields to table course_participant
3926 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
3927 $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3928 $table->add_field('enrolid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3929 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
3930 $table->add_field('timestart', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3931 $table->add_field('timeend', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '2147483647');
3932 $table->add_field('modifierid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3933 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
3935 // Adding keys to table course_participant
3936 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3937 $table->add_key('enrolid', XMLDB_KEY_FOREIGN, array('enrolid'), 'enrol', array('id'));
3938 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
3939 $table->add_key('modifierid', XMLDB_KEY_FOREIGN, array('modifierid'), 'user', array('id'));
3942 // Adding indexes to table user_enrolments
3943 $table->add_index('enrolid-userid', XMLDB_INDEX_UNIQUE, array('enrolid', 'userid'));
3945 // Launch create table for course_participant
3946 $dbman->create_table($table);
3948 // Main savepoint reached
3949 upgrade_main_savepoint(true, 2010061900.02);
3952 if ($oldversion < 2010061900.03) {
3953 // Define field itemid to be added to role_assignments
3954 $table = new xmldb_table('role_assignments');
3955 $field = new xmldb_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'enrol');
3957 // Launch add field itemid
3958 $dbman->add_field($table, $field);
3960 // The new enrol plugins may assign one role several times in one context,
3961 // if we did not allow it we would have big problems with roles when unenrolling
3962 $table = new xmldb_table('role_assignments');
3963 $index = new xmldb_index('contextid-roleid-userid', XMLDB_INDEX_UNIQUE, array('contextid', 'roleid', 'userid'));
3965 // Conditionally launch drop index contextid-roleid-userid
3966 if ($dbman->index_exists($table, $index)) {
3967 $dbman->drop_index($table, $index);
3970 // Main savepoint reached
3971 upgrade_main_savepoint(true, 2010061900.03);
3974 if ($oldversion < 2010061900.04) {
3975 // there is no default course role any more, each enrol plugin has to handle it separately
3976 if (!empty($CFG->defaultcourseroleid)) {
3977 $sql = "UPDATE {course} SET defaultrole = :default WHERE defaultrole = 0";
3978 $params = array('default' => $CFG->defaultcourseroleid);
3979 $DB->execute($sql, $params);
3981 unset_config('defaultcourseroleid');
3983 // Main savepoint reached
3984 upgrade_main_savepoint(true, 2010061900.04);
3987 if ($oldversion < 2010061900.05) {
3988 // make sure enrol settings make actually sense and tweak defaults a bit
3990 $sqlempty = $DB->sql_empty();
3992 // set course->enrol to default value so that other upgrade code is simpler