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 |
775f811a |
18 | // |
19 | // Please do not forget to use upgrade_set_timeout() |
20 | // before any action that may take longer time to finish. |
4e423cbf |
21 | |
775f811a |
22 | function xmldb_main_upgrade($oldversion) { |
f33e1ed4 |
23 | global $CFG, $THEME, $USER, $DB; |
4e423cbf |
24 | |
4f12838e |
25 | require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions |
26 | |
4e423cbf |
27 | $result = true; |
28 | |
46d318bc |
29 | $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes |
f33e1ed4 |
30 | |
1ea260d8 |
31 | //////////////////////////////////////// |
32 | ///upgrade supported only from 1.9.x /// |
33 | //////////////////////////////////////// |
da4aa3e4 |
34 | |
795a08ad |
35 | if ($result && $oldversion < 2008030600) { |
36 | //NOTE: this table was added much later, that is why this step is repeated later in this file |
37 | |
38 | /// Define table upgrade_log to be created |
39 | $table = new xmldb_table('upgrade_log'); |
40 | |
41 | /// Adding fields to table upgrade_log |
2a88f626 |
42 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
43 | $table->add_field('type', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
44 | $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null); |
45 | $table->add_field('version', XMLDB_TYPE_CHAR, '100', null, null, null, null); |
46 | $table->add_field('info', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
47 | $table->add_field('details', XMLDB_TYPE_TEXT, 'small', null, null, null, null); |
48 | $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null); |
49 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
50 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
795a08ad |
51 | |
52 | /// Adding keys to table upgrade_log |
53 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
54 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
55 | |
56 | /// Adding indexes to table upgrade_log |
57 | $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified')); |
58 | $table->add_index('type-timemodified', XMLDB_INDEX_NOTUNIQUE, array('type', 'timemodified')); |
59 | |
60 | /// Create table for upgrade_log |
61 | $dbman->create_table($table); |
62 | |
63 | /// Main savepoint reached |
64 | upgrade_main_savepoint($result, 2008030600); |
65 | } |
66 | |
a1f27717 |
67 | if ($result && $oldversion < 2008030700) { |
775f811a |
68 | upgrade_set_timeout(60*20); // this may take a while |
a1f27717 |
69 | |
70 | /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters |
a8cb94f6 |
71 | $table = new xmldb_table('grade_letters'); |
69b80cc2 |
72 | $index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary')); |
a1f27717 |
73 | |
74 | /// Launch drop index contextid-lowerboundary |
eee5d9bb |
75 | $dbman->drop_index($table, $index); |
a1f27717 |
76 | |
a1f27717 |
77 | /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters |
a8cb94f6 |
78 | $table = new xmldb_table('grade_letters'); |
69b80cc2 |
79 | $index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter')); |
a1f27717 |
80 | |
81 | /// Launch add index contextid-lowerboundary-letter |
eee5d9bb |
82 | $dbman->add_index($table, $index); |
a1f27717 |
83 | |
84 | /// Main savepoint reached |
0f77b186 |
85 | upgrade_main_savepoint($result, 2008030700); |
86 | } |
a1f27717 |
87 | |
1ea260d8 |
88 | if ($result && $oldversion < 2008050100) { |
89 | // Update courses that used weekscss to weeks |
a8cb94f6 |
90 | $result = $DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss')); |
1ea260d8 |
91 | upgrade_main_savepoint($result, 2008050100); |
92 | } |
93 | |
0b51c247 |
94 | if ($result && $oldversion < 2008050200) { |
95 | // remove unused config options |
96 | unset_config('statsrolesupgraded'); |
97 | upgrade_main_savepoint($result, 2008050200); |
98 | } |
99 | |
994fbaab |
100 | if ($result && $oldversion < 2008050700) { |
775f811a |
101 | upgrade_set_timeout(60*20); // this may take a while |
102 | |
994fbaab |
103 | /// Fix minor problem caused by MDL-5482. |
104 | require_once($CFG->dirroot . '/question/upgrade.php'); |
105 | $result = $result && question_fix_random_question_parents(); |
106 | upgrade_main_savepoint($result, 2008050700); |
107 | } |
108 | |
ab37dc60 |
109 | if ($result && $oldversion < 2008051200) { |
110 | // if guest role used as default user role unset it and force admin to choose new setting |
111 | if (!empty($CFG->defaultuserroleid)) { |
910dd4dd |
112 | if ($role = $DB->get_record('role', array('id'=>$CFG->defaultuserroleid))) { |
ab37dc60 |
113 | if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) { |
114 | if (isset($guestroles[$role->id])) { |
115 | set_config('defaultuserroleid', null); |
116 | notify('Guest role removed from "Default role for all users" setting, please select another role.', 'notifysuccess'); |
117 | } |
118 | } |
119 | } else { |
120 | set_config('defaultuserroleid', null); |
121 | } |
122 | } |
a54e1638 |
123 | /// Main savepoint reached |
124 | upgrade_main_savepoint($result, 2008051200); |
ab37dc60 |
125 | } |
126 | |
8b9cfac4 |
127 | if ($result && $oldversion < 2008051201) { |
128 | notify('Increasing size of user idnumber field, this may take a while...', 'notifysuccess'); |
775f811a |
129 | upgrade_set_timeout(60*20); // this may take a while |
8b9cfac4 |
130 | |
469dcbcc |
131 | /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859 |
cbc08f3b |
132 | $dbfamily = $DB->get_dbfamily(); |
133 | if ($dbfamily === 'mysql' || $dbfamily === 'postgres') { |
eee5d9bb |
134 | $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL"); |
469dcbcc |
135 | } |
136 | |
8b9cfac4 |
137 | /// Define index idnumber (not unique) to be dropped form user |
a8cb94f6 |
138 | $table = new xmldb_table('user'); |
69b80cc2 |
139 | $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber')); |
8b9cfac4 |
140 | |
141 | /// Launch drop index idnumber |
f33e1ed4 |
142 | if ($dbman->index_exists($table, $index)) { |
eee5d9bb |
143 | $dbman->drop_index($table, $index); |
8b9cfac4 |
144 | } |
145 | |
146 | /// Changing precision of field idnumber on table user to (255) |
a8cb94f6 |
147 | $table = new xmldb_table('user'); |
2a88f626 |
148 | $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'password'); |
8b9cfac4 |
149 | |
150 | /// Launch change of precision for field idnumber |
eee5d9bb |
151 | $dbman->change_field_precision($table, $field); |
8b9cfac4 |
152 | |
153 | /// Launch add index idnumber again |
69b80cc2 |
154 | $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber')); |
eee5d9bb |
155 | $dbman->add_index($table, $index); |
8b9cfac4 |
156 | |
157 | /// Main savepoint reached |
158 | upgrade_main_savepoint($result, 2008051201); |
159 | } |
160 | |
7ade55ad |
161 | if ($result && $oldversion < 2008051202) { |
910dd4dd |
162 | $log_action = new object(); |
7ade55ad |
163 | $log_action->module = 'course'; |
164 | $log_action->action = 'unenrol'; |
165 | $log_action->mtable = 'course'; |
166 | $log_action->field = 'fullname'; |
910dd4dd |
167 | if (!$DB->record_exists('log_display', array('action'=>'unenrol', 'module'=>'course'))) { |
168 | $result = $result && $DB->insert_record('log_display', $log_action); |
7ade55ad |
169 | } |
170 | upgrade_main_savepoint($result, 2008051202); |
171 | } |
172 | |
fa162144 |
173 | if ($result && $oldversion < 2008051203) { |
174 | $table = new xmldb_table('mnet_enrol_course'); |
2a88f626 |
175 | $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0); |
eee5d9bb |
176 | $dbman->change_field_precision($table, $field); |
fa162144 |
177 | upgrade_main_savepoint($result, 2008051203); |
178 | } |
179 | |
38fb8190 |
180 | if ($result && $oldversion < 2008063001) { |
775f811a |
181 | upgrade_set_timeout(60*20); // this may take a while |
182 | |
38fb8190 |
183 | // table to be modified |
184 | $table = new xmldb_table('tag_instance'); |
185 | // add field |
186 | $field = new xmldb_field('tiuserid'); |
187 | if (!$dbman->field_exists($table, $field)) { |
2a88f626 |
188 | $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'itemid'); |
38fb8190 |
189 | $dbman->add_field($table, $field); |
190 | } |
191 | // modify index |
192 | $index = new xmldb_index('itemtype-itemid-tagid'); |
193 | $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid')); |
b91de8a5 |
194 | if ($dbman->index_exists($table, $index)) { |
195 | $dbman->drop_index($table, $index); |
196 | } |
38fb8190 |
197 | $index = new xmldb_index('itemtype-itemid-tagid-tiuserid'); |
198 | $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid')); |
b91de8a5 |
199 | if (!$dbman->index_exists($table, $index)) { |
200 | $dbman->add_index($table, $index); |
201 | } |
38fb8190 |
202 | |
203 | /// Main savepoint reached |
204 | upgrade_main_savepoint($result, 2008063001); |
205 | } |
38fb8190 |
206 | |
a036d7f3 |
207 | if ($result && $oldversion < 2008070300) { |
208 | $result = $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false)); |
209 | upgrade_main_savepoint($result, 2008070300); |
210 | } |
4e781c7b |
211 | |
fe074586 |
212 | if ($result && $oldversion < 2008070700) { |
213 | if (isset($CFG->defaultuserroleid) and isset($CFG->guestroleid) and $CFG->defaultuserroleid == $CFG->guestroleid) { |
214 | // guest can not be selected in defaultuserroleid! |
215 | unset_config('defaultuserroleid'); |
216 | } |
217 | upgrade_main_savepoint($result, 2008070700); |
218 | } |
219 | |
ac5efef6 |
220 | if ($result && $oldversion < 2008070701) { |
221 | |
222 | /// Define table portfolio_instance to be created |
223 | $table = new xmldb_table('portfolio_instance'); |
224 | |
225 | /// Adding fields to table portfolio_instance |
2a88f626 |
226 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
227 | $table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null); |
228 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
229 | $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); |
ac5efef6 |
230 | |
231 | /// Adding keys to table portfolio_instance |
232 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
233 | |
234 | /// Conditionally launch create table for portfolio_instance |
235 | if (!$dbman->table_exists($table)) { |
236 | $dbman->create_table($table); |
237 | } |
238 | /// Define table portfolio_instance_config to be created |
239 | $table = new xmldb_table('portfolio_instance_config'); |
240 | |
241 | /// Adding fields to table portfolio_instance_config |
2a88f626 |
242 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
243 | $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
244 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
245 | $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null); |
ac5efef6 |
246 | |
247 | /// Adding keys to table portfolio_instance_config |
248 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
249 | $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id')); |
250 | |
251 | /// Adding indexes to table portfolio_instance_config |
252 | $table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name')); |
253 | |
254 | /// Conditionally launch create table for portfolio_instance_config |
255 | if (!$dbman->table_exists($table)) { |
256 | $dbman->create_table($table); |
257 | } |
258 | |
259 | /// Define table portfolio_instance_user to be created |
260 | $table = new xmldb_table('portfolio_instance_user'); |
261 | |
262 | /// Adding fields to table portfolio_instance_user |
2a88f626 |
263 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); |
264 | $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
265 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
266 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
267 | $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null); |
ac5efef6 |
268 | |
269 | /// Adding keys to table portfolio_instance_user |
270 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
271 | $table->add_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id')); |
272 | $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
273 | |
274 | /// Conditionally launch create table for portfolio_instance_user |
275 | if (!$dbman->table_exists($table)) { |
276 | $dbman->create_table($table); |
277 | } |
278 | |
279 | /// Main savepoint reached |
280 | upgrade_main_savepoint($result, 2008070701); |
281 | } |
172dd12c |
282 | |
775f811a |
283 | if ($result && $oldversion < 2008072400) { |
284 | /// Create the database tables for message_processors |
f65b2dae |
285 | $table = new xmldb_table('message_processors'); |
2a88f626 |
286 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
287 | $table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null); |
f65b2dae |
288 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
3b120e46 |
289 | $dbman->create_table($table); |
290 | |
3b120e46 |
291 | /// delete old and create new fields |
f65b2dae |
292 | $table = new xmldb_table('message'); |
293 | $field = new xmldb_field('messagetype'); |
3b120e46 |
294 | $dbman->drop_field($table, $field); |
295 | |
296 | /// fields to rename |
f65b2dae |
297 | $field = new xmldb_field('message'); |
2a88f626 |
298 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); |
3b120e46 |
299 | $dbman->rename_field($table, $field, 'fullmessage'); |
f65b2dae |
300 | $field = new xmldb_field('format'); |
2a88f626 |
301 | $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null); |
3b120e46 |
302 | $dbman->rename_field($table, $field, 'fullmessageformat'); |
303 | |
304 | /// new message fields |
f65b2dae |
305 | $field = new xmldb_field('subject'); |
2a88f626 |
306 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); |
3b120e46 |
307 | $dbman->add_field($table, $field); |
f65b2dae |
308 | $field = new xmldb_field('fullmessagehtml'); |
2a88f626 |
309 | $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null); |
3b120e46 |
310 | $dbman->add_field($table, $field); |
f65b2dae |
311 | $field = new xmldb_field('smallmessage'); |
2a88f626 |
312 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); |
3b120e46 |
313 | $dbman->add_field($table, $field); |
314 | |
315 | |
f65b2dae |
316 | $table = new xmldb_table('message_read'); |
317 | $field = new xmldb_field('messagetype'); |
3b120e46 |
318 | $dbman->drop_field($table, $field); |
f65b2dae |
319 | $field = new xmldb_field('mailed'); |
3b120e46 |
320 | $dbman->drop_field($table, $field); |
321 | |
322 | /// fields to rename |
f65b2dae |
323 | $field = new xmldb_field('message'); |
2a88f626 |
324 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); |
3b120e46 |
325 | $dbman->rename_field($table, $field, 'fullmessage'); |
f65b2dae |
326 | $field = new xmldb_field('format'); |
2a88f626 |
327 | $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null); |
3b120e46 |
328 | $dbman->rename_field($table, $field, 'fullmessageformat'); |
329 | |
330 | |
331 | /// new message fields |
f65b2dae |
332 | $field = new xmldb_field('subject'); |
2a88f626 |
333 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); |
3b120e46 |
334 | $dbman->add_field($table, $field); |
f65b2dae |
335 | $field = new xmldb_field('fullmessagehtml'); |
2a88f626 |
336 | $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null); |
3b120e46 |
337 | $dbman->add_field($table, $field); |
f65b2dae |
338 | $field = new xmldb_field('smallmessage'); |
2a88f626 |
339 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); |
3b120e46 |
340 | $dbman->add_field($table, $field); |
341 | |
342 | /// new table |
f65b2dae |
343 | $table = new xmldb_table('message_working'); |
2a88f626 |
344 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
345 | $table->add_field('unreadmessageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
346 | $table->add_field('processorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
f65b2dae |
347 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
3b120e46 |
348 | $dbman->create_table($table); |
349 | |
350 | |
351 | upgrade_main_savepoint($result, 2008072400); |
352 | } |
353 | |
4e781c7b |
354 | if ($result && $oldversion < 2008072800) { |
355 | |
356 | /// Define field enablecompletion to be added to course |
357 | $table = new xmldb_table('course'); |
358 | $field = new xmldb_field('enablecompletion'); |
2a88f626 |
359 | $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'defaultrole'); |
4e781c7b |
360 | |
361 | /// Launch add field enablecompletion |
775f811a |
362 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
363 | $dbman->add_field($table, $field); |
364 | } |
775f811a |
365 | |
4e781c7b |
366 | /// Define field completion to be added to course_modules |
367 | $table = new xmldb_table('course_modules'); |
368 | $field = new xmldb_field('completion'); |
2a88f626 |
369 | $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'groupmembersonly'); |
4e781c7b |
370 | |
371 | /// Launch add field completion |
775f811a |
372 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
373 | $dbman->add_field($table, $field); |
374 | } |
375 | |
376 | /// Define field completiongradeitemnumber to be added to course_modules |
377 | $field = new xmldb_field('completiongradeitemnumber'); |
2a88f626 |
378 | $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'completion'); |
4e781c7b |
379 | |
380 | /// Launch add field completiongradeitemnumber |
775f811a |
381 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
382 | $dbman->add_field($table, $field); |
383 | } |
384 | |
385 | /// Define field completionview to be added to course_modules |
386 | $field = new xmldb_field('completionview'); |
2a88f626 |
387 | $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completiongradeitemnumber'); |
4e781c7b |
388 | |
389 | /// Launch add field completionview |
775f811a |
390 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
391 | $dbman->add_field($table, $field); |
392 | } |
393 | |
394 | /// Define field completionexpected to be added to course_modules |
395 | $field = new xmldb_field('completionexpected'); |
2a88f626 |
396 | $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionview'); |
4e781c7b |
397 | |
398 | /// Launch add field completionexpected |
775f811a |
399 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
400 | $dbman->add_field($table, $field); |
401 | } |
402 | |
403 | /// Define table course_modules_completion to be created |
404 | $table = new xmldb_table('course_modules_completion'); |
775f811a |
405 | if (!$dbman->table_exists($table)) { |
4e781c7b |
406 | |
407 | /// Adding fields to table course_modules_completion |
2a88f626 |
408 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
409 | $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
410 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
411 | $table->add_field('completionstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
412 | $table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null); |
413 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
775f811a |
414 | |
4e781c7b |
415 | /// Adding keys to table course_modules_completion |
1e0c56ea |
416 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
775f811a |
417 | |
4e781c7b |
418 | /// Adding indexes to table course_modules_completion |
1e0c56ea |
419 | $table->add_index('coursemoduleid', XMLDB_INDEX_NOTUNIQUE, array('coursemoduleid')); |
420 | $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); |
775f811a |
421 | |
4e781c7b |
422 | /// Launch create table for course_modules_completion |
423 | $dbman->create_table($table); |
424 | } |
425 | |
426 | /// Main savepoint reached |
427 | upgrade_main_savepoint($result, 2008072800); |
428 | } |
775f811a |
429 | |
4ab16a09 |
430 | if ($result && $oldversion < 2008073000) { |
ac5efef6 |
431 | |
4ab16a09 |
432 | /// Define table portfolio_log to be created |
433 | $table = new xmldb_table('portfolio_log'); |
434 | |
435 | /// Adding fields to table portfolio_log |
2a88f626 |
436 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
437 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
438 | $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
439 | $table->add_field('portfolio', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
440 | $table->add_field('caller_class', XMLDB_TYPE_CHAR, '150', null, XMLDB_NOTNULL, null, null); |
441 | $table->add_field('caller_file', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
442 | $table->add_field('caller_sha1', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
4ab16a09 |
443 | |
444 | /// Adding keys to table portfolio_log |
445 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
446 | $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
447 | $table->add_key('portfoliofk', XMLDB_KEY_FOREIGN, array('portfolio'), 'portfolio_instance', array('id')); |
448 | |
449 | /// Conditionally launch create table for portfolio_log |
450 | if (!$dbman->table_exists($table)) { |
451 | $dbman->create_table($table); |
452 | } |
453 | |
454 | /// Main savepoint reached |
455 | upgrade_main_savepoint($result, 2008073000); |
456 | } |
120b3758 |
457 | |
458 | if ($result && $oldversion < 2008073104) { |
459 | /// Drop old table that might exist for some people |
460 | $table = new xmldb_table('message_providers'); |
461 | if ($dbman->table_exists($table)) { |
462 | $dbman->drop_table($table); |
463 | } |
464 | |
465 | /// Define table message_providers to be created |
466 | $table = new xmldb_table('message_providers'); |
467 | |
468 | /// Adding fields to table message_providers |
2a88f626 |
469 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
470 | $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); |
471 | $table->add_field('component', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null); |
472 | $table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null); |
120b3758 |
473 | |
474 | /// Adding keys to table message_providers |
475 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
476 | |
477 | /// Adding indexes to table message_providers |
478 | $table->add_index('componentname', XMLDB_INDEX_UNIQUE, array('component', 'name')); |
479 | |
480 | /// Create table for message_providers |
481 | $dbman->create_table($table); |
482 | |
483 | upgrade_main_savepoint($result, 2008073104); |
484 | } |
172dd12c |
485 | |
486 | if ($result && $oldversion < 2008073111) { |
487 | /// Define table files to be created |
488 | $table = new xmldb_table('files'); |
489 | |
490 | /// Adding fields to table files |
2a88f626 |
491 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
492 | $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); |
493 | $table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); |
494 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
495 | $table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null); |
496 | $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
497 | $table->add_field('filepath', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
498 | $table->add_field('filename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
499 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); |
500 | $table->add_field('filesize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
501 | $table->add_field('mimetype', XMLDB_TYPE_CHAR, '100', null, null, null, null); |
502 | $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); |
503 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
504 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
172dd12c |
505 | |
506 | /// Adding keys to table files |
507 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
508 | $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); |
509 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
510 | |
511 | /// Adding indexes to table files |
512 | $table->add_index('filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('filearea', 'contextid', 'itemid')); |
513 | $table->add_index('contenthash', XMLDB_INDEX_NOTUNIQUE, array('contenthash')); |
514 | $table->add_index('pathnamehash', XMLDB_INDEX_UNIQUE, array('pathnamehash')); |
515 | |
516 | /// Conditionally launch create table for files |
517 | $dbman->create_table($table); |
518 | |
519 | /// Main savepoint reached |
520 | upgrade_main_savepoint($result, 2008073111); |
521 | } |
522 | |
172dd12c |
523 | if ($result && $oldversion < 2008073113) { |
524 | /// move all course, backup and other files to new filepool based storage |
525 | upgrade_migrate_files_courses(); |
526 | /// Main savepoint reached |
527 | upgrade_main_savepoint($result, 2008073113); |
528 | } |
529 | |
530 | if ($result && $oldversion < 2008073114) { |
531 | /// move all course, backup and other files to new filepool based storage |
532 | upgrade_migrate_files_blog(); |
533 | /// Main savepoint reached |
534 | upgrade_main_savepoint($result, 2008073114); |
535 | } |
f33e1ed4 |
536 | |
1ce2da58 |
537 | if ($result && $oldversion < 2008080400) { |
538 | // Add field ssl_jump_url to mnet application, and populate existing default applications |
539 | $table = new xmldb_table('mnet_application'); |
540 | $field = new xmldb_field('sso_jump_url'); |
541 | if (!$dbman->field_exists($table, $field)) { |
2a88f626 |
542 | $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
c5a04d12 |
543 | $dbman->add_field($table, $field); |
544 | $result = $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle')); |
1ce2da58 |
545 | $result = $result && $DB->set_field('mnet_application', 'sso_jump_url', '/auth/xmlrpc/jump.php', array('name' => 'mahara')); |
546 | } |
547 | |
548 | /// Main savepoint reached |
549 | upgrade_main_savepoint($result, 2008080400); |
550 | } |
04f35360 |
551 | |
552 | if ($result && $oldversion < 2008080500) { |
553 | |
554 | /// Define table portfolio_tempdata to be created |
555 | $table = new xmldb_table('portfolio_tempdata'); |
556 | |
557 | /// Adding fields to table portfolio_tempdata |
2a88f626 |
558 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
559 | $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, null, null, null); |
04f35360 |
560 | |
561 | /// Adding keys to table portfolio_tempdata |
562 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
563 | |
564 | /// Conditionally launch create table for portfolio_tempdata |
565 | if (!$dbman->table_exists($table)) { |
566 | $dbman->create_table($table); |
567 | } |
568 | |
569 | /// Main savepoint reached |
570 | upgrade_main_savepoint($result, 2008080500); |
571 | } |
572 | |
84a44985 |
573 | if ($result && $oldversion < 2008080600) { |
574 | |
575 | $DB->delete_records('portfolio_tempdata'); // there shouldnt' be any, and it will cause problems with this upgrade. |
576 | /// Define field expirytime to be added to portfolio_tempdata |
577 | $table = new xmldb_table('portfolio_tempdata'); |
2a88f626 |
578 | $field = new xmldb_field('expirytime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'data'); |
84a44985 |
579 | |
580 | /// Conditionally launch add field expirytime |
581 | if (!$dbman->field_exists($table, $field)) { |
582 | $dbman->add_field($table, $field); |
583 | } |
584 | |
585 | /// Main savepoint reached |
586 | upgrade_main_savepoint($result, 2008080600); |
587 | } |
775f811a |
588 | |
f9a2cf86 |
589 | /// Changing the type of all the columns that the question bank uses to store grades to be NUMBER(12, 7). |
590 | if ($result && $oldversion < 2008081500) { |
591 | $table = new xmldb_table('question'); |
2a88f626 |
592 | $field = new xmldb_field('defaultgrade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'generalfeedback'); |
f9a2cf86 |
593 | $dbman->change_field_type($table, $field); |
594 | upgrade_main_savepoint($result, 2008081500); |
595 | } |
596 | |
597 | if ($result && $oldversion < 2008081501) { |
598 | $table = new xmldb_table('question'); |
2a88f626 |
599 | $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'defaultgrade'); |
f9a2cf86 |
600 | $dbman->change_field_type($table, $field); |
601 | upgrade_main_savepoint($result, 2008081501); |
602 | } |
603 | |
604 | if ($result && $oldversion < 2008081502) { |
605 | $table = new xmldb_table('question_answers'); |
2a88f626 |
606 | $field = new xmldb_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'answer'); |
f9a2cf86 |
607 | $dbman->change_field_type($table, $field); |
608 | upgrade_main_savepoint($result, 2008081502); |
609 | } |
610 | |
611 | if ($result && $oldversion < 2008081503) { |
612 | $table = new xmldb_table('question_sessions'); |
2a88f626 |
613 | $field = new xmldb_field('sumpenalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'newgraded'); |
f9a2cf86 |
614 | $dbman->change_field_type($table, $field); |
615 | upgrade_main_savepoint($result, 2008081503); |
616 | } |
617 | |
618 | if ($result && $oldversion < 2008081504) { |
619 | $table = new xmldb_table('question_states'); |
2a88f626 |
620 | $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'event'); |
f9a2cf86 |
621 | $dbman->change_field_type($table, $field); |
622 | upgrade_main_savepoint($result, 2008081504); |
623 | } |
624 | |
625 | if ($result && $oldversion < 2008081505) { |
626 | $table = new xmldb_table('question_states'); |
2a88f626 |
627 | $field = new xmldb_field('raw_grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'grade'); |
f9a2cf86 |
628 | $dbman->change_field_type($table, $field); |
629 | upgrade_main_savepoint($result, 2008081505); |
630 | } |
631 | |
632 | if ($result && $oldversion < 2008081506) { |
633 | $table = new xmldb_table('question_states'); |
2a88f626 |
634 | $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'raw_grade'); |
f9a2cf86 |
635 | $dbman->change_field_type($table, $field); |
636 | upgrade_main_savepoint($result, 2008081506); |
637 | } |
638 | |
775f811a |
639 | if ($result && $oldversion < 2008081600) { |
640 | |
641 | /// all 1.9 sites and fresh installs must already be unicode, not needed anymore |
642 | unset_config('unicodedb'); |
643 | |
644 | /// Main savepoint reached |
645 | upgrade_main_savepoint($result, 2008081600); |
646 | } |
647 | |
ff2f69bc |
648 | if ($result && $oldversion < 2008081900) { |
649 | /// Define field userid to be added to portfolio_tempdata |
650 | $table = new xmldb_table('portfolio_tempdata'); |
2a88f626 |
651 | $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'expirytime'); |
ff2f69bc |
652 | |
653 | /// Conditionally launch add field userid |
654 | if (!$dbman->field_exists($table, $field)) { |
655 | $dbman->add_field($table, $field); |
656 | } |
657 | $DB->set_field('portfolio_tempdata', 'userid', 0); |
658 | /// now change it to be notnull |
659 | |
660 | /// Changing nullability of field userid on table portfolio_tempdata to not null |
2a88f626 |
661 | $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'expirytime'); |
ff2f69bc |
662 | |
663 | /// Launch change of nullability for field userid |
664 | $dbman->change_field_notnull($table, $field); |
665 | |
666 | /// Define key userfk (foreign) to be added to portfolio_tempdata |
667 | $table = new xmldb_table('portfolio_tempdata'); |
668 | $key = new xmldb_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
669 | |
670 | /// Launch add key userfk |
671 | $dbman->add_key($table, $key); |
672 | |
673 | upgrade_main_savepoint($result, 2008081900); |
674 | } |
8f3f6cc3 |
675 | if ($result && $oldversion < 2008082602) { |
27051e43 |
676 | |
677 | /// Define table repository to be dropped |
678 | $table = new xmldb_table('repository'); |
679 | |
680 | /// Conditionally launch drop table for repository |
681 | if ($dbman->table_exists($table)) { |
682 | $dbman->drop_table($table); |
683 | } |
684 | |
685 | /// Define table repository to be created |
686 | $table = new xmldb_table('repository'); |
687 | |
688 | /// Adding fields to table repository |
2a88f626 |
689 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
690 | $table->add_field('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
691 | $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '1'); |
692 | $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); |
27051e43 |
693 | |
694 | /// Adding keys to table repository |
695 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
696 | |
697 | /// Conditionally launch create table for repository |
698 | if (!$dbman->table_exists($table)) { |
699 | $dbman->create_table($table); |
700 | } |
701 | /// Define table repository_instances to be created |
702 | $table = new xmldb_table('repository_instances'); |
703 | |
704 | /// Adding fields to table repository_instances |
2a88f626 |
705 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
706 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
707 | $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
708 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); |
709 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
710 | $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null); |
711 | $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null); |
712 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); |
713 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); |
27051e43 |
714 | |
715 | /// Adding keys to table repository_instances |
716 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
717 | |
718 | /// Conditionally launch create table for repository_instances |
719 | if (!$dbman->table_exists($table)) { |
720 | $dbman->create_table($table); |
721 | } |
722 | |
723 | /// Define table repository_instance_config to be created |
724 | $table = new xmldb_table('repository_instance_config'); |
725 | |
726 | /// Adding fields to table repository_instance_config |
2a88f626 |
727 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
728 | $table->add_field('instanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
729 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
730 | $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null); |
27051e43 |
731 | |
732 | /// Adding keys to table repository_instance_config |
733 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
734 | |
735 | /// Conditionally launch create table for repository_instance_config |
736 | if (!$dbman->table_exists($table)) { |
737 | $dbman->create_table($table); |
738 | } |
739 | |
740 | /// Main savepoint reached |
8f3f6cc3 |
741 | upgrade_main_savepoint($result, 2008082602); |
27051e43 |
742 | } |
743 | |
62e76c67 |
744 | if ($result && $oldversion < 2008082700) { |
745 | /// Add a new column to the question sessions table to record whether a |
746 | /// question has been flagged. |
747 | |
748 | /// Define field flagged to be added to question_sessions |
749 | $table = new xmldb_table('question_sessions'); |
2a88f626 |
750 | $field = new xmldb_field('flagged', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'manualcomment'); |
62e76c67 |
751 | |
752 | /// Conditionally launch add field flagged |
753 | if (!$dbman->field_exists($table, $field)) { |
754 | $dbman->add_field($table, $field); |
755 | } |
756 | |
757 | /// Main savepoint reached |
758 | upgrade_main_savepoint($result, 2008082700); |
759 | } |
ff2f69bc |
760 | |
2c48aeab |
761 | if ($result && $oldversion < 2008082900) { |
762 | |
763 | /// Changing precision of field parent_type on table mnet_rpc to (20) |
764 | $table = new xmldb_table('mnet_rpc'); |
2a88f626 |
765 | $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path'); |
2c48aeab |
766 | |
767 | /// Launch change of precision for field parent_type |
768 | $dbman->change_field_precision($table, $field); |
769 | |
770 | /// Main savepoint reached |
771 | upgrade_main_savepoint($result, 2008082900); |
772 | } |
773 | |
ff7e7f92 |
774 | if ($result && $oldversion < 2008090108) { |
775 | $repo = new object(); |
776 | $repo->type = 'upload'; |
777 | $repo->visible = 1; |
778 | $repo->sortorder = 1; |
779 | if (!$DB->record_exists('repository', array('type'=>'upload'))) { |
780 | $typeid = $DB->insert_record('repository', $repo); |
781 | }else{ |
782 | $record = $DB->get_record('repository', array('type'=>'upload')); |
783 | $typeid = $record->id; |
784 | } |
785 | if (!$DB->record_exists('repository_instances', array('typeid'=>$typeid))) { |
786 | $instance = new object(); |
fb7cae3b |
787 | $instance->name = get_string('repositoryname', 'repository_upload'); |
ff7e7f92 |
788 | $instance->typeid = $typeid; |
789 | $instance->userid = 0; |
790 | $instance->contextid = SITEID; |
791 | $instance->timecreated = time(); |
792 | $instance->timemodified = time(); |
793 | $result = $result && $DB->insert_record('repository_instances', $instance); |
794 | } |
795 | $repo->type = 'local'; |
796 | $repo->visible = 1; |
797 | $repo->sortorder = 1; |
798 | if (!$DB->record_exists('repository', array('type'=>'local'))) { |
799 | $typeid = $DB->insert_record('repository', $repo); |
800 | }else{ |
801 | $record = $DB->get_record('repository', array('type'=>'local')); |
802 | $typeid = $record->id; |
803 | } |
804 | if (!$DB->record_exists('repository_instances', array('typeid'=>$typeid))) { |
805 | $instance = new object(); |
fb7cae3b |
806 | $instance->name = get_string('repositoryname', 'repository_local'); |
ff7e7f92 |
807 | $instance->typeid = $typeid; |
808 | $instance->userid = 0; |
809 | $instance->contextid = SITEID; |
810 | $instance->timecreated = time(); |
811 | $instance->timemodified = time(); |
812 | $result = $result && $DB->insert_record('repository_instances', $instance); |
813 | } |
814 | |
815 | upgrade_main_savepoint($result, 2008090108); |
816 | } |
817 | |
d849880e |
818 | // MDL-16411 Move all plugintype_pluginname_version values from config to config_plugins. |
819 | if ($result && $oldversion < 2008091000) { |
820 | foreach (get_object_vars($CFG) as $name => $value) { |
821 | if (substr($name, strlen($name) - 8) !== '_version') { |
822 | continue; |
823 | } |
824 | $pluginname = substr($name, 0, strlen($name) - 8); |
825 | if (!strpos($pluginname, '_')) { |
826 | // Skip things like backup_version that don't contain an extra _ |
827 | continue; |
828 | } |
829 | if ($pluginname == 'enrol_ldap_version') { |
830 | // Special case - this is something different from a plugin version number. |
831 | continue; |
832 | } |
6f49dd0f |
833 | if (!preg_match('/^\d{10}$/', $value)) { |
d849880e |
834 | // Extra safety check, skip anything that does not look like a Moodle |
835 | // version number (10 digits). |
836 | continue; |
837 | } |
838 | $result = $result && set_config('version', $value, $pluginname); |
839 | $result = $result && unset_config($name); |
840 | } |
841 | upgrade_main_savepoint($result, 2008091000); |
842 | } |
843 | |
948c2860 |
844 | //Add a readonly field to the repository_instances table |
845 | //in order to support instance created automatically by a repository plugin |
846 | if ($result && $oldversion < 2008091611) { |
847 | |
848 | /// Define field readonly to be added to repository_instances |
849 | $table = new xmldb_table('repository_instances'); |
2a88f626 |
850 | $field = new xmldb_field('readonly', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timemodified'); |
948c2860 |
851 | |
852 | /// Conditionally launch add field readonly |
853 | if (!$dbman->field_exists($table, $field)) { |
854 | $dbman->add_field($table, $field); |
855 | } |
856 | |
857 | /// Main savepoint reached |
858 | upgrade_main_savepoint($result, 2008091611); |
859 | } |
860 | |
53b20fe3 |
861 | if ($result && $oldversion < 2008092300) { |
862 | unset_config('editorspelling'); |
863 | unset_config('editordictionary'); |
864 | /// Main savepoint reached |
865 | upgrade_main_savepoint($result, 2008092300); |
866 | } |
867 | |
a7df430b |
868 | if ($result && $oldversion < 2008101000) { |
869 | |
870 | /// Changing the default of field lang on table user to en_utf8 |
871 | $table = new xmldb_table('user'); |
2a88f626 |
872 | $field = new xmldb_field('lang', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, 'en_utf8', 'country'); |
a7df430b |
873 | |
874 | /// Launch change of default for field lang |
875 | $dbman->change_field_default($table, $field); |
876 | |
877 | /// Main savepoint reached |
878 | upgrade_main_savepoint($result, 2008101000); |
879 | } |
880 | |
5e7206a8 |
881 | if ($result && $oldversion < 2008101300) { |
882 | |
d9e673c1 |
883 | if (!get_config(NULL, 'statsruntimedays')) { |
5e7206a8 |
884 | set_config('statsruntimedays', '31'); |
885 | } |
886 | |
887 | /// Main savepoint reached |
888 | upgrade_main_savepoint($result, 2008101300); |
889 | } |
53b20fe3 |
890 | |
01a80f51 |
891 | /// New table for storing which roles can be assigned in which contexts. |
892 | if ($result && $oldversion < 2008110601) { |
893 | |
894 | /// Define table role_context_levels to be created |
895 | $table = new xmldb_table('role_context_levels'); |
896 | |
897 | /// Adding fields to table role_context_levels |
2a88f626 |
898 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
899 | $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
900 | $table->add_field('contextlevel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
01a80f51 |
901 | |
902 | /// Adding keys to table role_context_levels |
903 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
904 | $table->add_key('contextlevel-roleid', XMLDB_KEY_UNIQUE, array('contextlevel', 'roleid')); |
905 | $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id')); |
906 | |
907 | /// Conditionally launch create table for role_context_levels |
908 | if (!$dbman->table_exists($table)) { |
909 | $dbman->create_table($table); |
910 | } |
911 | |
912 | /// Main savepoint reached |
913 | upgrade_main_savepoint($result, 2008110601); |
914 | } |
915 | |
916 | /// Now populate the role_context_levels table with the defaults that match |
917 | /// moodle_install_roles, and any other combinations that exist in this system. |
918 | if ($result && $oldversion < 2008110602) { |
919 | $roleids = $DB->get_records_menu('role', array(), '', 'shortname,id'); |
920 | |
921 | /// Defaults, should match moodle_install_roles. |
922 | $rolecontextlevels = array(); |
923 | if (isset($roleids['admin'])) { |
924 | $rolecontextlevels[$roleids['admin']] = get_default_contextlevels('admin'); |
925 | } |
926 | if (isset($roleids['coursecreator'])) { |
927 | $rolecontextlevels[$roleids['coursecreator']] = get_default_contextlevels('coursecreator'); |
928 | } |
929 | if (isset($roleids['editingteacher'])) { |
930 | $rolecontextlevels[$roleids['editingteacher']] = get_default_contextlevels('editingteacher'); |
931 | } |
932 | if (isset($roleids['teacher'])) { |
933 | $rolecontextlevels[$roleids['teacher']] = get_default_contextlevels('teacher'); |
934 | } |
935 | if (isset($roleids['student'])) { |
936 | $rolecontextlevels[$roleids['student']] = get_default_contextlevels('student'); |
937 | } |
938 | if (isset($roleids['guest'])) { |
939 | $rolecontextlevels[$roleids['guest']] = get_default_contextlevels('guest'); |
940 | } |
941 | if (isset($roleids['user'])) { |
942 | $rolecontextlevels[$roleids['user']] = get_default_contextlevels('user'); |
943 | } |
656be893 |
944 | |
01a80f51 |
945 | /// See what other role assignments are in this database, extend the allowed |
946 | /// lists to allow them too. |
947 | $existingrolecontextlevels = $DB->get_recordset_sql('SELECT DISTINCT ra.roleid, con.contextlevel FROM |
948 | {role_assignments} ra JOIN {context} con ON ra.contextid = con.id'); |
949 | foreach ($existingrolecontextlevels as $rcl) { |
950 | if (!isset($rolecontextlevels[$rcl->roleid])) { |
951 | $rolecontextlevels[$rcl->roleid] = array($rcl->contextlevel); |
952 | } else if (!in_array($rcl->contextlevel, $rolecontextlevels[$rcl->roleid])) { |
953 | $rolecontextlevels[$rcl->roleid][] = $rcl->contextlevel; |
954 | } |
955 | } |
956 | |
957 | /// Put the data into the database. |
958 | foreach ($rolecontextlevels as $roleid => $contextlevels) { |
959 | set_role_contextlevels($roleid, $contextlevels); |
960 | } |
961 | |
962 | /// Main savepoint reached |
963 | upgrade_main_savepoint($result, 2008110602); |
964 | } |
965 | |
06de498b |
966 | /// Remove any role overrides for moodle/site:doanything, or any permissions |
967 | /// for it in a role without legacy:admin. |
968 | if ($result && $oldversion < 2008110603) { |
969 | $systemcontext = get_context_instance(CONTEXT_SYSTEM); |
970 | |
971 | // Remove all overrides. |
972 | $DB->delete_records_select('role_capabilities', 'capability = ? AND contextid <> ?', array('moodle/site:doanything', $systemcontext->id)); |
973 | |
974 | // Get the ids of all the roles that are moodle/legacy:admin. |
975 | $adminroleids = $DB->get_records_menu('role_capabilities', |
976 | array('capability' => 'moodle/legacy:admin', 'permission' => 1, 'contextid' => $systemcontext->id), |
977 | '', 'id, roleid'); |
978 | |
979 | // Remove moodle/site:doanything from all other roles. |
980 | list($notroletest, $params) = $DB->get_in_or_equal($adminroleids, SQL_PARAMS_QM, '', false); |
981 | $DB->delete_records_select('role_capabilities', "roleid $notroletest AND capability = ? AND contextid = ?", |
982 | array_merge($params, array('moodle/site:doanything', $systemcontext->id))); |
983 | |
984 | // Ensure that for all admin-y roles, the permission for moodle/site:doanything is 1 |
985 | list($isroletest, $params) = $DB->get_in_or_equal($adminroleids); |
986 | $DB->set_field_select('role_capabilities', 'permission', 1, |
987 | "roleid $isroletest AND capability = ? AND contextid = ?", |
988 | array_merge($params, array('moodle/site:doanything', $systemcontext->id))); |
989 | |
990 | // And for any admin-y roles where moodle/site:doanything is not set, set it. |
991 | $doanythingroleids = $DB->get_records_menu('role_capabilities', |
992 | array('capability' => 'moodle/site:doanything', 'permission' => 1, 'contextid' => $systemcontext->id), |
993 | '', 'id, roleid'); |
994 | foreach ($adminroleids as $roleid) { |
995 | if (!in_array($roleid, $doanythingroleids)) { |
996 | $rc = new stdClass; |
997 | $rc->contextid = $systemcontext->id; |
998 | $rc->roleid = $roleid; |
999 | $rc->capability = 'moodle/site:doanything'; |
1000 | $rc->permission = 1; |
1001 | $rc->timemodified = time(); |
1002 | $DB->insert_record('role_capabilities', $rc); |
1003 | } |
1004 | } |
1005 | |
1006 | /// Main savepoint reached |
1007 | upgrade_main_savepoint($result, 2008110603); |
1008 | } |
1009 | |
9101efd3 |
1010 | /// Drop the deprecated teacher, teachers, student and students columns from the course table. |
1011 | if ($result && $oldversion < 2008111200) { |
1012 | $table = new xmldb_table('course'); |
1013 | |
1014 | /// Conditionally launch drop field teacher |
1015 | $field = new xmldb_field('teacher'); |
1016 | if ($dbman->field_exists($table, $field)) { |
1017 | $dbman->drop_field($table, $field); |
1018 | } |
1019 | |
1020 | /// Conditionally launch drop field teacher |
1021 | $field = new xmldb_field('teachers'); |
1022 | if ($dbman->field_exists($table, $field)) { |
1023 | $dbman->drop_field($table, $field); |
1024 | } |
1025 | |
1026 | /// Conditionally launch drop field teacher |
1027 | $field = new xmldb_field('student'); |
1028 | if ($dbman->field_exists($table, $field)) { |
1029 | $dbman->drop_field($table, $field); |
1030 | } |
1031 | |
1032 | /// Conditionally launch drop field teacher |
1033 | $field = new xmldb_field('students'); |
1034 | if ($dbman->field_exists($table, $field)) { |
1035 | $dbman->drop_field($table, $field); |
1036 | } |
1037 | |
1038 | /// Main savepoint reached |
1039 | upgrade_main_savepoint($result, 2008111200); |
1040 | } |
1041 | |
40c792c3 |
1042 | /// Add a unique index to the role.name column. |
1043 | if ($result && $oldversion < 2008111800) { |
1044 | |
1045 | /// Define index name (unique) to be added to role |
1046 | $table = new xmldb_table('role'); |
1047 | $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name')); |
1048 | |
1049 | /// Conditionally launch add index name |
1050 | if (!$dbman->index_exists($table, $index)) { |
1051 | $dbman->add_index($table, $index); |
1052 | } |
1053 | |
1054 | /// Main savepoint reached |
1055 | upgrade_main_savepoint($result, 2008111800); |
1056 | } |
1057 | |
1058 | /// Add a unique index to the role.shortname column. |
1059 | if ($result && $oldversion < 2008111801) { |
1060 | |
1061 | /// Define index shortname (unique) to be added to role |
1062 | $table = new xmldb_table('role'); |
1063 | $index = new xmldb_index('shortname', XMLDB_INDEX_UNIQUE, array('shortname')); |
1064 | |
1065 | /// Conditionally launch add index shortname |
1066 | if (!$dbman->index_exists($table, $index)) { |
1067 | $dbman->add_index($table, $index); |
1068 | } |
1069 | |
1070 | /// Main savepoint reached |
1071 | upgrade_main_savepoint($result, 2008111801); |
1072 | } |
1073 | |
82bd6a5e |
1074 | if ($result && $oldversion < 2008120700) { |
1075 | |
1076 | /// Changing precision of field shortname on table course_request to (100) |
1077 | $table = new xmldb_table('course_request'); |
2a88f626 |
1078 | $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname'); |
82bd6a5e |
1079 | |
1080 | /// Launch change of precision for field shortname |
1081 | $dbman->change_field_precision($table, $field); |
1082 | |
1083 | /// Main savepoint reached |
1084 | upgrade_main_savepoint($result, 2008120700); |
1085 | } |
1086 | |
1087 | /// For MDL-17501. Ensure that any role that has moodle/course:update also |
1088 | /// has moodle/course:visibility. |
1089 | if ($result && $oldversion < 2008120800) { |
1090 | /// Get the roles with 'moodle/course:update'. |
1091 | $systemcontext = get_context_instance(CONTEXT_SYSTEM); |
1092 | $roles = get_roles_with_capability('moodle/course:update', CAP_ALLOW, $systemcontext); |
1093 | |
1094 | /// Give those roles 'moodle/course:visibility'. |
1095 | foreach ($roles as $role) { |
1096 | assign_capability('moodle/course:visibility', CAP_ALLOW, $role->id, $systemcontext->id); |
1097 | } |
1098 | |
1099 | /// Force all sessions to refresh access data. |
1100 | mark_context_dirty($systemcontext->path); |
1101 | |
1102 | /// Main savepoint reached |
1103 | upgrade_main_savepoint($result, 2008120800); |
1104 | } |
1105 | |
1106 | if ($result && $oldversion < 2008120801) { |
1107 | |
1108 | /// Changing precision of field shortname on table mnet_enrol_course to (100) |
1109 | $table = new xmldb_table('mnet_enrol_course'); |
2a88f626 |
1110 | $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname'); |
82bd6a5e |
1111 | |
1112 | /// Launch change of precision for field shortname |
1113 | $dbman->change_field_precision($table, $field); |
1114 | |
1115 | /// Main savepoint reached |
1116 | upgrade_main_savepoint($result, 2008120801); |
1117 | } |
1118 | |
1119 | if ($result && $oldversion < 2008121701) { |
0953a4e7 |
1120 | |
1121 | /// Define field availablefrom to be added to course_modules |
1122 | $table = new xmldb_table('course_modules'); |
2a88f626 |
1123 | $field = new xmldb_field('availablefrom', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionexpected'); |
0953a4e7 |
1124 | |
1125 | /// Conditionally launch add field availablefrom |
1126 | if (!$dbman->field_exists($table, $field)) { |
1127 | $dbman->add_field($table, $field); |
1128 | } |
1129 | |
1130 | /// Define field availableuntil to be added to course_modules |
2a88f626 |
1131 | $field = new xmldb_field('availableuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availablefrom'); |
0953a4e7 |
1132 | |
1133 | /// Conditionally launch add field availableuntil |
1134 | if (!$dbman->field_exists($table, $field)) { |
1135 | $dbman->add_field($table, $field); |
1136 | } |
82bd6a5e |
1137 | |
0953a4e7 |
1138 | /// Define field showavailability to be added to course_modules |
2a88f626 |
1139 | $field = new xmldb_field('showavailability', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availableuntil'); |
0953a4e7 |
1140 | |
1141 | /// Conditionally launch add field showavailability |
1142 | if (!$dbman->field_exists($table, $field)) { |
1143 | $dbman->add_field($table, $field); |
1144 | } |
82bd6a5e |
1145 | |
0953a4e7 |
1146 | /// Define table course_modules_availability to be created |
1147 | $table = new xmldb_table('course_modules_availability'); |
1148 | |
1149 | /// Adding fields to table course_modules_availability |
2a88f626 |
1150 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1151 | $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
1152 | $table->add_field('sourcecmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); |
1153 | $table->add_field('requiredcompletion', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null); |
1154 | $table->add_field('gradeitemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); |
1155 | $table->add_field('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null); |
1156 | $table->add_field('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null); |
0953a4e7 |
1157 | |
1158 | /// Adding keys to table course_modules_availability |
1159 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
cbb17d54 |
1160 | $table->add_key('coursemoduleid', XMLDB_KEY_FOREIGN, array('coursemoduleid'), 'course_modules', array('id')); |
1161 | $table->add_key('sourcecmid', XMLDB_KEY_FOREIGN, array('sourcecmid'), 'course_modules', array('id')); |
1162 | $table->add_key('gradeitemid', XMLDB_KEY_FOREIGN, array('gradeitemid'), 'grade_items', array('id')); |
0953a4e7 |
1163 | |
1164 | /// Conditionally launch create table for course_modules_availability |
1165 | if (!$dbman->table_exists($table)) { |
1166 | $dbman->create_table($table); |
1167 | } |
1168 | |
82bd6a5e |
1169 | /// Changes to modinfo mean we need to rebuild course cache |
a9a0b93d |
1170 | require_once($CFG->dirroot . '/course/lib.php'); |
82bd6a5e |
1171 | rebuild_course_cache(0,true); |
9136a60c |
1172 | |
82bd6a5e |
1173 | /// For developer upgrades, turn on the conditional activities and completion |
1174 | /// features automatically (to gain more testing) |
1175 | if(debugging('',DEBUG_DEVELOPER)) { |
1176 | set_config('enableavailability',1); |
1177 | set_config('enablecompletion',1); |
9136a60c |
1178 | } |
1179 | |
9d510a2e |
1180 | /// Main savepoint reached |
82bd6a5e |
1181 | upgrade_main_savepoint($result, 2008121701); |
9d510a2e |
1182 | } |
1183 | |
656be893 |
1184 | if ($result && $oldversion < 2009010500) { |
1185 | /// clean up config table a bit |
1186 | unset_config('session_error_counter'); |
1187 | |
1188 | /// Main savepoint reached |
1189 | upgrade_main_savepoint($result, 2009010500); |
1190 | } |
1191 | |
1192 | if ($result && $oldversion < 2009010600) { |
1193 | |
1194 | /// Define field originalquestion to be dropped from question_states |
1195 | $table = new xmldb_table('question_states'); |
1196 | $field = new xmldb_field('originalquestion'); |
1197 | |
1198 | /// Conditionally launch drop field originalquestion |
1199 | if ($dbman->field_exists($table, $field)) { |
1200 | $dbman->drop_field($table, $field); |
1201 | } |
1202 | |
1203 | /// Main savepoint reached |
1204 | upgrade_main_savepoint($result, 2009010600); |
1205 | } |
1206 | |
1207 | if ($result && $oldversion < 2009010601) { |
1208 | |
1209 | /// Changing precision of field ip on table log to (45) |
1210 | $table = new xmldb_table('log'); |
2a88f626 |
1211 | $field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'userid'); |
656be893 |
1212 | |
1213 | /// Launch change of precision for field ip |
1214 | $dbman->change_field_precision($table, $field); |
1215 | |
1216 | /// Main savepoint reached |
1217 | upgrade_main_savepoint($result, 2009010601); |
1218 | } |
1219 | |
1220 | if ($result && $oldversion < 2009010602) { |
1221 | |
1222 | /// Changing precision of field lastip on table user to (45) |
1223 | $table = new xmldb_table('user'); |
2a88f626 |
1224 | $field = new xmldb_field('lastip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'currentlogin'); |
656be893 |
1225 | |
1226 | /// Launch change of precision for field lastip |
1227 | $dbman->change_field_precision($table, $field); |
1228 | |
1229 | /// Main savepoint reached |
1230 | upgrade_main_savepoint($result, 2009010602); |
1231 | } |
1232 | |
1233 | if ($result && $oldversion < 2009010603) { |
1234 | |
1235 | /// Changing precision of field ip_address on table mnet_host to (45) |
1236 | $table = new xmldb_table('mnet_host'); |
2a88f626 |
1237 | $field = new xmldb_field('ip_address', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'wwwroot'); |
656be893 |
1238 | |
1239 | /// Launch change of precision for field ip_address |
1240 | $dbman->change_field_precision($table, $field); |
1241 | |
1242 | /// Main savepoint reached |
1243 | upgrade_main_savepoint($result, 2009010603); |
1244 | } |
1245 | |
1246 | if ($result && $oldversion < 2009010604) { |
1247 | |
1248 | /// Changing precision of field ip on table mnet_log to (45) |
1249 | $table = new xmldb_table('mnet_log'); |
2a88f626 |
1250 | $field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'userid'); |
656be893 |
1251 | |
1252 | /// Launch change of precision for field ip |
1253 | $dbman->change_field_precision($table, $field); |
1254 | |
1255 | /// Main savepoint reached |
1256 | upgrade_main_savepoint($result, 2009010604); |
1257 | } |
1258 | |
4413941f |
1259 | if ($result && $oldversion < 2009010800) { |
1260 | /// Update the notifyloginfailures setting. |
1261 | if ($CFG->notifyloginfailures == 'mainadmin') { |
1262 | set_config('notifyloginfailures', get_admin()->username); |
1263 | } else if ($CFG->notifyloginfailures == 'alladmins') { |
1264 | set_config('notifyloginfailures', '$@ALL@$'); |
1265 | } else { |
1266 | set_config('notifyloginfailures', ''); |
1267 | } |
1268 | |
1269 | /// Main savepoint reached |
1270 | upgrade_main_savepoint($result, 2009010800); |
1271 | } |
1272 | |
ab2eb65c |
1273 | if ($result && $oldversion < 2009011000) { |
1274 | |
1275 | /// Changing nullability of field configdata on table block_instance to null |
1276 | $table = new xmldb_table('block_instance'); |
1277 | $field = new xmldb_field('configdata'); |
2a88f626 |
1278 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'visible'); |
ab2eb65c |
1279 | |
1280 | /// Launch change of nullability for field configdata |
1281 | $dbman->change_field_notnull($table, $field); |
1282 | |
1283 | /// Main savepoint reached |
1284 | upgrade_main_savepoint($result, 2009011000); |
1285 | } |
1286 | |
1caea91e |
1287 | if ($result && $oldversion < 2009011100) { |
1288 | /// Remove unused settings |
1289 | unset_config('zip'); |
1290 | unset_config('unzip'); |
1291 | unset_config('adminblocks_initialised'); |
1292 | |
1293 | /// Main savepoint reached |
1294 | upgrade_main_savepoint($result, 2009011100); |
1295 | } |
1296 | |
eb6a973c |
1297 | if ($result && $oldversion < 2009011101) { |
1298 | /// Migrate backup settings to core plugin config table |
1299 | $configs = $DB->get_records('backup_config'); |
1300 | foreach ($configs as $config) { |
1301 | set_config($config->name, $config->value, 'backup'); |
1302 | } |
1303 | |
1304 | /// Define table to be dropped |
1305 | $table = new xmldb_table('backup_config'); |
1306 | |
1307 | /// Launch drop table for old backup config |
1308 | $dbman->drop_table($table); |
1309 | |
1310 | /// Main savepoint reached |
1311 | upgrade_main_savepoint($result, 2009011101); |
1312 | } |
1313 | |
301bf0b2 |
1314 | if ($result && $oldversion < 2009011303) { |
1315 | |
1316 | /// Define table config_log to be created |
1317 | $table = new xmldb_table('config_log'); |
1318 | |
1319 | /// Adding fields to table config_log |
2a88f626 |
1320 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1321 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
1322 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
1323 | $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null); |
1324 | $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); |
1325 | $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null); |
1326 | $table->add_field('oldvalue', XMLDB_TYPE_TEXT, 'small', null, null, null, null); |
301bf0b2 |
1327 | |
1328 | /// Adding keys to table config_log |
1329 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
1330 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
1331 | |
1332 | /// Adding indexes to table config_log |
1333 | $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified')); |
1334 | |
1335 | /// Launch create table for config_log |
1336 | $dbman->create_table($table); |
1337 | |
1338 | /// Main savepoint reached |
1339 | upgrade_main_savepoint($result, 2009011303); |
1340 | } |
1341 | |
b9fb7103 |
1342 | if ($result && $oldversion < 2009011900) { |
3f57bd45 |
1343 | |
1344 | /// Define table sessions2 to be dropped |
1345 | $table = new xmldb_table('sessions2'); |
1346 | |
1347 | /// Conditionally launch drop table for sessions |
1348 | if ($dbman->table_exists($table)) { |
1349 | $dbman->drop_table($table); |
1350 | } |
1351 | |
1352 | /// Define table sessions to be dropped |
1353 | $table = new xmldb_table('sessions'); |
1354 | |
1355 | /// Conditionally launch drop table for sessions |
1356 | if ($dbman->table_exists($table)) { |
1357 | $dbman->drop_table($table); |
1358 | } |
1359 | |
1360 | /// Define table sessions to be created |
1361 | $table = new xmldb_table('sessions'); |
1362 | |
1363 | /// Adding fields to table sessions |
2a88f626 |
1364 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1365 | $table->add_field('state', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); |
1366 | $table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null); |
1367 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
1368 | $table->add_field('sessdata', XMLDB_TYPE_TEXT, 'big', null, null, null, null); |
1369 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
1370 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
1371 | $table->add_field('firstip', XMLDB_TYPE_CHAR, '45', null, null, null, null); |
1372 | $table->add_field('lastip', XMLDB_TYPE_CHAR, '45', null, null, null, null); |
3f57bd45 |
1373 | |
1374 | /// Adding keys to table sessions |
1375 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
1376 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
1377 | |
1378 | /// Adding indexes to table sessions |
1379 | $table->add_index('state', XMLDB_INDEX_NOTUNIQUE, array('state')); |
1380 | $table->add_index('sid', XMLDB_INDEX_UNIQUE, array('sid')); |
1381 | $table->add_index('timecreated', XMLDB_INDEX_NOTUNIQUE, array('timecreated')); |
1382 | $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified')); |
1383 | |
1384 | /// Launch create table for sessions |
1385 | $dbman->create_table($table); |
1386 | |
1387 | /// Main savepoint reached |
b9fb7103 |
1388 | upgrade_main_savepoint($result, 2009011900); |
3f57bd45 |
1389 | } |
1390 | |
dc6f76b9 |
1391 | if ($result && $oldversion < 2009012901) { |
795a08ad |
1392 | // NOTE: this table may already exist, see beginning of this file ;-) |
1f20942c |
1393 | |
1394 | /// Define table upgrade_log to be created |
1395 | $table = new xmldb_table('upgrade_log'); |
1396 | |
1397 | /// Adding fields to table upgrade_log |
2a88f626 |
1398 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1399 | $table->add_field('type', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
1400 | $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null); |
1401 | $table->add_field('version', XMLDB_TYPE_CHAR, '100', null, null, null, null); |
1402 | $table->add_field('info', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
1403 | $table->add_field('details', XMLDB_TYPE_TEXT, 'small', null, null, null, null); |
1404 | $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null); |
1405 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
1406 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
1f20942c |
1407 | |
1408 | /// Adding keys to table upgrade_log |
1409 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
1410 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
1411 | |
1412 | /// Adding indexes to table upgrade_log |
1413 | $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified')); |
1414 | $table->add_index('type-timemodified', XMLDB_INDEX_NOTUNIQUE, array('type', 'timemodified')); |
1415 | |
1416 | /// Conditionally launch create table for upgrade_log |
1417 | if (!$dbman->table_exists($table)) { |
1418 | $dbman->create_table($table); |
1419 | } |
1420 | |
1421 | /// Main savepoint reached |
dc6f76b9 |
1422 | upgrade_main_savepoint($result, 2009012901); |
1f20942c |
1423 | } |
1caea91e |
1424 | |
75564228 |
1425 | if ($result && $oldversion < 2009021800) { |
eb2761f8 |
1426 | // Converting format of grade conditions, if any exist, to percentages. |
75564228 |
1427 | $DB->execute(" |
1428 | UPDATE {course_modules_availability} SET grademin=( |
1429 | SELECT 100.0*({course_modules_availability}.grademin-gi.grademin) |
eb2761f8 |
1430 | /(gi.grademax-gi.grademin) |
1431 | FROM {grade_items} gi |
75564228 |
1432 | WHERE gi.id={course_modules_availability}.gradeitemid) |
1433 | WHERE gradeitemid IS NOT NULL AND grademin IS NOT NULL"); |
1434 | $DB->execute(" |
1435 | UPDATE {course_modules_availability} SET grademax=( |
1436 | SELECT 100.0*({course_modules_availability}.grademax-gi.grademin) |
eb2761f8 |
1437 | /(gi.grademax-gi.grademin) |
1438 | FROM {grade_items} gi |
75564228 |
1439 | WHERE gi.id={course_modules_availability}.gradeitemid) |
1440 | WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); |
1441 | |
1442 | /// Main savepoint reached |
1443 | upgrade_main_savepoint($result, 2009021800); |
1444 | } |
bc7ec91a |
1445 | if ($result && $oldversion < 2009021801) { |
1446 | /// Define field backuptype to be added to backup_log |
382123a0 |
1447 | $table = new xmldb_table('backup_log'); |
2a88f626 |
1448 | $field = new xmldb_field('backuptype', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, 'info'); |
bc7ec91a |
1449 | /// Conditionally Launch add field backuptype and set all old records as 'scheduledbackup' records. |
1450 | if (!$dbman->field_exists($table, $field)) { |
1451 | $dbman->add_field($table, $field); |
1452 | $DB->execute("UPDATE {backup_log} SET backuptype='scheduledbackup'"); |
1453 | } |
75564228 |
1454 | |
bc7ec91a |
1455 | /// Main savepoint reached |
1456 | upgrade_main_savepoint($result, 2009021801); |
1457 | } |
af52ecee |
1458 | /// Add default sort order for question types. |
1459 | if ($result && $oldversion < 2009030300) { |
1460 | set_config('multichoice_sortorder', 1, 'question'); |
1461 | set_config('truefalse_sortorder', 2, 'question'); |
1462 | set_config('shortanswer_sortorder', 3, 'question'); |
1463 | set_config('numerical_sortorder', 4, 'question'); |
1464 | set_config('calculated_sortorder', 5, 'question'); |
1465 | set_config('essay_sortorder', 6, 'question'); |
1466 | set_config('match_sortorder', 7, 'question'); |
1467 | set_config('randomsamatch_sortorder', 8, 'question'); |
1468 | set_config('multianswer_sortorder', 9, 'question'); |
1469 | set_config('description_sortorder', 10, 'question'); |
1470 | set_config('random_sortorder', 11, 'question'); |
1471 | set_config('missingtype_sortorder', 12, 'question'); |
1472 | |
1473 | upgrade_main_savepoint($result, 2009030300); |
1474 | } |
a75c78d3 |
1475 | if ($result && $oldversion < 2009030501) { |
1476 | /// setup default repository plugins |
1477 | require_once($CFG->dirroot . '/repository/lib.php'); |
1478 | repository_setup_default_plugins(); |
1479 | /// Main savepoint reached |
1480 | upgrade_main_savepoint($result, 2009030501); |
1481 | } |
af52ecee |
1482 | |
82701e24 |
1483 | /// MDL-18132 replace the use a new Role allow switch settings page, instead of |
1484 | /// $CFG->allowuserswitchrolestheycantassign |
1485 | if ($result && $oldversion < 2009032000) { |
1486 | /// First create the new table. |
1487 | $table = new xmldb_table('role_allow_switch'); |
1488 | |
1489 | /// Adding fields to table role_allow_switch |
2a88f626 |
1490 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1491 | $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
1492 | $table->add_field('allowswitch', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
82701e24 |
1493 | |
1494 | /// Adding keys to table role_allow_switch |
1495 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
1496 | $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id')); |
1497 | $table->add_key('allowswitch', XMLDB_KEY_FOREIGN, array('allowswitch'), 'role', array('id')); |
1498 | |
1499 | /// Adding indexes to table role_allow_switch |
1500 | $table->add_index('roleid-allowoverride', XMLDB_INDEX_UNIQUE, array('roleid', 'allowswitch')); |
1501 | |
1502 | /// Conditionally launch create table for role_allow_switch |
1503 | if (!$dbman->table_exists($table)) { |
1504 | $dbman->create_table($table); |
1505 | } |
1506 | |
1507 | /// Main savepoint reached |
1508 | upgrade_main_savepoint($result, 2009032000); |
1509 | } |
0fc9c009 |
1510 | |
82701e24 |
1511 | if ($result && $oldversion < 2009032001) { |
1512 | /// Copy from role_allow_assign into the new table. |
dc740f97 |
1513 | $DB->execute('INSERT INTO {role_allow_switch} (roleid, allowswitch) |
1514 | SELECT roleid, allowassign FROM {role_allow_assign}'); |
82701e24 |
1515 | |
1516 | /// Unset the config variable used in 1.9. |
1517 | unset_config('allowuserswitchrolestheycantassign'); |
1518 | |
1519 | /// Main savepoint reached |
1520 | upgrade_main_savepoint($result, 2009032001); |
1521 | } |
c94985ef |
1522 | |
1523 | if ($result && $oldversion < 2009033100) { |
1524 | require_once("$CFG->dirroot/filter/tex/lib.php"); |
1525 | filter_tex_updatedcallback(null); |
1526 | /// Main savepoint reached |
1527 | upgrade_main_savepoint($result, 2009033100); |
1528 | } |
1529 | |
0fc9c009 |
1530 | if ($result && $oldversion < 2009040300) { |
1531 | |
1532 | /// Define table filter_active to be created |
1533 | $table = new xmldb_table('filter_active'); |
1534 | |
1535 | /// Adding fields to table filter_active |
2a88f626 |
1536 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1537 | $table->add_field('filter', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); |
1538 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
1539 | $table->add_field('active', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null); |
1540 | $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); |
0fc9c009 |
1541 | |
1542 | /// Adding keys to table filter_active |
1543 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
1544 | $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); |
1545 | |
1546 | /// Adding indexes to table filter_active |
1547 | $table->add_index('contextid-filter', XMLDB_INDEX_UNIQUE, array('contextid', 'filter')); |
1548 | |
1549 | /// Conditionally launch create table for filter_active |
1550 | if (!$dbman->table_exists($table)) { |
1551 | $dbman->create_table($table); |
1552 | } |
1553 | |
1554 | /// Main savepoint reached |
1555 | upgrade_main_savepoint($result, 2009040300); |
1556 | } |
1557 | |
1558 | if ($result && $oldversion < 2009040301) { |
1559 | |
1560 | /// Define table filter_config to be created |
1561 | $table = new xmldb_table('filter_config'); |
1562 | |
1563 | /// Adding fields to table filter_config |
2a88f626 |
1564 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1565 | $table->add_field('filter', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); |
1566 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
1567 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
1568 | $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null); |
0fc9c009 |
1569 | |
1570 | /// Adding keys to table filter_config |
1571 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
1572 | $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); |
1573 | |
1574 | /// Adding indexes to table filter_config |
1575 | $table->add_index('contextid-filter-name', XMLDB_INDEX_UNIQUE, array('contextid', 'filter', 'name')); |
1576 | |
1577 | /// Conditionally launch create table for filter_config |
1578 | if (!$dbman->table_exists($table)) { |
1579 | $dbman->create_table($table); |
1580 | } |
1581 | |
1582 | /// Main savepoint reached |
1583 | upgrade_main_savepoint($result, 2009040301); |
1584 | } |
1585 | |
c07e6d8d |
1586 | if ($result && $oldversion < 2009040302) { |
1587 | /// Transfer current settings from $CFG->textfilters |
1588 | $disabledfilters = filter_get_all_installed(); |
1589 | if (empty($CFG->textfilters)) { |
1590 | $activefilters = array(); |
1591 | } else { |
1592 | $activefilters = explode(',', $CFG->textfilters); |
1593 | } |
1594 | $syscontext = get_context_instance(CONTEXT_SYSTEM); |
1595 | $sortorder = 1; |
1596 | foreach ($activefilters as $filter) { |
1597 | filter_set_global_state($filter, TEXTFILTER_ON, $sortorder); |
1598 | $sortorder += 1; |
1599 | unset($disabledfilters[$filter]); |
1600 | } |
1601 | foreach ($disabledfilters as $filter => $notused) { |
1602 | filter_set_global_state($filter, TEXTFILTER_DISABLED, $sortorder); |
1603 | $sortorder += 1; |
1604 | } |
1605 | |
1606 | /// Main savepoint reached |
1607 | upgrade_main_savepoint($result, 2009040302); |
1608 | } |
1609 | |
bbb45905 |
1610 | if ($result && $oldversion < 2009040600) { |
1611 | /// Ensure that $CFG->stringfilters is set. |
1612 | if (empty($CFG->stringfilters)) { |
1613 | if (!empty($CFG->filterall)) { |
1614 | set_config('stringfilters', $CFG->textfilters); |
1615 | } else { |
1616 | set_config('stringfilters', ''); |
1617 | } |
1618 | } |
1619 | |
1620 | set_config('filterall', !empty($CFG->stringfilters)); |
1621 | unset_config('textfilters'); |
1622 | |
1623 | /// Main savepoint reached |
1624 | upgrade_main_savepoint($result, 2009040600); |
1625 | } |
1626 | |
e7c6bf0e |
1627 | if ($result && $oldversion < 2009041700) { |
1628 | /// To ensure the UI remains consistent with no behaviour change, any |
1629 | /// 'until' date in an activity condition should have 1 second subtracted |
1630 | /// (to go from 0:00 on the following day to 23:59 on the previous one). |
1631 | $DB->execute('UPDATE {course_modules} SET availableuntil = availableuntil - 1 WHERE availableuntil <> 0'); |
6861b6fe |
1632 | require_once($CFG->dirroot . '/course/lib.php'); |
0f9534c1 |
1633 | rebuild_course_cache(0, true); |
e7c6bf0e |
1634 | |
1635 | /// Main savepoint reached |
1636 | upgrade_main_savepoint($result, 2009041700); |
1637 | } |
1638 | |
6bdf4c99 |
1639 | if ($result && $oldversion < 2009042600) { |
1640 | /// Deleting orphaned messages from deleted users. |
1641 | require_once($CFG->dirroot.'/message/lib.php'); |
1642 | /// Detect deleted users with messages sent(useridfrom) and not read |
1643 | if ($deletedusers = $DB->get_records_sql('SELECT DISTINCT u.id |
1644 | FROM {user} u |
1645 | JOIN {message} m ON m.useridfrom = u.id |
1646 | WHERE u.deleted = ?', array(1))) { |
1647 | foreach ($deletedusers as $deleteduser) { |
1648 | message_move_userfrom_unread2read($deleteduser->id); // move messages |
1649 | } |
1650 | } |
1651 | /// Main savepoint reached |
1652 | upgrade_main_savepoint($result, 2009042600); |
1653 | } |
1654 | |
e37cd84a |
1655 | /// Dropping all enums/check contraints from core. MDL-18577 |
1656 | if ($result && $oldversion < 2009042700) { |
1657 | |
1658 | /// Changing list of values (enum) of field stattype on table stats_daily to none |
1659 | $table = new xmldb_table('stats_daily'); |
2a88f626 |
1660 | $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid'); |
e37cd84a |
1661 | |
1662 | /// Launch change of list of values for field stattype |
2a88f626 |
1663 | $dbman->drop_enum_from_field($table, $field); |
e37cd84a |
1664 | |
1665 | /// Changing list of values (enum) of field stattype on table stats_weekly to none |
1666 | $table = new xmldb_table('stats_weekly'); |
2a88f626 |
1667 | $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid'); |
e37cd84a |
1668 | |
1669 | /// Launch change of list of values for field stattype |
2a88f626 |
1670 | $dbman->drop_enum_from_field($table, $field); |
e37cd84a |
1671 | |
1672 | /// Changing list of values (enum) of field stattype on table stats_monthly to none |
1673 | $table = new xmldb_table('stats_monthly'); |
2a88f626 |
1674 | $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid'); |
e37cd84a |
1675 | |
1676 | /// Launch change of list of values for field stattype |
2a88f626 |
1677 | $dbman->drop_enum_from_field($table, $field); |
e37cd84a |
1678 | |
1679 | /// Changing list of values (enum) of field publishstate on table post to none |
1680 | $table = new xmldb_table('post'); |
2a88f626 |
1681 | $field = new xmldb_field('publishstate', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'draft', 'attachment'); |
e37cd84a |
1682 | |
1683 | /// Launch change of list of values for field publishstate |
2a88f626 |
1684 | $dbman->drop_enum_from_field($table, $field); |
e37cd84a |
1685 | |
1686 | /// Main savepoint reached |
1687 | upgrade_main_savepoint($result, 2009042700); |
1688 | } |
1689 | |
c045e45a |
1690 | if ($result && $oldversion < 2009043000) { |
1691 | unset_config('grade_report_showgroups'); |
1692 | upgrade_main_savepoint($result, 2009043000); |
1693 | } |
1694 | |
1695 | if ($result && $oldversion < 2009050600) { |
e88462a0 |
1696 | /// Site front page blocks need to be moved due to page name change. |
1697 | $DB->set_field('block_instance', 'pagetype', 'site-index', array('pagetype' => 'course-view', 'pageid' => SITEID)); |
1698 | |
1699 | /// Main savepoint reached |
c045e45a |
1700 | upgrade_main_savepoint($result, 2009050600); |
e88462a0 |
1701 | } |
1702 | |
c045e45a |
1703 | if ($result && $oldversion < 2009050601) { |
66b10689 |
1704 | |
3aceb097 |
1705 | /// Define table block_instance to be renamed to block_instances |
66b10689 |
1706 | $table = new xmldb_table('block_instance'); |
1707 | |
1708 | /// Launch rename table for block_instance |
3aceb097 |
1709 | $dbman->rename_table($table, 'block_instances'); |
66b10689 |
1710 | |
1711 | /// Main savepoint reached |
c045e45a |
1712 | upgrade_main_savepoint($result, 2009050601); |
66b10689 |
1713 | } |
1714 | |
c045e45a |
1715 | if ($result && $oldversion < 2009050602) { |
66b10689 |
1716 | |
1717 | /// Define table block_instance to be renamed to block_instance_old |
1718 | $table = new xmldb_table('block_pinned'); |
1719 | |
1720 | /// Launch rename table for block_instance |
1721 | $dbman->rename_table($table, 'block_pinned_old'); |
1722 | |
1723 | /// Main savepoint reached |
c045e45a |
1724 | upgrade_main_savepoint($result, 2009050602); |
66b10689 |
1725 | } |
1726 | |
c045e45a |
1727 | if ($result && $oldversion < 2009050603) { |
66b10689 |
1728 | |
1729 | /// Define table block_instance_old to be created |
1730 | $table = new xmldb_table('block_instance_old'); |
1731 | |
1732 | /// Adding fields to table block_instance_old |
2b212777 |
1733 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1734 | $table->add_field('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
1735 | $table->add_field('blockid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); |
1736 | $table->add_field('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); |
1737 | $table->add_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null); |
1738 | $table->add_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null); |
1739 | $table->add_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0'); |
1740 | $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0'); |
1741 | $table->add_field('configdata', XMLDB_TYPE_TEXT, 'small', null, null, null, null); |
66b10689 |
1742 | |
1743 | /// Adding keys to table block_instance_old |
1744 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
1745 | $table->add_key('blockid', XMLDB_KEY_FOREIGN, array('blockid'), 'block', array('id')); |
1746 | |
1747 | /// Adding indexes to table block_instance_old |
1748 | $table->add_index('pageid', XMLDB_INDEX_NOTUNIQUE, array('pageid')); |
1749 | $table->add_index('pagetype', XMLDB_INDEX_NOTUNIQUE, array('pagetype')); |
1750 | |
1751 | /// Conditionally launch create table for block_instance_old |
1752 | if (!$dbman->table_exists($table)) { |
1753 | $dbman->create_table($table); |
1754 | } |
1755 | |
1756 | /// Main savepoint reached |
c045e45a |
1757 | upgrade_main_savepoint($result, 2009050603); |
66b10689 |
1758 | } |
1759 | |
c045e45a |
1760 | if ($result && $oldversion < 2009050604) { |
66b10689 |
1761 | /// Copy current blocks data from block_instances to block_instance_old |
35550fd6 |
1762 | $DB->execute('INSERT INTO {block_instance_old} (oldid, blockid, pageid, pagetype, position, weight, visible, configdata) |
1763 | SELECT id, blockid, pageid, pagetype, position, weight, visible, configdata FROM {block_instances} ORDER BY id'); |
66b10689 |
1764 | |
c045e45a |
1765 | upgrade_main_savepoint($result, 2009050604); |
66b10689 |
1766 | } |
1767 | |
c045e45a |
1768 | if ($result && $oldversion < 2009050605) { |
66b10689 |
1769 | |
1770 | /// Define field multiple to be dropped from block |
1771 | $table = new xmldb_table('block'); |
1772 | $field = new xmldb_field('multiple'); |
1773 | |
1774 | /// Conditionally launch drop field multiple |
1775 | if ($dbman->field_exists($table, $field)) { |
1776 | $dbman->drop_field($table, $field); |
1777 | } |
1778 | |
1779 | /// Main savepoint reached |
c045e45a |
1780 | upgrade_main_savepoint($result, 2009050605); |
66b10689 |
1781 | } |
1782 | |
c045e45a |
1783 | if ($result && $oldversion < 2009050606) { |
66b10689 |
1784 | $table = new xmldb_table('block_instances'); |
1785 | |
1786 | /// Rename field weight on table block_instances to defaultweight |
2b212777 |
1787 | $field = new xmldb_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0', 'position'); |
66b10689 |
1788 | $dbman->rename_field($table, $field, 'defaultweight'); |
1789 | |
1790 | /// Rename field position on table block_instances to defaultregion |
2b212777 |
1791 | $field = new xmldb_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, 'pagetype'); |
66b10689 |
1792 | $dbman->rename_field($table, $field, 'defaultregion'); |
1793 | |
1794 | /// Main savepoint reached |
c045e45a |
1795 | upgrade_main_savepoint($result, 2009050606); |
66b10689 |
1796 | } |
1797 | |
c045e45a |
1798 | if ($result && $oldversion < 2009050607) { |
1e308b64 |
1799 | //TODO: remove, this field does not exist yet! |
66b10689 |
1800 | /// Changing precision of field defaultregion on table block_instances to (16) |
1e308b64 |
1801 | /* $table = new xmldb_table('block_instances'); |
2b212777 |
1802 | $field = new xmldb_field('defaultregion', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, 'subpagepattern'); |
66b10689 |
1803 | |
1804 | /// Launch change of precision for field defaultregion |
1805 | $dbman->change_field_precision($table, $field); |
1806 | |
1807 | /// Main savepoint reached |
1e308b64 |
1808 | upgrade_main_savepoint($result, 2009050607);*/ |
66b10689 |
1809 | } |
1810 | |
c045e45a |
1811 | if ($result && $oldversion < 2009050608) { |
66b10689 |
1812 | /// Change regions to the new notation |
1813 | $DB->set_field('block_instances', 'defaultregion', 'side-pre', array('defaultregion' => 'l')); |
1814 | $DB->set_field('block_instances', 'defaultregion', 'side-post', array('defaultregion' => 'r')); |
1815 | $DB->set_field('block_instances', 'defaultregion', 'course-view-top', array('defaultregion' => 'c')); |
1816 | // This third one is a custom value from contrib/patches/center_blocks_position_patch and the |
1817 | // flex page course format. Hopefully this new value is an adequate alternative. |
1818 | |
1819 | /// Main savepoint reached |
c045e45a |
1820 | upgrade_main_savepoint($result, 2009050608); |
66b10689 |
1821 | } |
1822 | |
c045e45a |
1823 | if ($result && $oldversion < 2009050609) { |
66b10689 |
1824 | |
1825 | /// Define key blockname (unique) to be added to block |
1826 | $table = new xmldb_table('block'); |
1827 | $key = new xmldb_key('blockname', XMLDB_KEY_UNIQUE, array('name')); |
1828 | |
1829 | /// Launch add key blockname |
1830 | $dbman->add_key($table, $key); |
1831 | |
1832 | /// Main savepoint reached |
c045e45a |
1833 | upgrade_main_savepoint($result, 2009050609); |
66b10689 |
1834 | } |
1835 | |
c045e45a |
1836 | if ($result && $oldversion < 2009050610) { |
66b10689 |
1837 | $table = new xmldb_table('block_instances'); |
1838 | |
1839 | /// Define field blockname to be added to block_instances |
2b212777 |
1840 | $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, null, null, null, 'blockid'); |
66b10689 |
1841 | if (!$dbman->field_exists($table, $field)) { |
1842 | $dbman->add_field($table, $field); |
1843 | } |
1844 | |
1845 | /// Define field contextid to be added to block_instances |
2b212777 |
1846 | $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'blockname'); |
66b10689 |
1847 | if (!$dbman->field_exists($table, $field)) { |
1848 | $dbman->add_field($table, $field); |
1849 | } |
1850 | |
1851 | /// Define field showinsubcontexts to be added to block_instances |
2b212777 |
1852 | $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, null, null, null, 'contextid'); |
66b10689 |
1853 | if (!$dbman->field_exists($table, $field)) { |
1854 | $dbman->add_field($table, $field); |
1855 | } |
1856 | |
1857 | /// Define field subpagepattern to be added to block_instances |
2b212777 |
1858 | $field = new xmldb_field('subpagepattern', XMLDB_TYPE_CHAR, '16', null, null, null, null, 'pagetype'); |
66b10689 |
1859 | if (!$dbman->field_exists($table, $field)) { |
1860 | $dbman->add_field($table, $field); |
1861 | } |
1862 | |
1863 | /// Main savepoint reached |
c045e45a |
1864 | upgrade_main_savepoint($result, 2009050610); |
66b10689 |
1865 | } |
1866 | |
c045e45a |
1867 | if ($result && $oldversion < 2009050611) { |
66b10689 |
1868 | $table = new xmldb_table('block_instances'); |
1869 | |
1870 | /// Fill in blockname from blockid |
1871 | $DB->execute("UPDATE {block_instances} SET blockname = (SELECT name FROM {block} WHERE id = blockid)"); |
1872 | |
1873 | /// Set showinsubcontexts = 0 for all rows. |
1874 | $DB->execute("UPDATE {block_instances} SET showinsubcontexts = 0"); |
1875 | |
1876 | /// Main savepoint reached |
c045e45a |
1877 | upgrade_main_savepoint($result, 2009050611); |
66b10689 |
1878 | } |
1879 | |
c045e45a |
1880 | if ($result && $oldversion < 2009050612) { |
66b10689 |
1881 | |
1882 | /// Rename field pagetype on table block_instances to pagetypepattern |
1883 | $table = new xmldb_table('block_instances'); |
2b212777 |
1884 | $field = new xmldb_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'pageid'); |
66b10689 |
1885 | |
1886 | /// Launch rename field pagetype |
1887 | $dbman->rename_field($table, $field, 'pagetypepattern'); |
1888 | |
1889 | /// Main savepoint reached |
c045e45a |
1890 | upgrade_main_savepoint($result, 2009050612); |
66b10689 |
1891 | } |
1892 | |
c045e45a |
1893 | if ($result && $oldversion < 2009050613) { |
66b10689 |
1894 | /// fill in contextid and subpage, and update pagetypepattern from pagetype and pageid |
1895 | |
1896 | /// site-index |
1897 | $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID); |
eb2761f8 |
1898 | $DB->execute("UPDATE {block_instances} SET contextid = " . $frontpagecontext->id . ", |
1899 | pagetypepattern = 'site-index', |
1900 | subpagepattern = NULL |
1901 | WHERE pagetypepattern = 'site-index'"); |
66b10689 |
1902 | |
1903 | /// course-view |
eb2761f8 |
1904 | $DB->execute("UPDATE {block_instances} SET |
1905 | contextid = ( |
1906 | SELECT {context}.id |
1907 | FROM {context} |
1908 | JOIN {course} ON instanceid = {course}.id AND contextlevel = " . CONTEXT_COURSE . " |
1909 | WHERE {course}.id = pageid |
1910 | ), |
1911 | pagetypepattern = 'course-view-*', |
1912 | subpagepattern = NULL |
1913 | WHERE pagetypepattern = 'course-view'"); |
66b10689 |
1914 | |
1915 | /// admin |
1916 | $syscontext = get_context_instance(CONTEXT_SYSTEM); |
eb2761f8 |
1917 | $DB->execute("UPDATE {block_instances} SET |
1918 | contextid = " . $syscontext->id . ", |
1919 | pagetypepattern = 'admin-*', |
1920 | subpagepattern = NULL |
1921 | WHERE pagetypepattern = 'admin'"); |
66b10689 |
1922 | |
1923 | /// my-index |
eb2761f8 |
1924 | $DB->execute("UPDATE {block_instances} SET |
1925 | contextid = ( |
1926 | SELECT {context}.id |
1927 | FROM {context} |
1928 | JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . " |
1929 | WHERE {user}.id = pageid |
1930 | ), |
1931 | pagetypepattern = 'my-index', |
1932 | subpagepattern = NULL |
1933 | WHERE pagetypepattern = 'my-index'"); |
66b10689 |
1934 | |
1935 | /// tag-index |
eb2761f8 |
1936 | $DB->execute("UPDATE {block_instances} SET |
1937 | contextid = " . $syscontext->id . ", |
1938 | pagetypepattern = 'tag-index', |
1939 | subpagepattern = pageid |
1940 | WHERE pagetypepattern = 'tag-index'"); |
66b10689 |
1941 | |
1942 | /// blog-view |
eb2761f8 |
1943 | $DB->execute("UPDATE {block_instances} SET |
1944 | contextid = ( |
1945 | SELECT {context}.id |
1946 | FROM {context} |
1947 | JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . " |
1948 | WHERE {user}.id = pageid |
1949 | ), |
1950 | pagetypepattern = 'blog-index', |
1951 | subpagepattern = NULL |
1952 | WHERE pagetypepattern = 'blog-view'"); |
66b10689 |
1953 | |
1954 | /// mod-xxx-view |
1955 | $moduleswithblocks = array('chat', 'data', 'lesson', 'quiz', 'dimdim', 'game', 'wiki', 'oublog'); |
1956 | foreach ($moduleswithblocks as $modname) { |
1957 | if (!$dbman->table_exists($modname)) { |
1958 | continue; |
1959 | } |
eb2761f8 |
1960 | $DB->execute("UPDATE {block_instances} SET |
1961 | contextid = ( |
1962 | SELECT {context}.id |
1963 | FROM {context} |
1964 | JOIN {course_modules} ON instanceid = {course_modules}.id AND contextlevel = " . CONTEXT_MODULE . " |
1965 | JOIN {modules} ON {modules}.id = {course_modules}.module AND {modules}.name = '$modname' |
1966 | JOIN {{$modname}} ON {course_modules}.instance = {{$modname}}.id |
1967 | WHERE {{$modname}}.id = pageid |
1968 | ), |
1969 | pagetypepattern = 'blog-index', |
1970 | subpagepattern = NULL |
1971 | WHERE pagetypepattern = 'blog-view'"); |
66b10689 |
1972 | } |
1973 | |
1974 | /// Main savepoint reached |
c045e45a |
1975 | upgrade_main_savepoint($result, 2009050613); |
66b10689 |
1976 | } |
1977 | |
c045e45a |
1978 | if ($result && $oldversion < 2009050614) { |
66b10689 |
1979 | /// fill in any missing contextids with a dummy value, so we can add the not-null constraint. |
1980 | $DB->execute("UPDATE {block_instances} SET contextid = -1 WHERE contextid IS NULL"); |
1981 | |
1982 | /// Main savepoint reached |
c045e45a |
1983 | upgrade_main_savepoint($result, 2009050614); |
66b10689 |
1984 | } |
1985 | |
c045e45a |
1986 | if ($result && $oldversion < 2009050615) { |
66b10689 |
1987 | $table = new xmldb_table('block_instances'); |
1988 | |
1989 | /// Changing nullability of field blockname on table block_instances to not null |
2b212777 |
1990 | $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'id'); |
66b10689 |
1991 | $dbman->change_field_notnull($table, $field); |
1992 | |
1993 | /// Changing nullability of field contextid on table block_instances to not null |
2b212777 |
1994 | $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'blockname'); |
66b10689 |
1995 | $dbman->change_field_notnull($table, $field); |
1996 | |
1997 | /// Changing nullability of field showinsubcontexts on table block_instances to not null |
2b212777 |
1998 | $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, 'contextid'); |
66b10689 |
1999 | $dbman->change_field_notnull($table, $field); |
2000 | |
2001 | /// Main savepoint reached |
c045e45a |
2002 | upgrade_main_savepoint($result, 2009050615); |
66b10689 |
2003 | } |
2004 | |
c045e45a |
2005 | if ($result && $oldversion < 2009050616) { |
66b10689 |
2006 | /// Add exiting sticky blocks. |
2007 | $blocks = $DB->get_records('block'); |
2008 | $syscontext = get_context_instance(CONTEXT_SYSTEM); |
2009 | $newregions = array( |
2010 | 'l' => 'side-pre', |
2011 | 'r' => 'side-post', |
2012 | 'c' => 'course-view-top', |
2013 | ); |
2014 | $stickyblocks = $DB->get_recordset('block_pinned_old'); |
2015 | foreach ($stickyblocks as $stickyblock) { |
2016 | $newblock = stdClass; |
2017 | $newblock->blockname = $blocks[$stickyblock]->name; |
2018 | $newblock->contextid = $syscontext->id; |
2019 | $newblock->showinsubcontexts = 1; |
2020 | switch ($stickyblock->pagetype) { |
2021 | case 'course-view': |
2022 | $newblock->pagetypepattern = 'course-view-*'; |
2023 | break; |
2024 | default: |
2025 | $newblock->pagetypepattern = $stickyblock->pagetype; |
2026 | } |
2027 | $newblock->defaultregion = $newregions[$stickyblock->position]; |
2028 | $newblock->defaultweight = $stickyblock->weight; |
2029 | $newblock->configdata = $stickyblock->configdata; |
2030 | $DB->insert_record('block_instances', $newblock); |
2031 | } |
2032 | |
2033 | /// Main savepoint reached |
c045e45a |
2034 | upgrade_main_savepoint($result, 2009050616); |
66b10689 |
2035 | } |
2036 | |
c045e45a |
2037 | if ($result && $oldversion < 2009050617) { |
66b10689 |
2038 | |
2039 | /// Define table block_positions to be created |
2040 | $table = new xmldb_table('block_positions'); |
2041 | |
2042 | /// Adding fields to table block_positions |
2b212777 |
2043 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
2044 | $table->add_field('blockinstanceid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
2045 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
2046 | $table->add_field('pagetype', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null); |
2047 | $table->add_field('subpage', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null); |
2048 | $table->add_field('visible', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '1'); |
2049 | $table->add_field('region', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null); |
2050 | $table->add_field('weight', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
66b10689 |
2051 | |
2052 | /// Adding keys to table block_positions |
2053 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
2054 | $table->add_key('blockinstanceid', XMLDB_KEY_FOREIGN, array('blockinstanceid'), 'block_instances', array('id')); |
2055 | $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); |
2056 | |
2057 | /// Adding indexes to table block_positions |
2058 | $table->add_index('blockinstanceid-contextid-pagetype-subpage', XMLDB_INDEX_UNIQUE, array('blockinstanceid', 'contextid', 'pagetype', 'subpage')); |
2059 | |
2060 | /// Conditionally launch create table for block_positions |
2061 | if (!$dbman->table_exists($table)) { |
2062 | $dbman->create_table($table); |
2063 | } |
2064 | |
2065 | /// Main savepoint reached |
c045e45a |
2066 | upgrade_main_savepoint($result, 2009050617); |
66b10689 |
2067 | } |
2068 | |
c045e45a |
2069 | if ($result && $oldversion < 2009050618) { |
66b10689 |
2070 | /// And block instances with visible = 0, copy that information to block_positions |
2071 | $DB->execute("INSERT INTO {block_positions} (blockinstanceid, contextid, pagetype, subpage, visible, region, weight) |
2072 | SELECT id, contextid, |
2073 | CASE WHEN pagetypepattern = 'course-view-*' THEN |
2074 | (SELECT " . $DB->sql_concat("'course-view-'", 'format') . " |
2075 | FROM {course} |
2076 | JOIN {context} ON {course}.id = {context}.instanceid |
2077 | WHERE {context}.id = contextid) |
2078 | ELSE pagetypepattern END, |
2079 | CASE WHEN subpagepattern IS NULL THEN '' |
2080 | ELSE subpagepattern END, |
2081 | 0, defaultregion, defaultweight |
2082 | FROM {block_instances} WHERE visible = 0 AND pagetypepattern <> 'admin-*'"); |
2083 | |
2084 | /// Main savepoint reached |
c045e45a |
2085 | upgrade_main_savepoint($result, 2009050618); |
66b10689 |
2086 | } |
2087 | |
c045e45a |
2088 | if ($result && $oldversion < 2009050619) { |
66b10689 |
2089 | $table = new xmldb_table('block_instances'); |
2090 | |
2091 | /// Define field blockid to be dropped from block_instances |
2092 | $field = new xmldb_field('blockid'); |
2093 | if ($dbman->field_exists($table, $field)) { |
2094 | $dbman->drop_field($table, $field); |
2095 | } |
2096 | |
2097 | /// Define field pageid to be dropped from block_instances |
2098 | $field = new xmldb_field('pageid'); |
2099 | if ($dbman->field_exists($table, $field)) { |
2100 | $dbman->drop_field($table, $field); |
2101 | } |
2102 | |
2103 | /// Define field visible to be dropped from block_instances |
2104 | $field = new xmldb_field('visible'); |
2105 | if ($dbman->field_exists($table, $field)) { |
2106 | $dbman->drop_field($table, $field); |
2107 | } |
2108 | |
2109 | /// Main savepoint reached |
c045e45a |
2110 | upgrade_main_savepoint($result, 2009050619); |
35079f53 |
2111 | } |
2112 | |
ecdf5d17 |
2113 | if ($result && $oldversion < 2009051200) { |
2114 | /// Let's check the status of mandatory mnet_host records, fixing them |
2115 | /// and moving "orphan" users to default localhost record. MDL-16879 |
2116 | notify('Fixing mnet records, this may take a while...', 'notifysuccess'); |
2117 | upgrade_fix_incorrect_mnethostids(); |
2118 | |
2119 | /// Main savepoint reached |
2120 | upgrade_main_savepoint($result, 2009051200); |
2121 | } |
2122 | |
a5747cf8 |
2123 | |
2124 | if ($result && $oldversion < 2009051700) { |
2125 | /// migrate editor settings |
2126 | if (empty($CFG->htmleditor)) { |
2127 | set_config('texteditors', 'textarea'); |
2128 | } else { |
2129 | set_config('texteditors', 'tinymce,textarea'); |
2130 | } |
2131 | |
2132 | unset_config('htmleditor'); |
2133 | unset_config('defaulthtmleditor'); |
2134 | |
2135 | /// Main savepoint reached |
2136 | upgrade_main_savepoint($result, 2009051700); |
2137 | } |
2138 | |
1aa01caf |
2139 | if ($result && $oldversion < 2009060200) { |
2140 | /// Define table files_cleanup to be dropped - not needed |
2141 | $table = new xmldb_table('files_cleanup'); |
2142 | |
2143 | /// Conditionally launch drop table for files_cleanup |
2144 | if ($dbman->table_exists($table)) { |
2145 | $dbman->drop_table($table); |
2146 | } |
2147 | |
2148 | /// Main savepoint reached |
2149 | upgrade_main_savepoint($result, 2009060200); |
2150 | } |
2151 | |
ac9b0805 |
2152 | return $result; |
4e423cbf |
2153 | } |
271e6dec |
2154 | |