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 installtion 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 functions defined in lib/ddllib.php
20 function xmldb_main_upgrade($oldversion=0) {
22 global $CFG, $THEME, $USER, $db;
26 ////////////////////////////////////////
27 ///upgrade supported only from 1.9.x ///
28 ////////////////////////////////////////
30 if ($result && $oldversion < 2008030700) {
32 /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters
33 $table = new XMLDBTable('grade_letters');
34 $index = new XMLDBIndex('contextid-lowerboundary');
35 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
37 /// Launch drop index contextid-lowerboundary
38 $result = $result && drop_index($table, $index);
40 /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
41 $table = new XMLDBTable('grade_letters');
42 $index = new XMLDBIndex('contextid-lowerboundary-letter');
43 $index->setAttributes(XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
45 /// Launch add index contextid-lowerboundary-letter
46 $result = $result && add_index($table, $index);
48 /// Main savepoint reached
49 upgrade_main_savepoint($result, 2008030700);
52 if ($result && $oldversion < 2008050100) {
53 // Update courses that used weekscss to weeks
54 $result = set_field('course', 'format', 'weeks', 'format', 'weekscss');
55 upgrade_main_savepoint($result, 2008050100);
58 if ($result && $oldversion < 2008050200) {
59 // remove unused config options
60 unset_config('statsrolesupgraded');
61 upgrade_main_savepoint($result, 2008050200);
64 if ($result && $oldversion < 2008050700) {
65 /// Fix minor problem caused by MDL-5482.
66 require_once($CFG->dirroot . '/question/upgrade.php');
67 $result = $result && question_fix_random_question_parents();
68 upgrade_main_savepoint($result, 2008050700);
71 if ($result && $oldversion < 2008051200) {
72 // if guest role used as default user role unset it and force admin to choose new setting
73 if (!empty($CFG->defaultuserroleid)) {
74 if ($role = get_record('role', 'id', $CFG->defaultuserroleid)) {
75 if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
76 if (isset($guestroles[$role->id])) {
77 set_config('defaultuserroleid', null);
78 notify('Guest role removed from "Default role for all users" setting, please select another role.', 'notifysuccess');
82 set_config('defaultuserroleid', null);
87 if ($result && $oldversion < 2008051201) {
88 notify('Increasing size of user idnumber field, this may take a while...', 'notifysuccess');
90 /// Define index idnumber (not unique) to be dropped form user
91 $table = new XMLDBTable('user');
92 $index = new XMLDBIndex('idnumber');
93 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
95 /// Launch drop index idnumber
96 if (index_exists($table, $index)) {
97 $result = $result && drop_index($table, $index);
100 /// Changing precision of field idnumber on table user to (255)
101 $table = new XMLDBTable('user');
102 $field = new XMLDBField('idnumber');
103 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'password');
105 /// Launch change of precision for field idnumber
106 $result = $result && change_field_precision($table, $field);
108 /// Launch add index idnumber again
109 $index = new XMLDBIndex('idnumber');
110 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
111 $result = $result && add_index($table, $index);
113 /// Main savepoint reached
114 upgrade_main_savepoint($result, 2008051201);