"MDL-15350, boxnet plug-in worked now"
[moodle.git] / lib / db / upgrade.php
CommitLineData
4e423cbf 1<?PHP //$Id$
2
3// This file keeps track of upgrades to Moodle.
4//
5// Sometimes, changes between versions involve
6// alterations to database structures and other
7// major things that may break installations.
8//
9// The upgrade function in this file will attempt
10// to perform all the necessary actions to upgrade
11// your older installtion to the current version.
12//
13// If there's something it cannot do itself, it
14// will tell you what you need to do.
15//
16// The commands in here will all be database-neutral,
b1f93b15 17// using the methods of database_manager class
4e423cbf 18
19
20function xmldb_main_upgrade($oldversion=0) {
f33e1ed4 21 global $CFG, $THEME, $USER, $DB;
4e423cbf 22
23 $result = true;
24
46d318bc 25 $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
f33e1ed4 26
1ea260d8 27 ////////////////////////////////////////
28 ///upgrade supported only from 1.9.x ///
29 ////////////////////////////////////////
da4aa3e4 30
a1f27717 31 if ($result && $oldversion < 2008030700) {
32
33 /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters
a8cb94f6 34 $table = new xmldb_table('grade_letters');
69b80cc2 35 $index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
a1f27717 36
37 /// Launch drop index contextid-lowerboundary
eee5d9bb 38 $dbman->drop_index($table, $index);
a1f27717 39
a1f27717 40 /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
a8cb94f6 41 $table = new xmldb_table('grade_letters');
69b80cc2 42 $index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
a1f27717 43
44 /// Launch add index contextid-lowerboundary-letter
eee5d9bb 45 $dbman->add_index($table, $index);
a1f27717 46
47 /// Main savepoint reached
0f77b186 48 upgrade_main_savepoint($result, 2008030700);
49 }
a1f27717 50
1ea260d8 51 if ($result && $oldversion < 2008050100) {
52 // Update courses that used weekscss to weeks
a8cb94f6 53 $result = $DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss'));
1ea260d8 54 upgrade_main_savepoint($result, 2008050100);
55 }
56
0b51c247 57 if ($result && $oldversion < 2008050200) {
58 // remove unused config options
59 unset_config('statsrolesupgraded');
60 upgrade_main_savepoint($result, 2008050200);
61 }
62
994fbaab 63 if ($result && $oldversion < 2008050700) {
64 /// Fix minor problem caused by MDL-5482.
65 require_once($CFG->dirroot . '/question/upgrade.php');
66 $result = $result && question_fix_random_question_parents();
67 upgrade_main_savepoint($result, 2008050700);
68 }
69
ab37dc60 70 if ($result && $oldversion < 2008051200) {
71 // if guest role used as default user role unset it and force admin to choose new setting
72 if (!empty($CFG->defaultuserroleid)) {
910dd4dd 73 if ($role = $DB->get_record('role', array('id'=>$CFG->defaultuserroleid))) {
ab37dc60 74 if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
75 if (isset($guestroles[$role->id])) {
76 set_config('defaultuserroleid', null);
77 notify('Guest role removed from "Default role for all users" setting, please select another role.', 'notifysuccess');
78 }
79 }
80 } else {
81 set_config('defaultuserroleid', null);
82 }
83 }
84 }
85
8b9cfac4 86 if ($result && $oldversion < 2008051201) {
87 notify('Increasing size of user idnumber field, this may take a while...', 'notifysuccess');
88
469dcbcc 89 /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859
90 if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') {
eee5d9bb 91 $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL");
469dcbcc 92 }
93
8b9cfac4 94 /// Define index idnumber (not unique) to be dropped form user
a8cb94f6 95 $table = new xmldb_table('user');
69b80cc2 96 $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
8b9cfac4 97
98 /// Launch drop index idnumber
f33e1ed4 99 if ($dbman->index_exists($table, $index)) {
eee5d9bb 100 $dbman->drop_index($table, $index);
8b9cfac4 101 }
102
103 /// Changing precision of field idnumber on table user to (255)
a8cb94f6 104 $table = new xmldb_table('user');
69b80cc2 105 $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'password');
8b9cfac4 106
107 /// Launch change of precision for field idnumber
eee5d9bb 108 $dbman->change_field_precision($table, $field);
8b9cfac4 109
110 /// Launch add index idnumber again
69b80cc2 111 $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
eee5d9bb 112 $dbman->add_index($table, $index);
8b9cfac4 113
114 /// Main savepoint reached
115 upgrade_main_savepoint($result, 2008051201);
116 }
117
7ade55ad 118 if ($result && $oldversion < 2008051202) {
910dd4dd 119 $log_action = new object();
7ade55ad 120 $log_action->module = 'course';
121 $log_action->action = 'unenrol';
122 $log_action->mtable = 'course';
123 $log_action->field = 'fullname';
910dd4dd 124 if (!$DB->record_exists('log_display', array('action'=>'unenrol', 'module'=>'course'))) {
125 $result = $result && $DB->insert_record('log_display', $log_action);
7ade55ad 126 }
127 upgrade_main_savepoint($result, 2008051202);
128 }
129
fa162144 130 if ($result && $oldversion < 2008051203) {
131 $table = new xmldb_table('mnet_enrol_course');
132 $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', true, true, null, false, false, 0);
eee5d9bb 133 $dbman->change_field_precision($table, $field);
fa162144 134 upgrade_main_savepoint($result, 2008051203);
135 }
136
f33e1ed4 137/*
138 * TODO:
eb636785 139 * drop adodb_logsql table and create a new general sql log table
f33e1ed4 140 *
141 */
142
ac9b0805 143 return $result;
4e423cbf 144}
271e6dec 145
146
4e423cbf 147?>