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 | |
20 | function 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 | |
38fb8190 |
137 | if ($result && $oldversion < 2008063001) { |
138 | // table to be modified |
139 | $table = new xmldb_table('tag_instance'); |
140 | // add field |
141 | $field = new xmldb_field('tiuserid'); |
142 | if (!$dbman->field_exists($table, $field)) { |
143 | $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0, 'itemid'); |
144 | $dbman->add_field($table, $field); |
145 | } |
146 | // modify index |
147 | $index = new xmldb_index('itemtype-itemid-tagid'); |
148 | $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid')); |
149 | $dbman->drop_index($table, $index); |
150 | $index = new xmldb_index('itemtype-itemid-tagid-tiuserid'); |
151 | $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid')); |
152 | $dbman->add_index($table, $index); |
153 | |
154 | /// Main savepoint reached |
155 | upgrade_main_savepoint($result, 2008063001); |
156 | } |
98978c2e |
157 | if ($result && $oldversion < 2008063002) { |
158 | |
159 | /// Define table repository to be created |
160 | $table = new xmldb_table('repository'); |
161 | |
162 | /// Adding fields to table repository |
163 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
164 | $table->add_field('repositoryname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); |
165 | $table->add_field('repositorytype', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
166 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); |
167 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
168 | $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); |
169 | $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); |
170 | $table->add_field('data1', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); |
171 | $table->add_field('data2', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); |
172 | $table->add_field('data3', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); |
173 | $table->add_field('data4', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); |
174 | $table->add_field('data5', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); |
175 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); |
176 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); |
177 | |
178 | /// Adding keys to table repository |
179 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
180 | |
181 | /// Conditionally launch create table for repository |
182 | if (!$dbman->table_exists($table)) { |
183 | $dbman->create_table($table); |
184 | } |
38fb8190 |
185 | |
98978c2e |
186 | /// Main savepoint reached |
187 | upgrade_main_savepoint($result, 2008063002); |
188 | } |
38fb8190 |
189 | |
a036d7f3 |
190 | if ($result && $oldversion < 2008070300) { |
191 | $result = $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false)); |
192 | upgrade_main_savepoint($result, 2008070300); |
193 | } |
194 | |
fe074586 |
195 | if ($result && $oldversion < 2008070700) { |
196 | if (isset($CFG->defaultuserroleid) and isset($CFG->guestroleid) and $CFG->defaultuserroleid == $CFG->guestroleid) { |
197 | // guest can not be selected in defaultuserroleid! |
198 | unset_config('defaultuserroleid'); |
199 | } |
200 | upgrade_main_savepoint($result, 2008070700); |
201 | } |
202 | |
f33e1ed4 |
203 | /* |
204 | * TODO: |
eb636785 |
205 | * drop adodb_logsql table and create a new general sql log table |
f33e1ed4 |
206 | * |
207 | */ |
208 | |
ac9b0805 |
209 | return $result; |
4e423cbf |
210 | } |
271e6dec |
211 | |
212 | |
4e423cbf |
213 | ?> |