Commit | Line | Data |
---|---|---|
5b4a78e2 | 1 | <?php |
5b4a78e2 | 2 | // This file is part of Moodle - http://moodle.org/ |
4e423cbf | 3 | // |
5b4a78e2 PS |
4 | // Moodle is free software: you can redistribute it and/or modify |
5 | // it under the terms of the GNU General Public License as published by | |
6 | // the Free Software Foundation, either version 3 of the License, or | |
7 | // (at your option) any later version. | |
4e423cbf | 8 | // |
5b4a78e2 PS |
9 | // Moodle is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
4e423cbf | 13 | // |
5b4a78e2 PS |
14 | // You should have received a copy of the GNU General Public License |
15 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
16 | ||
17 | /** | |
18 | * This file keeps track of upgrades to Moodle. | |
19 | * | |
20 | * Sometimes, changes between versions involve | |
21 | * alterations to database structures and other | |
22 | * major things that may break installations. | |
23 | * | |
24 | * The upgrade function in this file will attempt | |
25 | * to perform all the necessary actions to upgrade | |
26 | * your older installation to the current version. | |
27 | * | |
28 | * If there's something it cannot do itself, it | |
29 | * will tell you what you need to do. | |
30 | * | |
31 | * The commands in here will all be database-neutral, | |
32 | * using the methods of database_manager class | |
33 | * | |
34 | * Please do not forget to use upgrade_set_timeout() | |
35 | * before any action that may take longer time to finish. | |
36 | * | |
39b90b51 EL |
37 | * @package core_install |
38 | * @category upgrade | |
39 | * @copyright 2006 onwards Martin Dougiamas http://dougiamas.com | |
40 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
5b4a78e2 PS |
41 | */ |
42 | ||
43 | defined('MOODLE_INTERNAL') || die(); | |
4e423cbf | 44 | |
3406acde | 45 | /** |
39b90b51 EL |
46 | * Main upgrade tasks to be executed on Moodle version bump |
47 | * | |
48 | * This function is automatically executed after one bump in the Moodle core | |
f9488a6f | 49 | * version is detected. It's in charge of performing the required tasks |
39b90b51 EL |
50 | * to raise core from the previous version to the next one. |
51 | * | |
52 | * It's a collection of ordered blocks of code, named "upgrade steps", | |
f9488a6f | 53 | * each one performing one isolated (from the rest of steps) task. Usually |
39b90b51 EL |
54 | * tasks involve creating new DB objects or performing manipulation of the |
55 | * information for cleanup/fixup purposes. | |
56 | * | |
57 | * Each upgrade step has a fixed structure, that can be summarised as follows: | |
58 | * | |
59 | * if ($oldversion < XXXXXXXXXX.XX) { | |
f9488a6f | 60 | * // Explanation of the update step, linking to issue in the Tracker if necessary |
39b90b51 EL |
61 | * upgrade_set_timeout(XX); // Optional for big tasks |
62 | * // Code to execute goes here, usually the XMLDB Editor will | |
63 | * // help you here. See {@link http://docs.moodle.org/dev/XMLDB_editor}. | |
64 | * upgrade_main_savepoint(true, XXXXXXXXXX.XX); | |
65 | * } | |
66 | * | |
67 | * All plugins within Moodle (modules, blocks, reports...) support the existence of | |
68 | * their own upgrade.php file, using the "Frankenstyle" component name as | |
69 | * defined at {@link http://docs.moodle.org/dev/Frankenstyle}, for example: | |
70 | * - {@link xmldb_page_upgrade($oldversion)}. (modules don't require the plugintype ("mod_") to be used. | |
71 | * - {@link xmldb_auth_manual_upgrade($oldversion)}. | |
72 | * - {@link xmldb_workshopform_accumulative_upgrade($oldversion)}. | |
73 | * - .... | |
74 | * | |
75 | * In order to keep the contents of this file reduced, it's allowed to create some helper | |
76 | * functions to be used here in the {@link upgradelib.php} file at the same directory. Note | |
f9488a6f | 77 | * that such a file must be manually included from upgrade.php, and there are some restrictions |
39b90b51 EL |
78 | * about what can be used within it. |
79 | * | |
80 | * For more information, take a look to the documentation available: | |
81 | * - Data definition API: {@link http://docs.moodle.org/dev/Data_definition_API} | |
82 | * - Upgrade API: {@link http://docs.moodle.org/dev/Upgrade_API} | |
3406acde | 83 | * |
3406acde | 84 | * @param int $oldversion |
5b4a78e2 | 85 | * @return bool always true |
3406acde | 86 | */ |
775f811a | 87 | function xmldb_main_upgrade($oldversion) { |
3713514b | 88 | global $CFG, $USER, $DB, $OUTPUT, $SITE; |
4e423cbf | 89 | |
4f12838e | 90 | require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions |
13a0d3d3 | 91 | |
46d318bc | 92 | $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes |
f33e1ed4 | 93 | |
5c79b8ed PS |
94 | if ($oldversion < 2011120500) { |
95 | // just in case somebody hacks upgrade scripts or env, we really can not continue | |
96 | echo("You need to upgrade to 2.2.x first!\n"); | |
97 | exit(1); | |
ae95489d EL |
98 | // Note this savepoint is 100% unreachable, but needed to pass the upgrade checks |
99 | upgrade_main_savepoint(true, 2011120500); | |
5c79b8ed PS |
100 | } |
101 | ||
39b90b51 EL |
102 | // Moodle v2.2.0 release upgrade line |
103 | // Put any upgrade step following this | |
da4aa3e4 | 104 | |
43cf3165 EL |
105 | if ($oldversion < 2011120500.02) { |
106 | ||
107 | upgrade_set_timeout(60*20); // This may take a while | |
108 | // MDL-28180. Some missing restrictions in certain backup & restore operations | |
109 | // were causing incorrect duplicates in the course_completion_aggr_methd table. | |
110 | // This upgrade step takes rid of them. | |
111 | $sql = 'SELECT course, criteriatype, MIN(id) AS minid | |
112 | FROM {course_completion_aggr_methd} | |
113 | GROUP BY course, criteriatype | |
114 | HAVING COUNT(*) > 1'; | |
115 | $duprs = $DB->get_recordset_sql($sql); | |
116 | foreach ($duprs as $duprec) { | |
117 | // We need to handle NULLs in criteriatype diferently | |
118 | if (is_null($duprec->criteriatype)) { | |
119 | $where = 'course = ? AND criteriatype IS NULL AND id > ?'; | |
120 | $params = array($duprec->course, $duprec->minid); | |
121 | } else { | |
122 | $where = 'course = ? AND criteriatype = ? AND id > ?'; | |
123 | $params = array($duprec->course, $duprec->criteriatype, $duprec->minid); | |
124 | } | |
125 | $DB->delete_records_select('course_completion_aggr_methd', $where, $params); | |
126 | } | |
127 | $duprs->close(); | |
128 | ||
129 | // Main savepoint reached | |
130 | upgrade_main_savepoint(true, 2011120500.02); | |
131 | } | |
132 | ||
52a23063 | 133 | if ($oldversion < 2011120500.03) { |
8e54ce97 AD |
134 | |
135 | // Changing precision of field value on table user_preferences to (1333) | |
136 | $table = new xmldb_table('user_preferences'); | |
137 | $field = new xmldb_field('value', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'name'); | |
138 | ||
139 | // Launch change of precision for field value | |
140 | $dbman->change_field_precision($table, $field); | |
141 | ||
142 | // Main savepoint reached | |
52a23063 | 143 | upgrade_main_savepoint(true, 2011120500.03); |
8e54ce97 AD |
144 | } |
145 | ||
91331b6b MG |
146 | if ($oldversion < 2012020200.03) { |
147 | ||
148 | // Define index rolecontext (not unique) to be added to role_assignments | |
149 | $table = new xmldb_table('role_assignments'); | |
150 | $index = new xmldb_index('rolecontext', XMLDB_INDEX_NOTUNIQUE, array('roleid', 'contextid')); | |
151 | ||
152 | // Conditionally launch add index rolecontext | |
153 | if (!$dbman->index_exists($table, $index)) { | |
154 | $dbman->add_index($table, $index); | |
155 | } | |
156 | ||
157 | // Define index usercontextrole (not unique) to be added to role_assignments | |
158 | $index = new xmldb_index('usercontextrole', XMLDB_INDEX_NOTUNIQUE, array('userid', 'contextid', 'roleid')); | |
159 | ||
160 | // Conditionally launch add index usercontextrole | |
161 | if (!$dbman->index_exists($table, $index)) { | |
162 | $dbman->add_index($table, $index); | |
163 | } | |
164 | ||
165 | // Main savepoint reached | |
166 | upgrade_main_savepoint(true, 2012020200.03); | |
167 | } | |
168 | ||
8900213b AD |
169 | if ($oldversion < 2012020200.06) { |
170 | // Previously we always allowed users to override their email address via the messaging system | |
171 | // We have now added a setting to allow admins to turn this this ability on and off | |
172 | // While this setting defaults to 0 (off) we're setting it to 1 (on) to maintain the behaviour for upgrading sites | |
173 | set_config('messagingallowemailoverride', 1); | |
174 | ||
175 | // Main savepoint reached | |
176 | upgrade_main_savepoint(true, 2012020200.06); | |
177 | } | |
178 | ||
bc5fbbb3 | 179 | if ($oldversion < 2012021700.01) { |
669bdcab RT |
180 | // Changing precision of field uniquehash on table post to 255 |
181 | $table = new xmldb_table('post'); | |
182 | $field = new xmldb_field('uniquehash', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'content'); | |
183 | ||
184 | // Launch change of precision for field uniquehash | |
185 | $dbman->change_field_precision($table, $field); | |
186 | ||
187 | // Main savepoint reached | |
bc5fbbb3 | 188 | upgrade_main_savepoint(true, 2012021700.01); |
669bdcab RT |
189 | } |
190 | ||
aa803ceb RT |
191 | if ($oldversion < 2012021700.02) { |
192 | // Somewhere before 1.9 summary and content column in post table were not null. In 1.9+ | |
193 | // not null became false. | |
194 | $columns = $DB->get_columns('post'); | |
195 | ||
196 | // Fix discrepancies in summary field after upgrade from 1.9 | |
197 | if (array_key_exists('summary', $columns) && $columns['summary']->not_null != false) { | |
198 | $table = new xmldb_table('post'); | |
199 | $summaryfield = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'big', null, null, null, null, 'subject'); | |
5f5ee191 | 200 | |
aa803ceb RT |
201 | if ($dbman->field_exists($table, $summaryfield)) { |
202 | $dbman->change_field_notnull($table, $summaryfield); | |
203 | } | |
204 | ||
205 | } | |
206 | ||
207 | // Fix discrepancies in content field after upgrade from 1.9 | |
208 | if (array_key_exists('content', $columns) && $columns['content']->not_null != false) { | |
209 | $table = new xmldb_table('post'); | |
210 | $contentfield = new xmldb_field('content', XMLDB_TYPE_TEXT, 'big', null, null, null, null, 'summary'); | |
211 | ||
212 | if ($dbman->field_exists($table, $contentfield)) { | |
213 | $dbman->change_field_notnull($table, $contentfield); | |
214 | } | |
215 | ||
216 | } | |
217 | ||
218 | upgrade_main_savepoint(true, 2012021700.02); | |
219 | } | |
220 | ||
f8822462 EL |
221 | // The ability to backup user (private) files is out completely - MDL-29248 |
222 | if ($oldversion < 2012030100.01) { | |
223 | unset_config('backup_general_user_files', 'backup'); | |
224 | unset_config('backup_general_user_files_locked', 'backup'); | |
225 | unset_config('backup_auto_user_files', 'backup'); | |
226 | ||
227 | upgrade_main_savepoint(true, 2012030100.01); | |
228 | } | |
229 | ||
436650b0 | 230 | if ($oldversion < 2012030900.01) { |
801ae0f4 PS |
231 | // Migrate all numbers to signed & all texts and binaries to big size. |
232 | // It should be safe to interrupt this and continue later. | |
233 | upgrade_mysql_fix_unsigned_and_lob_columns(); | |
436650b0 PS |
234 | |
235 | // Main savepoint reached | |
236 | upgrade_main_savepoint(true, 2012030900.01); | |
237 | } | |
238 | ||
9665ecd2 TH |
239 | if ($oldversion < 2012031500.01) { |
240 | // Upgrade old course_allowed_modules data to be permission overrides. | |
6f3570ff | 241 | if ($CFG->restrictmodulesfor === 'all') { |
9665ecd2 | 242 | $courses = $DB->get_records_menu('course', array(), 'id', 'id, 1'); |
6f3570ff | 243 | } else if ($CFG->restrictmodulesfor === 'requested') { |
e08eaf7d | 244 | $courses = $DB->get_records_menu('course', array('restrictmodules' => 1), 'id', 'id, 1'); |
9665ecd2 TH |
245 | } else { |
246 | $courses = array(); | |
247 | } | |
248 | ||
249 | if (!$dbman->table_exists('course_allowed_modules')) { | |
250 | // Upgrade must already have been run on this server. This might happen, | |
251 | // for example, during development of these changes. | |
252 | $courses = array(); | |
253 | } | |
254 | ||
255 | $modidtoname = $DB->get_records_menu('modules', array(), 'id', 'id, name'); | |
256 | ||
257 | $coursecount = count($courses); | |
258 | if ($coursecount) { | |
259 | $pbar = new progress_bar('allowedmods', 500, true); | |
260 | $transaction = $DB->start_delegated_transaction(); | |
261 | } | |
262 | ||
263 | $i = 0; | |
264 | foreach ($courses as $courseid => $notused) { | |
265 | $i += 1; | |
266 | upgrade_set_timeout(60); // 1 minute per course should be fine. | |
267 | ||
268 | $allowedmoduleids = $DB->get_records_menu('course_allowed_modules', | |
269 | array('course' => $courseid), 'module', 'module, 1'); | |
270 | if (empty($allowedmoduleids)) { | |
271 | // This seems to be the best match for backwards compatibility, | |
8149d624 | 272 | // not necessarily with the old code in course_allowed_module function, |
9665ecd2 TH |
273 | // but with the code that used to be in the coures settings form. |
274 | $allowedmoduleids = explode(',', $CFG->defaultallowedmodules); | |
275 | $allowedmoduleids = array_combine($allowedmoduleids, $allowedmoduleids); | |
276 | } | |
277 | ||
278 | $context = context_course::instance($courseid); | |
279 | ||
280 | list($roleids) = get_roles_with_cap_in_context($context, 'moodle/course:manageactivities'); | |
281 | list($managerroleids) = get_roles_with_cap_in_context($context, 'moodle/site:config'); | |
282 | foreach ($managerroleids as $roleid) { | |
283 | unset($roleids[$roleid]); | |
284 | } | |
285 | ||
286 | foreach ($modidtoname as $modid => $modname) { | |
287 | if (isset($allowedmoduleids[$modid])) { | |
288 | // Module is allowed, no worries. | |
289 | continue; | |
290 | } | |
291 | ||
292 | $capability = 'mod/' . $modname . ':addinstance'; | |
293 | foreach ($roleids as $roleid) { | |
294 | assign_capability($capability, CAP_PREVENT, $roleid, $context); | |
295 | } | |
296 | } | |
297 | ||
298 | $pbar->update($i, $coursecount, "Upgrading legacy course_allowed_modules data - $i/$coursecount."); | |
299 | } | |
300 | ||
301 | if ($coursecount) { | |
302 | $transaction->allow_commit(); | |
303 | } | |
304 | ||
305 | upgrade_main_savepoint(true, 2012031500.01); | |
306 | } | |
307 | ||
308 | if ($oldversion < 2012031500.02) { | |
309 | ||
e08eaf7d | 310 | // Define field restrictmodules to be dropped from course |
9665ecd2 | 311 | $table = new xmldb_table('course'); |
4354486d | 312 | $field = new xmldb_field('restrictmodules'); |
9665ecd2 TH |
313 | |
314 | // Conditionally launch drop field requested | |
315 | if ($dbman->field_exists($table, $field)) { | |
316 | $dbman->drop_field($table, $field); | |
317 | } | |
318 | ||
319 | upgrade_main_savepoint(true, 2012031500.02); | |
320 | } | |
321 | ||
322 | if ($oldversion < 2012031500.03) { | |
323 | ||
324 | // Define table course_allowed_modules to be dropped | |
325 | $table = new xmldb_table('course_allowed_modules'); | |
326 | ||
327 | // Conditionally launch drop table for course_allowed_modules | |
328 | if ($dbman->table_exists($table)) { | |
329 | $dbman->drop_table($table); | |
330 | } | |
331 | ||
332 | upgrade_main_savepoint(true, 2012031500.03); | |
333 | } | |
334 | ||
335 | if ($oldversion < 2012031500.04) { | |
336 | // Clean up the old admin settings. | |
337 | unset_config('restrictmodulesfor'); | |
338 | unset_config('restrictbydefault'); | |
339 | unset_config('defaultallowedmodules'); | |
340 | ||
341 | upgrade_main_savepoint(true, 2012031500.04); | |
342 | } | |
e9e4a4a6 | 343 | |
e63f95d7 PS |
344 | if ($oldversion < 2012032300.02) { |
345 | // Migrate the old admin debug setting. | |
346 | if ($CFG->debug == 38911) { | |
347 | set_config('debug', DEBUG_DEVELOPER); | |
348 | } else if ($CFG->debug == 6143) { | |
349 | set_config('debug', DEBUG_ALL); | |
350 | } | |
351 | upgrade_main_savepoint(true, 2012032300.02); | |
352 | } | |
353 | ||
e7e0f8d2 DP |
354 | if ($oldversion < 2012042300.00) { |
355 | // This change makes the course_section index unique. | |
356 | ||
cf76b335 | 357 | // xmldb does not allow changing index uniqueness - instead we must drop |
e7e0f8d2 DP |
358 | // index then add it again |
359 | $table = new xmldb_table('course_sections'); | |
cf76b335 | 360 | $index = new xmldb_index('course_section', XMLDB_INDEX_NOTUNIQUE, array('course', 'section')); |
e7e0f8d2 DP |
361 | |
362 | // Conditionally launch drop index course_section | |
363 | if ($dbman->index_exists($table, $index)) { | |
364 | $dbman->drop_index($table, $index); | |
365 | } | |
cf76b335 | 366 | |
367 | // Look for any duplicate course_sections entries. There should not be | |
368 | // any but on some busy systems we found a few, maybe due to previous | |
369 | // bugs. | |
370 | $transaction = $DB->start_delegated_transaction(); | |
371 | $rs = $DB->get_recordset_sql(' | |
372 | SELECT DISTINCT | |
373 | cs.id, cs.course | |
374 | FROM | |
375 | {course_sections} cs | |
376 | INNER JOIN {course_sections} older | |
377 | ON cs.course = older.course AND cs.section = older.section | |
378 | AND older.id < cs.id'); | |
379 | foreach ($rs as $rec) { | |
380 | $DB->delete_records('course_sections', array('id' => $rec->id)); | |
026082b4 DP |
381 | // We can't use rebuild_course_cache() here because introducing sectioncache later |
382 | // so reset modinfo manually. | |
383 | $DB->set_field('course', 'modinfo', null, array('id' => $rec->course)); | |
cf76b335 | 384 | } |
385 | $rs->close(); | |
386 | $transaction->allow_commit(); | |
387 | ||
388 | // Define index course_section (unique) to be added to course_sections | |
389 | $index = new xmldb_index('course_section', XMLDB_INDEX_UNIQUE, array('course', 'section')); | |
390 | ||
391 | // Conditionally launch add index course_section | |
392 | if (!$dbman->index_exists($table, $index)) { | |
393 | $dbman->add_index($table, $index); | |
394 | } | |
395 | ||
396 | // Main savepoint reached | |
e7e0f8d2 | 397 | upgrade_main_savepoint(true, 2012042300.00); |
cf76b335 | 398 | } |
296c0247 | 399 | |
ede323e2 | 400 | if ($oldversion < 2012042300.02) { |
60829d80 | 401 | require_once($CFG->dirroot.'/completion/criteria/completion_criteria.php'); |
ede323e2 ARN |
402 | // Delete orphaned criteria which were left when modules were removed |
403 | if ($DB->get_dbfamily() === 'mysql') { | |
404 | $sql = "DELETE cc FROM {course_completion_criteria} cc | |
405 | LEFT JOIN {course_modules} cm ON cm.id = cc.moduleinstance | |
406 | WHERE cm.id IS NULL AND cc.criteriatype = ".COMPLETION_CRITERIA_TYPE_ACTIVITY; | |
407 | } else { | |
408 | $sql = "DELETE FROM {course_completion_criteria} | |
409 | WHERE NOT EXISTS ( | |
410 | SELECT 'x' FROM {course_modules} | |
411 | WHERE {course_modules}.id = {course_completion_criteria}.moduleinstance) | |
2ea2549e | 412 | AND {course_completion_criteria}.criteriatype = ".COMPLETION_CRITERIA_TYPE_ACTIVITY; |
ede323e2 ARN |
413 | } |
414 | $DB->execute($sql); | |
415 | ||
416 | // Main savepoint reached | |
417 | upgrade_main_savepoint(true, 2012042300.02); | |
418 | } | |
419 | ||
0dda790c | 420 | if ($oldversion < 2012050300.01) { |
fa530687 PS |
421 | // Make sure deleted users do not have picture flag. |
422 | $DB->set_field('user', 'picture', 0, array('deleted'=>1, 'picture'=>1)); | |
0dda790c | 423 | upgrade_main_savepoint(true, 2012050300.01); |
fa530687 PS |
424 | } |
425 | ||
0dda790c | 426 | if ($oldversion < 2012050300.02) { |
4d254790 PS |
427 | |
428 | // Changing precision of field picture on table user to (10) | |
429 | $table = new xmldb_table('user'); | |
430 | $field = new xmldb_field('picture', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'secret'); | |
431 | ||
432 | // Launch change of precision for field picture | |
433 | $dbman->change_field_precision($table, $field); | |
434 | ||
435 | // Main savepoint reached | |
0dda790c | 436 | upgrade_main_savepoint(true, 2012050300.02); |
4d254790 PS |
437 | } |
438 | ||
1156d38d DP |
439 | if ($oldversion < 2012050300.03) { |
440 | ||
441 | // Define field coursedisplay to be added to course | |
442 | $table = new xmldb_table('course'); | |
443 | $field = new xmldb_field('coursedisplay', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'completionnotify'); | |
444 | ||
445 | // Conditionally launch add field coursedisplay | |
446 | if (!$dbman->field_exists($table, $field)) { | |
447 | $dbman->add_field($table, $field); | |
448 | } | |
449 | ||
450 | // Main savepoint reached | |
451 | upgrade_main_savepoint(true, 2012050300.03); | |
452 | } | |
453 | ||
b9bcdb54 DP |
454 | if ($oldversion < 2012050300.04) { |
455 | ||
456 | // Define table course_display to be dropped | |
457 | $table = new xmldb_table('course_display'); | |
458 | ||
459 | // Conditionally launch drop table for course_display | |
460 | if ($dbman->table_exists($table)) { | |
461 | $dbman->drop_table($table); | |
462 | } | |
463 | ||
464 | // Main savepoint reached | |
465 | upgrade_main_savepoint(true, 2012050300.04); | |
466 | } | |
467 | ||
468 | if ($oldversion < 2012050300.05) { | |
469 | ||
470 | // Clean up removed admin setting. | |
471 | unset_config('navlinkcoursesections'); | |
472 | ||
473 | upgrade_main_savepoint(true, 2012050300.05); | |
474 | } | |
475 | ||
c119a2ee PS |
476 | if ($oldversion < 2012050400.01) { |
477 | ||
478 | // Define index sortorder (not unique) to be added to course | |
479 | $table = new xmldb_table('course'); | |
480 | $index = new xmldb_index('sortorder', XMLDB_INDEX_NOTUNIQUE, array('sortorder')); | |
481 | ||
482 | // Conditionally launch add index sortorder | |
483 | if (!$dbman->index_exists($table, $index)) { | |
484 | $dbman->add_index($table, $index); | |
485 | } | |
486 | ||
487 | // Main savepoint reached | |
488 | upgrade_main_savepoint(true, 2012050400.01); | |
489 | } | |
490 | ||
bbb0a6eb SH |
491 | if ($oldversion < 2012050400.02) { |
492 | ||
9fa74379 DP |
493 | // Clean up removed admin setting. |
494 | unset_config('enablecourseajax'); | |
495 | ||
bbb0a6eb | 496 | upgrade_main_savepoint(true, 2012050400.02); |
9fa74379 DP |
497 | } |
498 | ||
74b714df ARN |
499 | if ($oldversion < 2012051100.01) { |
500 | ||
501 | // Define field idnumber to be added to groups | |
502 | $table = new xmldb_table('groups'); | |
503 | $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'courseid'); | |
504 | $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber')); | |
505 | ||
506 | // Conditionally launch add field idnumber | |
507 | if (!$dbman->field_exists($table, $field)) { | |
508 | $dbman->add_field($table, $field); | |
509 | } | |
510 | ||
511 | // Conditionally launch add index idnumber | |
512 | if (!$dbman->index_exists($table, $index)) { | |
513 | $dbman->add_index($table, $index); | |
514 | } | |
515 | ||
516 | // Define field idnumber to be added to groupings | |
517 | $table = new xmldb_table('groupings'); | |
518 | $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'name'); | |
519 | $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber')); | |
520 | ||
521 | // Conditionally launch add field idnumber | |
522 | if (!$dbman->field_exists($table, $field)) { | |
523 | $dbman->add_field($table, $field); | |
524 | } | |
525 | ||
526 | // Conditionally launch add index idnumber | |
527 | if (!$dbman->index_exists($table, $index)) { | |
528 | $dbman->add_index($table, $index); | |
529 | } | |
530 | ||
531 | // Main savepoint reached | |
532 | upgrade_main_savepoint(true, 2012051100.01); | |
533 | } | |
534 | ||
dd420aba EL |
535 | if ($oldversion < 2012051100.03) { |
536 | ||
ce4dfd27 | 537 | // Amend course table to add sectioncache cache |
538 | $table = new xmldb_table('course'); | |
539 | $field = new xmldb_field('sectioncache', XMLDB_TYPE_TEXT, null, null, null, null, null, 'showgrades'); | |
540 | if (!$dbman->field_exists($table, $field)) { | |
541 | $dbman->add_field($table, $field); | |
542 | } | |
543 | ||
544 | // Amend course_sections to add date, time and groupingid availability | |
545 | // conditions and a setting about whether to show them | |
546 | $table = new xmldb_table('course_sections'); | |
dd420aba | 547 | $field = new xmldb_field('availablefrom', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'visible'); |
ce4dfd27 | 548 | if (!$dbman->field_exists($table, $field)) { |
549 | $dbman->add_field($table, $field); | |
550 | } | |
dd420aba | 551 | $field = new xmldb_field('availableuntil', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'availablefrom'); |
ce4dfd27 | 552 | if (!$dbman->field_exists($table, $field)) { |
553 | $dbman->add_field($table, $field); | |
554 | } | |
dd420aba | 555 | $field = new xmldb_field('showavailability', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'availableuntil'); |
ce4dfd27 | 556 | // Conditionally launch add field showavailability |
557 | if (!$dbman->field_exists($table, $field)) { | |
558 | $dbman->add_field($table, $field); | |
559 | } | |
dd420aba | 560 | $field = new xmldb_field('groupingid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'showavailability'); |
ce4dfd27 | 561 | // Conditionally launch add field groupingid |
562 | if (!$dbman->field_exists($table, $field)) { | |
563 | $dbman->add_field($table, $field); | |
564 | } | |
565 | ||
566 | // Add course_sections_availability to add completion & grade availability conditions | |
567 | $table = new xmldb_table('course_sections_availability'); | |
568 | ||
569 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
570 | $table->add_field('coursesectionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); | |
571 | $table->add_field('sourcecmid', XMLDB_TYPE_INTEGER, '10', null, null, null, null); | |
572 | $table->add_field('requiredcompletion', XMLDB_TYPE_INTEGER, '1', null, null, null, null); | |
573 | $table->add_field('gradeitemid', XMLDB_TYPE_INTEGER, '10', null, null, null, null); | |
574 | $table->add_field('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null); | |
575 | $table->add_field('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null); | |
576 | ||
577 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
dd420aba EL |
578 | $table->add_key('coursesectionid', XMLDB_KEY_FOREIGN, array('coursesectionid'), 'course_sections', array('id')); |
579 | $table->add_key('sourcecmid', XMLDB_KEY_FOREIGN, array('sourcecmid'), 'course_modules', array('id')); | |
580 | $table->add_key('gradeitemid', XMLDB_KEY_FOREIGN, array('gradeitemid'), 'grade_items', array('id')); | |
ce4dfd27 | 581 | |
582 | if (!$dbman->table_exists($table)) { | |
583 | $dbman->create_table($table); | |
584 | } | |
585 | ||
94dc3c7d | 586 | // Main savepoint reached |
dd420aba | 587 | upgrade_main_savepoint(true, 2012051100.03); |
ce4dfd27 | 588 | } |
589 | ||
67233725 DC |
590 | if ($oldversion < 2012052100.00) { |
591 | ||
7051415c | 592 | // Define field referencefileid to be added to files. |
67233725 DC |
593 | $table = new xmldb_table('files'); |
594 | ||
7051415c | 595 | // Define field referencefileid to be added to files. |
67233725 | 596 | $field = new xmldb_field('referencefileid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'sortorder'); |
7051415c DC |
597 | |
598 | // Conditionally launch add field referencefileid. | |
67233725 DC |
599 | if (!$dbman->field_exists($table, $field)) { |
600 | $dbman->add_field($table, $field); | |
601 | } | |
602 | ||
7051415c | 603 | // Define field referencelastsync to be added to files. |
67233725 | 604 | $field = new xmldb_field('referencelastsync', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'referencefileid'); |
7051415c DC |
605 | |
606 | // Conditionally launch add field referencelastsync. | |
67233725 DC |
607 | if (!$dbman->field_exists($table, $field)) { |
608 | $dbman->add_field($table, $field); | |
609 | } | |
610 | ||
7051415c DC |
611 | // Define field referencelifetime to be added to files. |
612 | $field = new xmldb_field('referencelifetime', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'referencelastsync'); | |
613 | ||
614 | // Conditionally launch add field referencelifetime. | |
67233725 DC |
615 | if (!$dbman->field_exists($table, $field)) { |
616 | $dbman->add_field($table, $field); | |
617 | } | |
618 | ||
619 | $key = new xmldb_key('referencefileid', XMLDB_KEY_FOREIGN, array('referencefileid'), 'files_reference', array('id')); | |
620 | // Launch add key referencefileid | |
621 | $dbman->add_key($table, $key); | |
622 | ||
623 | // Define table files_reference to be created. | |
624 | $table = new xmldb_table('files_reference'); | |
625 | ||
626 | // Adding fields to table files_reference. | |
627 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
67233725 DC |
628 | $table->add_field('repositoryid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); |
629 | $table->add_field('lastsync', XMLDB_TYPE_INTEGER, '10', null, null, null, null); | |
630 | $table->add_field('lifetime', XMLDB_TYPE_INTEGER, '10', null, null, null, null); | |
631 | $table->add_field('reference', XMLDB_TYPE_TEXT, null, null, null, null, null); | |
632 | ||
633 | // Adding keys to table files_reference. | |
634 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
635 | $table->add_key('repositoryid', XMLDB_KEY_FOREIGN, array('repositoryid'), 'repository_instances', array('id')); | |
636 | ||
637 | // Conditionally launch create table for files_reference | |
638 | if (!$dbman->table_exists($table)) { | |
639 | $dbman->create_table($table); | |
640 | } | |
641 | ||
642 | // Main savepoint reached | |
643 | upgrade_main_savepoint(true, 2012052100.00); | |
644 | } | |
645 | ||
3f1bca9d | 646 | if ($oldversion < 2012052500.03) { // fix invalid course_completion_records MDL-27368 |
d2e3a1b4 DM |
647 | //first get all instances of duplicate records |
648 | $sql = 'SELECT userid, course FROM {course_completions} WHERE (deleted IS NULL OR deleted <> 1) GROUP BY userid, course HAVING (count(id) > 1)'; | |
649 | $duplicates = $DB->get_recordset_sql($sql, array()); | |
650 | ||
651 | foreach ($duplicates as $duplicate) { | |
652 | $pointer = 0; | |
653 | //now get all the records for this user/course | |
654 | $sql = 'userid = ? AND course = ? AND (deleted IS NULL OR deleted <> 1)'; | |
655 | $completions = $DB->get_records_select('course_completions', $sql, | |
656 | array($duplicate->userid, $duplicate->course), 'timecompleted DESC, timestarted DESC'); | |
657 | $needsupdate = false; | |
658 | $origcompletion = null; | |
659 | foreach ($completions as $completion) { | |
660 | $pointer++; | |
661 | if ($pointer === 1) { //keep 1st record but delete all others. | |
662 | $origcompletion = $completion; | |
663 | } else { | |
664 | //we need to keep the "oldest" of all these fields as the valid completion record. | |
665 | $fieldstocheck = array('timecompleted', 'timestarted', 'timeenrolled'); | |
666 | foreach ($fieldstocheck as $f) { | |
667 | if ($origcompletion->$f > $completion->$f) { | |
668 | $origcompletion->$f = $completion->$f; | |
669 | $needsupdate = true; | |
670 | } | |
671 | } | |
672 | $DB->delete_records('course_completions', array('id'=>$completion->id)); | |
673 | } | |
674 | } | |
675 | if ($needsupdate) { | |
676 | $DB->update_record('course_completions', $origcompletion); | |
677 | } | |
678 | } | |
679 | ||
680 | // Main savepoint reached | |
3f1bca9d | 681 | upgrade_main_savepoint(true, 2012052500.03); |
d2e3a1b4 | 682 | } |
424a19b1 | 683 | |
bd633dda | 684 | if ($oldversion < 2012052900.00) { |
e6f55285 SH |
685 | // Clean up all duplicate records in the course_completions table in preparation |
686 | // for adding a new index there. | |
424a19b1 AB |
687 | upgrade_course_completion_remove_duplicates( |
688 | 'course_completions', | |
689 | array('userid', 'course'), | |
690 | array('timecompleted', 'timestarted', 'timeenrolled') | |
691 | ); | |
692 | ||
e6f55285 SH |
693 | // Main savepoint reached |
694 | upgrade_main_savepoint(true, 2012052900.00); | |
695 | } | |
696 | ||
697 | if ($oldversion < 2012052900.01) { | |
698 | // Add indexes to prevent new duplicates in the course_completions table. | |
424a19b1 AB |
699 | // Define index useridcourse (unique) to be added to course_completions |
700 | $table = new xmldb_table('course_completions'); | |
701 | $index = new xmldb_index('useridcourse', XMLDB_INDEX_UNIQUE, array('userid', 'course')); | |
702 | ||
424a19b1 AB |
703 | // Conditionally launch add index useridcourse |
704 | if (!$dbman->index_exists($table, $index)) { | |
705 | $dbman->add_index($table, $index); | |
706 | } | |
707 | ||
708 | // Main savepoint reached | |
e6f55285 | 709 | upgrade_main_savepoint(true, 2012052900.01); |
424a19b1 AB |
710 | } |
711 | ||
e6f55285 SH |
712 | if ($oldversion < 2012052900.02) { |
713 | // Clean up all duplicate records in the course_completion_crit_compl table in preparation | |
714 | // for adding a new index there. | |
424a19b1 AB |
715 | upgrade_course_completion_remove_duplicates( |
716 | 'course_completion_crit_compl', | |
717 | array('userid', 'course', 'criteriaid'), | |
718 | array('timecompleted') | |
719 | ); | |
720 | ||
e6f55285 SH |
721 | // Main savepoint reached |
722 | upgrade_main_savepoint(true, 2012052900.02); | |
723 | } | |
424a19b1 | 724 | |
e6f55285 SH |
725 | if ($oldversion < 2012052900.03) { |
726 | // Add indexes to prevent new duplicates in the course_completion_crit_compl table. | |
424a19b1 AB |
727 | // Define index useridcoursecriteraid (unique) to be added to course_completion_crit_compl |
728 | $table = new xmldb_table('course_completion_crit_compl'); | |
729 | $index = new xmldb_index('useridcoursecriteraid', XMLDB_INDEX_UNIQUE, array('userid', 'course', 'criteriaid')); | |
730 | ||
731 | // Conditionally launch add index useridcoursecriteraid | |
732 | if (!$dbman->index_exists($table, $index)) { | |
733 | $dbman->add_index($table, $index); | |
734 | } | |
735 | ||
736 | // Main savepoint reached | |
e6f55285 | 737 | upgrade_main_savepoint(true, 2012052900.03); |
424a19b1 AB |
738 | } |
739 | ||
e6f55285 SH |
740 | if ($oldversion < 2012052900.04) { |
741 | // Clean up all duplicate records in the course_completion_aggr_methd table in preparation | |
742 | // for adding a new index there. | |
424a19b1 AB |
743 | upgrade_course_completion_remove_duplicates( |
744 | 'course_completion_aggr_methd', | |
745 | array('course', 'criteriatype') | |
746 | ); | |
747 | ||
e6f55285 SH |
748 | // Main savepoint reached |
749 | upgrade_main_savepoint(true, 2012052900.04); | |
750 | } | |
751 | ||
752 | if ($oldversion < 2012052900.05) { | |
753 | // Add indexes to prevent new duplicates in the course_completion_aggr_methd table. | |
424a19b1 AB |
754 | // Define index coursecriteratype (unique) to be added to course_completion_aggr_methd |
755 | $table = new xmldb_table('course_completion_aggr_methd'); | |
756 | $index = new xmldb_index('coursecriteriatype', XMLDB_INDEX_UNIQUE, array('course', 'criteriatype')); | |
757 | ||
758 | // Conditionally launch add index coursecriteratype | |
759 | if (!$dbman->index_exists($table, $index)) { | |
760 | $dbman->add_index($table, $index); | |
761 | } | |
762 | ||
763 | // Main savepoint reached | |
e6f55285 | 764 | upgrade_main_savepoint(true, 2012052900.05); |
424a19b1 AB |
765 | } |
766 | ||
79c2b509 | 767 | if ($oldversion < 2012060600.01) { |
51003653 DM |
768 | // Add field referencehash to files_reference |
769 | $table = new xmldb_table('files_reference'); | |
770 | $field = new xmldb_field('referencehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'reference'); | |
771 | if (!$dbman->field_exists($table, $field)) { | |
772 | $dbman->add_field($table, $field); | |
773 | } | |
79c2b509 | 774 | upgrade_main_savepoint(true, 2012060600.01); |
51003653 DM |
775 | } |
776 | ||
79c2b509 | 777 | if ($oldversion < 2012060600.02) { |
dccba8bc DM |
778 | // Populate referencehash field with SHA1 hash of the reference - this shoudl affect only 2.3dev sites |
779 | // that were using the feature for testing. Production sites have the table empty. | |
780 | $rs = $DB->get_recordset('files_reference', null, '', 'id, reference'); | |
781 | foreach ($rs as $record) { | |
782 | $hash = sha1($record->reference); | |
783 | $DB->set_field('files_reference', 'referencehash', $hash, array('id' => $record->id)); | |
784 | } | |
785 | $rs->close(); | |
786 | ||
79c2b509 | 787 | upgrade_main_savepoint(true, 2012060600.02); |
dccba8bc DM |
788 | } |
789 | ||
79c2b509 | 790 | if ($oldversion < 2012060600.03) { |
8f47a60e DM |
791 | // Merge duplicate records in files_reference that were created during the development |
792 | // phase at 2.3dev sites. This is needed so we can create the unique index over | |
793 | // (repositoryid, referencehash) fields. | |
794 | $sql = "SELECT repositoryid, referencehash, MIN(id) AS minid | |
795 | FROM {files_reference} | |
796 | GROUP BY repositoryid, referencehash | |
4a5be0e9 | 797 | HAVING COUNT(*) > 1"; |
8f47a60e DM |
798 | $duprs = $DB->get_recordset_sql($sql); |
799 | foreach ($duprs as $duprec) { | |
800 | // get the list of all ids in {files_reference} that need to be remapped | |
801 | $dupids = $DB->get_records_select('files_reference', "repositoryid = ? AND referencehash = ? AND id > ?", | |
802 | array($duprec->repositoryid, $duprec->referencehash, $duprec->minid), '', 'id'); | |
803 | $dupids = array_keys($dupids); | |
804 | // relink records in {files} that are now referring to a duplicate record | |
805 | // in {files_reference} to refer to the first one | |
806 | list($subsql, $subparams) = $DB->get_in_or_equal($dupids); | |
807 | $DB->set_field_select('files', 'referencefileid', $duprec->minid, "referencefileid $subsql", $subparams); | |
808 | // and finally remove all orphaned records from {files_reference} | |
809 | $DB->delete_records_list('files_reference', 'id', $dupids); | |
810 | } | |
811 | $duprs->close(); | |
812 | ||
79c2b509 | 813 | upgrade_main_savepoint(true, 2012060600.03); |
8f47a60e DM |
814 | } |
815 | ||
79c2b509 | 816 | if ($oldversion < 2012060600.04) { |
6bbf31c3 DM |
817 | // Add a unique index over repositoryid and referencehash fields in files_reference table |
818 | $table = new xmldb_table('files_reference'); | |
819 | $index = new xmldb_index('uq_external_file', XMLDB_INDEX_UNIQUE, array('repositoryid', 'referencehash')); | |
820 | ||
821 | if (!$dbman->index_exists($table, $index)) { | |
822 | $dbman->add_index($table, $index); | |
823 | } | |
824 | ||
79c2b509 | 825 | upgrade_main_savepoint(true, 2012060600.04); |
6bbf31c3 DM |
826 | } |
827 | ||
a80b5a0c DP |
828 | if ($oldversion < 2012061800.01) { |
829 | ||
830 | // Define field screenreader to be dropped from user | |
831 | $table = new xmldb_table('user'); | |
832 | $field = new xmldb_field('ajax'); | |
833 | ||
834 | // Conditionally launch drop field screenreader | |
835 | if ($dbman->field_exists($table, $field)) { | |
836 | $dbman->drop_field($table, $field); | |
837 | } | |
838 | ||
839 | // Main savepoint reached | |
840 | upgrade_main_savepoint(true, 2012061800.01); | |
841 | } | |
842 | ||
088c374a | 843 | if ($oldversion < 2012062000.00) { |
38ca2f1a DM |
844 | // Add field newcontextid to backup_files_template |
845 | $table = new xmldb_table('backup_files_template'); | |
846 | $field = new xmldb_field('newcontextid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'info'); | |
847 | ||
848 | if (!$dbman->field_exists($table, $field)) { | |
849 | $dbman->add_field($table, $field); | |
850 | } | |
851 | ||
088c374a | 852 | upgrade_main_savepoint(true, 2012062000.00); |
38ca2f1a DM |
853 | } |
854 | ||
088c374a | 855 | if ($oldversion < 2012062000.01) { |
38ca2f1a DM |
856 | // Add field newitemid to backup_files_template |
857 | $table = new xmldb_table('backup_files_template'); | |
858 | $field = new xmldb_field('newitemid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'newcontextid'); | |
859 | ||
860 | if (!$dbman->field_exists($table, $field)) { | |
861 | $dbman->add_field($table, $field); | |
862 | } | |
863 | ||
088c374a | 864 | upgrade_main_savepoint(true, 2012062000.01); |
38ca2f1a DM |
865 | } |
866 | ||
44cb29a0 EL |
867 | |
868 | // Moodle v2.3.0 release upgrade line | |
869 | // Put any upgrade step following this | |
870 | ||
871 | ||
872 | if ($oldversion < 2012062500.02) { | |
3f4a2999 PÅ |
873 | // Drop some old backup tables, not used anymore |
874 | ||
875 | // Define table backup_files to be dropped | |
876 | $table = new xmldb_table('backup_files'); | |
877 | ||
878 | // Conditionally launch drop table for backup_files | |
879 | if ($dbman->table_exists($table)) { | |
880 | $dbman->drop_table($table); | |
881 | } | |
882 | ||
883 | // Define table backup_ids to be dropped | |
884 | $table = new xmldb_table('backup_ids'); | |
885 | ||
886 | // Conditionally launch drop table for backup_ids | |
66dd3e5d SH |
887 | if ($dbman->table_exists($table)) { |
888 | $dbman->drop_table($table); | |
3f4a2999 PÅ |
889 | } |
890 | ||
891 | // Main savepoint reached | |
44cb29a0 | 892 | upgrade_main_savepoint(true, 2012062500.02); |
3f4a2999 PÅ |
893 | } |
894 | ||
00142ce5 | 895 | if ($oldversion < 2012070600.04) { |
141d3c86 SH |
896 | // Define table course_modules_avail_fields to be created |
897 | $table = new xmldb_table('course_modules_avail_fields'); | |
898 | ||
899 | // Adding fields to table course_modules_avail_fields | |
900 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
901 | $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); | |
902 | $table->add_field('userfield', XMLDB_TYPE_CHAR, '50', null, null, null, null); | |
903 | $table->add_field('customfieldid', XMLDB_TYPE_INTEGER, '10', null, null, null, null); | |
904 | $table->add_field('operator', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null); | |
905 | $table->add_field('value', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
906 | ||
907 | // Adding keys to table course_modules_avail_fields | |
908 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
909 | $table->add_key('coursemoduleid', XMLDB_KEY_FOREIGN, array('coursemoduleid'), 'course_modules', array('id')); | |
910 | ||
911 | // Conditionally launch create table for course_modules_avail_fields | |
912 | if (!$dbman->table_exists($table)) { | |
913 | $dbman->create_table($table); | |
914 | } | |
915 | ||
916 | // Main savepoint reached | |
00142ce5 | 917 | upgrade_main_savepoint(true, 2012070600.04); |
141d3c86 SH |
918 | } |
919 | ||
00142ce5 | 920 | if ($oldversion < 2012070600.05) { |
141d3c86 SH |
921 | // Define table course_sections_avail_fields to be created |
922 | $table = new xmldb_table('course_sections_avail_fields'); | |
923 | ||
924 | // Adding fields to table course_sections_avail_fields | |
925 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
926 | $table->add_field('coursesectionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); | |
927 | $table->add_field('userfield', XMLDB_TYPE_CHAR, '50', null, null, null, null); | |
928 | $table->add_field('customfieldid', XMLDB_TYPE_INTEGER, '10', null, null, null, null); | |
929 | $table->add_field('operator', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null); | |
930 | $table->add_field('value', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
931 | ||
932 | // Adding keys to table course_sections_avail_fields | |
933 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
934 | $table->add_key('coursesectionid', XMLDB_KEY_FOREIGN, array('coursesectionid'), 'course_sections', array('id')); | |
935 | ||
936 | // Conditionally launch create table for course_sections_avail_fields | |
937 | if (!$dbman->table_exists($table)) { | |
938 | $dbman->create_table($table); | |
939 | } | |
940 | ||
941 | // Main savepoint reached | |
00142ce5 | 942 | upgrade_main_savepoint(true, 2012070600.05); |
141d3c86 | 943 | } |
a80b5a0c | 944 | |
00142ce5 | 945 | if ($oldversion < 2012070600.06) { |
a2a2e7fb SH |
946 | |
947 | // Drop "deleted" fields | |
46eca1f7 AB |
948 | $table = new xmldb_table('course_completions'); |
949 | $field = new xmldb_field('timenotified'); | |
a2a2e7fb SH |
950 | $field = new xmldb_field('deleted'); |
951 | ||
952 | // Conditionally launch drop field deleted from course_completions | |
953 | if ($dbman->field_exists($table, $field)) { | |
66dd3e5d | 954 | $dbman->drop_field($table, $field); |
a2a2e7fb | 955 | } |
46eca1f7 | 956 | |
a2a2e7fb | 957 | $field = new xmldb_field('timenotified'); |
46eca1f7 AB |
958 | // Conditionally launch drop field timenotified from course_completions |
959 | if ($dbman->field_exists($table, $field)) { | |
960 | $dbman->drop_field($table, $field); | |
961 | } | |
962 | ||
963 | // Main savepoint reached | |
00142ce5 | 964 | upgrade_main_savepoint(true, 2012070600.06); |
46eca1f7 AB |
965 | } |
966 | ||
00142ce5 | 967 | if ($oldversion < 2012070600.07) { |
a2a2e7fb SH |
968 | $table = new xmldb_table('course_completion_crit_compl'); |
969 | $field = new xmldb_field('deleted'); | |
970 | ||
971 | // Conditionally launch drop field deleted from course_completion_crit_compl | |
972 | if ($dbman->field_exists($table, $field)) { | |
973 | $dbman->drop_field($table, $field); | |
974 | } | |
975 | // Main savepoint reached | |
00142ce5 | 976 | upgrade_main_savepoint(true, 2012070600.07); |
a2a2e7fb SH |
977 | } |
978 | ||
00142ce5 | 979 | if ($oldversion < 2012070600.08) { |
a2a2e7fb SH |
980 | |
981 | // Drop unused table "course_completion_notify" | |
982 | $table = new xmldb_table('course_completion_notify'); | |
983 | ||
984 | // Conditionally launch drop table course_completion_notify | |
985 | if ($dbman->table_exists($table)) { | |
986 | $dbman->drop_table($table); | |
987 | } | |
988 | ||
989 | // Main savepoint reached | |
00142ce5 | 990 | upgrade_main_savepoint(true, 2012070600.08); |
a2a2e7fb SH |
991 | } |
992 | ||
00142ce5 | 993 | if ($oldversion < 2012070600.09) { |
bd991d03 PS |
994 | |
995 | // Define index path (not unique) to be added to context | |
996 | $table = new xmldb_table('context'); | |
997 | $index = new xmldb_index('path', XMLDB_INDEX_NOTUNIQUE, array('path'), array('varchar_pattern_ops')); | |
998 | ||
999 | // Recreate index with new pattern hint | |
1000 | if ($DB->get_dbfamily() === 'postgres') { | |
1001 | if ($dbman->index_exists($table, $index)) { | |
1002 | $dbman->drop_index($table, $index); | |
1003 | } | |
1004 | $dbman->add_index($table, $index); | |
1005 | } | |
1006 | ||
1007 | // Main savepoint reached | |
00142ce5 | 1008 | upgrade_main_savepoint(true, 2012070600.09); |
bd991d03 PS |
1009 | } |
1010 | ||
00142ce5 | 1011 | if ($oldversion < 2012070600.10) { |
c52551dc PS |
1012 | |
1013 | // Define index name (unique) to be dropped form role | |
1014 | $table = new xmldb_table('role'); | |
1015 | $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name')); | |
1016 | ||
1017 | // Conditionally launch drop index name | |
1018 | if ($dbman->index_exists($table, $index)) { | |
1019 | $dbman->drop_index($table, $index); | |
1020 | } | |
1021 | ||
1022 | // Main savepoint reached | |
00142ce5 | 1023 | upgrade_main_savepoint(true, 2012070600.10); |
c52551dc PS |
1024 | } |
1025 | ||
f0d6e53c | 1026 | if ($oldversion < 2012070600.11) { |
79a47143 PÅ |
1027 | |
1028 | // Define index component-itemid-userid (not unique) to be added to role_assignments | |
1029 | $table = new xmldb_table('role_assignments'); | |
1030 | $index = new xmldb_index('component-itemid-userid', XMLDB_INDEX_NOTUNIQUE, array('component', 'itemid', 'userid')); | |
1031 | ||
1032 | // Conditionally launch add index component-itemid-userid | |
1033 | if (!$dbman->index_exists($table, $index)) { | |
1034 | $dbman->add_index($table, $index); | |
1035 | } | |
1036 | ||
1037 | // Main savepoint reached | |
f0d6e53c | 1038 | upgrade_main_savepoint(true, 2012070600.11); |
79a47143 PÅ |
1039 | } |
1040 | ||
c8b3346c PS |
1041 | if ($oldversion < 2012071900.01) { |
1042 | // Cleanup after simpeltests tool | |
1043 | capabilities_cleanup('tool_unittest'); | |
1044 | unset_all_config_for_plugin('tool_unittest'); | |
1045 | ||
1046 | upgrade_main_savepoint(true, 2012071900.01); | |
1047 | } | |
1048 | ||
b7db7803 | 1049 | if ($oldversion < 2012072400.00) { |
13725b37 PS |
1050 | // Remove obsolete xhtml strict setting - use THEME->doctype in theme config if necessary, |
1051 | // see theme_config->doctype in lib/outputlib.php for more details. | |
1052 | unset_config('xmlstrictheaders'); | |
b7db7803 | 1053 | upgrade_main_savepoint(true, 2012072400.00); |
13725b37 | 1054 | } |
a80b5a0c | 1055 | |
61e93a4c | 1056 | if ($oldversion < 2012072401.00) { |
67e3dd2c FM |
1057 | |
1058 | // Saves orphaned questions from the Dark Side | |
1059 | upgrade_save_orphaned_questions(); | |
1060 | ||
1061 | // Main savepoint reached | |
61e93a4c | 1062 | upgrade_main_savepoint(true, 2012072401.00); |
67e3dd2c | 1063 | } |
a80b5a0c | 1064 | |
3713514b | 1065 | if ($oldversion < 2012072600.01) { |
f14f9842 AA |
1066 | // Handle events with empty eventtype //MDL-32827 |
1067 | ||
1068 | $DB->set_field('event', 'eventtype', 'site', array('eventtype' => '', 'courseid' => $SITE->id)); | |
1069 | $DB->set_field_select('event', 'eventtype', 'due', "eventtype = '' AND courseid != 0 AND groupid = 0 AND (modulename = 'assignment' OR modulename = 'assign')"); | |
1070 | $DB->set_field_select('event', 'eventtype', 'course', "eventtype = '' AND courseid != 0 AND groupid = 0"); | |
1071 | $DB->set_field_select('event', 'eventtype', 'group', "eventtype = '' AND groupid != 0"); | |
1072 | $DB->set_field_select('event', 'eventtype', 'user', "eventtype = '' AND userid != 0"); | |
1073 | ||
3713514b AA |
1074 | // Main savepoint reached |
1075 | upgrade_main_savepoint(true, 2012072600.01); | |
1076 | } | |
237f05cf PS |
1077 | |
1078 | if ($oldversion < 2012080200.02) { | |
1079 | // Drop obsolete question upgrade field that should have been added to the install.xml. | |
1080 | $table = new xmldb_table('question'); | |
1081 | $field = new xmldb_field('oldquestiontextformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0'); | |
1082 | ||
1083 | if ($dbman->field_exists($table, $field)) { | |
1084 | $dbman->drop_field($table, $field); | |
1085 | } | |
1086 | ||
1087 | upgrade_main_savepoint(true, 2012080200.02); | |
1088 | } | |
237f05cf | 1089 | |
76b97631 | 1090 | if ($oldversion < 2012081400.01) { |
850d2db8 DP |
1091 | // Move the ability to disable blogs to its own setting MDL-25012. |
1092 | ||
1093 | if (isset($CFG->bloglevel)) { | |
1094 | // Only change settings if existing setting was set. | |
1095 | if (empty($CFG->bloglevel)) { | |
1096 | set_config('enableblogs', 0); | |
1097 | // Now set the bloglevel to a valid setting as the disabled setting has been removed. | |
1098 | // This prevents confusing results when users enable the blog system in future. | |
1099 | set_config('bloglevel', BLOG_USER_LEVEL); | |
1100 | } else { | |
1101 | set_config('enableblogs', 1); | |
1102 | } | |
1103 | } | |
1104 | ||
1105 | // Main savepoint reached | |
76b97631 | 1106 | upgrade_main_savepoint(true, 2012081400.01); |
850d2db8 DP |
1107 | } |
1108 | ||
704533fc PS |
1109 | if ($oldversion < 2012081600.01) { |
1110 | // Delete removed setting - Google Maps API V2 will not work in 2013. | |
1111 | unset_config('googlemapkey'); | |
1112 | upgrade_main_savepoint(true, 2012081600.01); | |
1113 | } | |
1114 | ||
882fb835 PS |
1115 | if ($oldversion < 2012082300.01) { |
1116 | // Add more custom enrol fields. | |
1117 | $table = new xmldb_table('enrol'); | |
882fb835 | 1118 | $field = new xmldb_field('customint5', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'customint4'); |
59b9a140 | 1119 | |
882fb835 PS |
1120 | if (!$dbman->field_exists($table, $field)) { |
1121 | $dbman->add_field($table, $field); | |
1122 | } | |
1123 | ||
1124 | $field = new xmldb_field('customint6', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'customint5'); | |
1125 | if (!$dbman->field_exists($table, $field)) { | |
1126 | $dbman->add_field($table, $field); | |
1127 | } | |
1128 | ||
1129 | $field = new xmldb_field('customint7', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'customint6'); | |
1130 | if (!$dbman->field_exists($table, $field)) { | |
1131 | $dbman->add_field($table, $field); | |
1132 | } | |
1133 | ||
1134 | $field = new xmldb_field('customint8', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'customint7'); | |
1135 | if (!$dbman->field_exists($table, $field)) { | |
1136 | $dbman->add_field($table, $field); | |
1137 | } | |
1138 | ||
1139 | $field = new xmldb_field('customchar3', XMLDB_TYPE_CHAR, '1333', null, null, null, null, 'customchar2'); | |
1140 | if (!$dbman->field_exists($table, $field)) { | |
1141 | $dbman->add_field($table, $field); | |
1142 | } | |
1143 | ||
1144 | $field = new xmldb_field('customtext3', XMLDB_TYPE_TEXT, null, null, null, null, null, 'customtext2'); | |
1145 | if (!$dbman->field_exists($table, $field)) { | |
1146 | $dbman->add_field($table, $field); | |
1147 | } | |
1148 | ||
1149 | $field = new xmldb_field('customtext4', XMLDB_TYPE_TEXT, null, null, null, null, null, 'customtext3'); | |
1150 | if (!$dbman->field_exists($table, $field)) { | |
1151 | $dbman->add_field($table, $field); | |
1152 | } | |
1153 | ||
1154 | // Main savepoint reached. | |
1155 | upgrade_main_savepoint(true, 2012082300.01); | |
1156 | } | |
1157 | ||
238f7761 | 1158 | if ($oldversion < 2012082300.02) { |
1d1917ae | 1159 | // Define field component to be added to groups_members |
1160 | $table = new xmldb_table('groups_members'); | |
1161 | $field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'timeadded'); | |
1162 | ||
1163 | // Conditionally launch add field component | |
1164 | if (!$dbman->field_exists($table, $field)) { | |
1165 | $dbman->add_field($table, $field); | |
1166 | } | |
1167 | ||
1168 | // Define field itemid to be added to groups_members | |
1169 | $field = new xmldb_field('itemid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'component'); | |
1170 | ||
1171 | // Conditionally launch add field itemid | |
1172 | if (!$dbman->field_exists($table, $field)) { | |
1173 | $dbman->add_field($table, $field); | |
1174 | } | |
1175 | ||
1176 | // Main savepoint reached | |
238f7761 | 1177 | upgrade_main_savepoint(true, 2012082300.02); |
1d1917ae | 1178 | } |
704533fc | 1179 | |
937b0acb AB |
1180 | if ($oldversion < 2012090500.00) { |
1181 | $subquery = 'SELECT b.id FROM {blog_external} b where b.id = ' . $DB->sql_cast_char2int('{post}.content', true); | |
f3616783 AD |
1182 | $sql = 'DELETE FROM {post} |
1183 | WHERE {post}.module = \'blog_external\' | |
1184 | AND NOT EXISTS (' . $subquery . ') | |
1185 | AND ' . $DB->sql_isnotempty('post', 'uniquehash', false, false); | |
1186 | $DB->execute($sql); | |
937b0acb | 1187 | upgrade_main_savepoint(true, 2012090500.00); |
f3616783 | 1188 | } |
704533fc | 1189 | |
59b9a140 FM |
1190 | if ($oldversion < 2012090700.01) { |
1191 | // Add a category field in the course_request table | |
1192 | $table = new xmldb_table('course_request'); | |
1193 | $field = new xmldb_field('category', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, 0, 'summaryformat'); | |
1194 | if (!$dbman->field_exists($table, $field)) { | |
1195 | $dbman->add_field($table, $field); | |
1196 | } | |
1197 | ||
1198 | // Main savepoint reached. | |
1199 | upgrade_main_savepoint(true, 2012090700.01); | |
1200 | } | |
1201 | ||
d11f12f6 DM |
1202 | if ($oldversion < 2012091700.00) { |
1203 | ||
1204 | // Dropping screenreader field from user. | |
1205 | $table = new xmldb_table('user'); | |
1206 | $field = new xmldb_field('screenreader'); | |
1207 | ||
1208 | if ($dbman->field_exists($table, $field)) { | |
1209 | $dbman->drop_field($table, $field); | |
1210 | } | |
1211 | ||
1212 | // Main savepoint reached. | |
1213 | upgrade_main_savepoint(true, 2012091700.00); | |
1214 | } | |
1215 | ||
52ebfade | 1216 | if ($oldversion < 2012092100.01) { |
0f764c02 FM |
1217 | // Some folders still have a sortorder set, which is used for main files but is not |
1218 | // supported by the folder resource. We reset the value here. | |
1219 | $sql = 'UPDATE {files} SET sortorder = ? WHERE component = ? AND filearea = ? AND sortorder <> ?'; | |
1220 | $DB->execute($sql, array(0, 'mod_folder', 'content', 0)); | |
1221 | ||
1222 | // Main savepoint reached. | |
52ebfade | 1223 | upgrade_main_savepoint(true, 2012092100.01); |
0f764c02 FM |
1224 | } |
1225 | ||
bb14cc2d | 1226 | if ($oldversion < 2012092600.00) { |
7dd764b8 JG |
1227 | // Define index idname (unique) to be added to tag |
1228 | $table = new xmldb_table('tag'); | |
1229 | $index = new xmldb_index('idname', XMLDB_INDEX_UNIQUE, array('id', 'name')); | |
1230 | ||
1231 | // Conditionally launch add index idname | |
1232 | if (!$dbman->index_exists($table, $index)) { | |
1233 | $dbman->add_index($table, $index); | |
1234 | } | |
1235 | ||
1236 | // Main savepoint reached | |
bb14cc2d | 1237 | upgrade_main_savepoint(true, 2012092600.00); |
7dd764b8 JG |
1238 | } |
1239 | ||
cb6b5fb6 | 1240 | if ($oldversion < 2012101500.01) { |
c0a05926 AG |
1241 | // Find all orphaned blog associations that might exist. |
1242 | $sql = "SELECT ba.id | |
1243 | FROM {blog_association} ba | |
1244 | LEFT JOIN {post} p | |
1245 | ON p.id = ba.blogid | |
1246 | WHERE p.id IS NULL"; | |
1247 | $orphanedrecordids = $DB->get_records_sql($sql); | |
1248 | // Now delete these associations. | |
1249 | foreach ($orphanedrecordids as $orphanedrecord) { | |
1250 | $DB->delete_records('blog_association', array('id' => $orphanedrecord->id)); | |
1251 | } | |
1252 | ||
cb6b5fb6 | 1253 | upgrade_main_savepoint(true, 2012101500.01); |
c0a05926 AG |
1254 | } |
1255 | ||
c28717d9 | 1256 | if ($oldversion < 2012101800.02) { |
d8271e39 FM |
1257 | // Renaming backups using previous file naming convention. |
1258 | upgrade_rename_old_backup_files_using_shortname(); | |
1259 | ||
1260 | // Main savepoint reached. | |
c28717d9 | 1261 | upgrade_main_savepoint(true, 2012101800.02); |
d8271e39 FM |
1262 | } |
1263 | ||
0c918a1f | 1264 | if ($oldversion < 2012103001.00) { |
b5a52acd JH |
1265 | // create new event_subscriptions table |
1266 | $table = new xmldb_table('event_subscriptions'); | |
e30390a0 | 1267 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
b5a52acd JH |
1268 | $table->add_field('url', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
1269 | $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); | |
1270 | $table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); | |
1271 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); | |
1272 | $table->add_field('pollinterval', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); | |
1273 | $table->add_field('lastupdated', XMLDB_TYPE_INTEGER, '10', null, null, null, null); | |
e30390a0 | 1274 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
b5a52acd JH |
1275 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
1276 | if (!$dbman->table_exists($table)) { | |
1277 | $dbman->create_table($table); | |
1278 | } | |
1279 | // Main savepoint reached | |
0c918a1f | 1280 | upgrade_main_savepoint(true, 2012103001.00); |
b5a52acd JH |
1281 | } |
1282 | ||
0c918a1f | 1283 | if ($oldversion < 2012103002.00) { |
b5a52acd JH |
1284 | // Add subscription field to the event table |
1285 | $table = new xmldb_table('event'); | |
e30390a0 SH |
1286 | $field = new xmldb_field('subscriptionid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'timemodified'); |
1287 | ||
1288 | // Conditionally launch add field subscriptionid | |
b5a52acd JH |
1289 | if (!$dbman->field_exists($table, $field)) { |
1290 | $dbman->add_field($table, $field); | |
1291 | } | |
d618dcf3 DP |
1292 | upgrade_main_savepoint(true, 2012103002.00); |
1293 | } | |
b5a52acd | 1294 | |
d618dcf3 | 1295 | if ($oldversion < 2012103003.00) { |
b5a52acd | 1296 | // Fix uuid field in event table to match RFC-2445 UID property |
d618dcf3 | 1297 | $table = new xmldb_table('event'); |
e30390a0 | 1298 | $field = new xmldb_field('uuid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'visible'); |
b5a52acd | 1299 | if ($dbman->field_exists($table, $field)) { |
e30390a0 | 1300 | // Changing precision of field uuid on table event to (255) |
b5a52acd JH |
1301 | $dbman->change_field_precision($table, $field); |
1302 | } | |
b5a52acd | 1303 | // Main savepoint reached |
d618dcf3 | 1304 | upgrade_main_savepoint(true, 2012103003.00); |
b5a52acd JH |
1305 | } |
1306 | ||
29ac9fc1 MG |
1307 | if ($oldversion < 2012110200.00) { |
1308 | ||
1309 | // Define table course_format_options to be created | |
1310 | $table = new xmldb_table('course_format_options'); | |
1311 | ||
1312 | // Adding fields to table course_format_options | |
1313 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
1314 | $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); | |
1315 | $table->add_field('format', XMLDB_TYPE_CHAR, '21', null, XMLDB_NOTNULL, null, null); | |
1316 | $table->add_field('sectionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'format'); | |
1317 | $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); | |
1318 | $table->add_field('value', XMLDB_TYPE_TEXT, null, null, null, null, null); | |
1319 | ||
1320 | // Adding keys to table course_format_options | |
1321 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1322 | $table->add_key('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); | |
1323 | ||
1324 | // Adding indexes to table course_format_options | |
1325 | $table->add_index('formatoption', XMLDB_INDEX_UNIQUE, array('courseid', 'format', 'sectionid', 'name')); | |
1326 | ||
1327 | // Conditionally launch create table for course_format_options | |
1328 | if (!$dbman->table_exists($table)) { | |
1329 | $dbman->create_table($table); | |
1330 | } | |
1331 | ||
1332 | // Changing type of field format on table course to char with length 21 | |
1333 | $table = new xmldb_table('course'); | |
1334 | $field = new xmldb_field('format', XMLDB_TYPE_CHAR, '21', null, XMLDB_NOTNULL, null, 'topics', 'summaryformat'); | |
1335 | ||
1336 | // Launch change of type for field format | |
1337 | $dbman->change_field_type($table, $field); | |
1338 | ||
1339 | // Main savepoint reached | |
1340 | upgrade_main_savepoint(true, 2012110200.00); | |
1341 | } | |
1342 | ||
b5cf83f0 MG |
1343 | if ($oldversion < 2012110201.00) { |
1344 | ||
1345 | // Copy fields 'coursedisplay', 'numsections', 'hiddensections' from table {course} | |
1346 | // to table {course_format_options} as the additional format options | |
1347 | $fields = array(); | |
1348 | $table = new xmldb_table('course'); | |
1349 | foreach (array('coursedisplay', 'numsections', 'hiddensections') as $fieldname) { | |
1350 | // first check that fields still exist | |
1351 | $field = new xmldb_field($fieldname); | |
1352 | if ($dbman->field_exists($table, $field)) { | |
1353 | $fields[] = $fieldname; | |
1354 | } | |
1355 | } | |
1356 | ||
1357 | if (!empty($fields)) { | |
1358 | $transaction = $DB->start_delegated_transaction(); | |
1359 | $rs = $DB->get_recordset_sql('SELECT id, format, '. join(',', $fields).' | |
1360 | FROM {course} | |
1361 | WHERE format <> ? AND format <> ?', | |
1362 | array('scorm', 'social')); | |
1363 | // (do not copy fields from scrom and social formats, we already know that they are not used) | |
1364 | foreach ($rs as $rec) { | |
1365 | foreach ($fields as $field) { | |
1366 | try { | |
1367 | $DB->insert_record('course_format_options', | |
1368 | array( | |
1369 | 'courseid' => $rec->id, | |
1370 | 'format' => $rec->format, | |
1371 | 'sectionid' => 0, | |
1372 | 'name' => $field, | |
1373 | 'value' => $rec->$field | |
1374 | )); | |
1375 | } catch (dml_exception $e) { | |
1376 | // index 'courseid,format,sectionid,name' violation | |
1377 | // continue; the entry in course_format_options already exists, use it | |
1378 | } | |
1379 | } | |
1380 | } | |
1381 | $rs->close(); | |
1382 | $transaction->allow_commit(); | |
1383 | ||
1384 | // Drop fields from table course | |
1385 | foreach ($fields as $fieldname) { | |
1386 | $field = new xmldb_field($fieldname); | |
1387 | $dbman->drop_field($table, $field); | |
1388 | } | |
1389 | } | |
1390 | ||
1391 | // Main savepoint reached | |
1392 | upgrade_main_savepoint(true, 2012110201.00); | |
1393 | } | |
1394 | ||
37743241 MN |
1395 | if ($oldversion < 2012110700.01) { |
1396 | ||
1397 | // Define field caller_component to be added to portfolio_log. | |
1398 | $table = new xmldb_table('portfolio_log'); | |
1399 | $field = new xmldb_field('caller_component', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'caller_file'); | |
1400 | ||
1401 | // Conditionally launch add field caller_component. | |
1402 | if (!$dbman->field_exists($table, $field)) { | |
1403 | $dbman->add_field($table, $field); | |
1404 | } | |
1405 | ||
1406 | // Main savepoint reached. | |
1407 | upgrade_main_savepoint(true, 2012110700.01); | |
1408 | } | |
1409 | ||
7d270556 AB |
1410 | if ($oldversion < 2012111200.00) { |
1411 | ||
1412 | // Define table temp_enroled_template to be created | |
1413 | $table = new xmldb_table('temp_enroled_template'); | |
1414 | ||
1415 | // Adding fields to table temp_enroled_template | |
1416 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
1417 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); | |
1418 | $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); | |
1419 | $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); | |
1420 | ||
1421 | // Adding keys to table temp_enroled_template | |
1422 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1423 | ||
1424 | // Adding indexes to table temp_enroled_template | |
1425 | $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); | |
1426 | $table->add_index('courseid', XMLDB_INDEX_NOTUNIQUE, array('courseid')); | |
1427 | $table->add_index('roleid', XMLDB_INDEX_NOTUNIQUE, array('roleid')); | |
1428 | ||
1429 | // Conditionally launch create table for temp_enroled_template | |
1430 | if (!$dbman->table_exists($table)) { | |
1431 | $dbman->create_table($table); | |
1432 | } | |
1433 | ||
1434 | // Define table temp_log_template to be created | |
1435 | $table = new xmldb_table('temp_log_template'); | |
1436 | ||
1437 | // Adding fields to table temp_log_template | |
1438 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
1439 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); | |
1440 | $table->add_field('course', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); | |
1441 | $table->add_field('action', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); | |
1442 | ||
1443 | // Adding keys to table temp_log_template | |
1444 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1445 | ||
1446 | // Adding indexes to table temp_log_template | |
1447 | $table->add_index('action', XMLDB_INDEX_NOTUNIQUE, array('action')); | |
1448 | $table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course')); | |
1449 | $table->add_index('user', XMLDB_INDEX_NOTUNIQUE, array('userid')); | |
1450 | $table->add_index('usercourseaction', XMLDB_INDEX_NOTUNIQUE, array('userid', 'course', 'action')); | |
1451 | ||
1452 | // Conditionally launch create table for temp_log_template | |
1453 | if (!$dbman->table_exists($table)) { | |
1454 | $dbman->create_table($table); | |
1455 | } | |
1456 | ||
1457 | // Main savepoint reached | |
1458 | upgrade_main_savepoint(true, 2012111200.00); | |
1459 | } | |
1460 | ||
9b835f70 FM |
1461 | if ($oldversion < 2012111200.01) { |
1462 | // Force the rebuild of the cache of every courses, some cached information could contain wrong icon references. | |
4202471a | 1463 | $DB->execute('UPDATE {course} set modinfo = ?, sectioncache = ?', array(null, null)); |
9b835f70 FM |
1464 | |
1465 | // Main savepoint reached. | |
1466 | upgrade_main_savepoint(true, 2012111200.01); | |
1467 | } | |
1468 | ||
0b37fe46 PS |
1469 | if ($oldversion < 2012111601.01) { |
1470 | // Clea up after old shared memory caching support. | |
1471 | unset_config('cachetype'); | |
1472 | unset_config('rcache'); | |
1473 | unset_config('rcachettl'); | |
1474 | unset_config('intcachemax'); | |
1475 | unset_config('memcachedhosts'); | |
1476 | unset_config('memcachedpconn'); | |
1477 | ||
1478 | // Main savepoint reached. | |
1479 | upgrade_main_savepoint(true, 2012111601.01); | |
1480 | } | |
1481 | ||
9cae08da AB |
1482 | if ($oldversion < 2012112100.00) { |
1483 | ||
1484 | // Define field eventtype to be added to event_subscriptions. | |
1485 | $table = new xmldb_table('event_subscriptions'); | |
1486 | $field = new xmldb_field('eventtype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'userid'); | |
1487 | ||
1488 | // Conditionally launch add field eventtype. | |
1489 | if (!$dbman->field_exists($table, $field)) { | |
1490 | $dbman->add_field($table, $field); | |
1491 | } | |
1492 | ||
1493 | // Main savepoint reached. | |
1494 | upgrade_main_savepoint(true, 2012112100.00); | |
1495 | } | |
7d270556 | 1496 | |
6b9dfe73 EL |
1497 | // Moodle v2.4.0 release upgrade line |
1498 | // Put any upgrade step following this | |
1499 | ||
1500 | ||
e28d5db2 MG |
1501 | if ($oldversion < 2012120300.01) { |
1502 | // Make sure site-course has format='site' //MDL-36840 | |
1503 | ||
1504 | if ($SITE->format !== 'site') { | |
1505 | $DB->set_field('course', 'format', 'site', array('id' => $SITE->id)); | |
1506 | $SITE->format = 'site'; | |
1507 | } | |
1508 | ||
1509 | // Main savepoint reached | |
1510 | upgrade_main_savepoint(true, 2012120300.01); | |
1511 | } | |
1512 | ||
dbfe4150 PS |
1513 | if ($oldversion < 2012120300.04) { |
1514 | // Remove "_utf8" suffix from all langs in course table. | |
1515 | $langs = $DB->get_records_sql("SELECT DISTINCT lang FROM {course} WHERE lang LIKE ?", array('%_utf8')); | |
1516 | ||
1517 | foreach ($langs as $lang=>$unused) { | |
1518 | $newlang = str_replace('_utf8', '', $lang); | |
1519 | $sql = "UPDATE {course} SET lang = :newlang WHERE lang = :lang"; | |
1520 | $DB->execute($sql, array('newlang'=>$newlang, 'lang'=>$lang)); | |
1521 | } | |
1522 | ||
1523 | // Main savepoint reached. | |
1524 | upgrade_main_savepoint(true, 2012120300.04); | |
1525 | } | |
1526 | ||
21df0539 | 1527 | if ($oldversion < 2012123000.00) { |
0662bd67 PS |
1528 | // Purge removed module filters and all their settings. |
1529 | ||
1530 | $tables = array('filter_active', 'filter_config'); | |
1531 | foreach ($tables as $table) { | |
1532 | $DB->delete_records_select($table, "filter LIKE 'mod/%'"); | |
1533 | $filters = $DB->get_records_sql("SELECT DISTINCT filter FROM {{$table}} WHERE filter LIKE 'filter/%'"); | |
1534 | foreach ($filters as $filter) { | |
1535 | $DB->set_field($table, 'filter', substr($filter->filter, 7), array('filter'=>$filter->filter)); | |
1536 | } | |
1537 | } | |
1538 | ||
1539 | $configs = array('stringfilters', 'filterall'); | |
1540 | foreach ($configs as $config) { | |
1541 | if ($filters = get_config(null, $config)) { | |
1542 | $filters = explode(',', $filters); | |
1543 | $newfilters = array(); | |
1544 | foreach($filters as $filter) { | |
1545 | if (strpos($filter, '/') === false) { | |
1546 | $newfilters[] = $filter; | |
1547 | } else if (strpos($filter, 'filter/') === 0) { | |
1548 | $newfilters[] = substr($filter, 7); | |
1549 | } | |
1550 | } | |
1551 | $filters = implode(',', $newfilters); | |
1552 | set_config($config, $filters); | |
1553 | } | |
1554 | } | |
1555 | ||
1556 | unset($tables); | |
1557 | unset($table); | |
1558 | unset($configs); | |
1559 | unset($newfilters); | |
1560 | unset($filters); | |
1561 | unset($filter); | |
1562 | ||
1563 | // Main savepoint reached. | |
21df0539 | 1564 | upgrade_main_savepoint(true, 2012123000.00); |
0662bd67 PS |
1565 | } |
1566 | ||
1e7db9fe | 1567 | if ($oldversion < 2013021100.01) { |
ec2d8ceb SC |
1568 | |
1569 | // Changing precision of field password on table user to (255). | |
1570 | $table = new xmldb_table('user'); | |
1571 | $field = new xmldb_field('password', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'username'); | |
1572 | ||
1573 | // Launch change of precision for field password. | |
1574 | $dbman->change_field_precision($table, $field); | |
1575 | ||
1576 | // Main savepoint reached. | |
1e7db9fe | 1577 | upgrade_main_savepoint(true, 2013021100.01); |
ec2d8ceb | 1578 | } |
0662bd67 | 1579 | |
e0d9b7c0 SH |
1580 | if ($oldversion < 2013021800.00) { |
1581 | // Add the site identifier to the cache config's file. | |
1582 | $siteidentifier = $DB->get_field('config', 'value', array('name' => 'siteidentifier')); | |
1583 | cache_helper::update_site_identifier($siteidentifier); | |
1584 | ||
1585 | // Main savepoint reached. | |
1586 | upgrade_main_savepoint(true, 2013021800.00); | |
1587 | } | |
1588 | ||
28d72ad9 | 1589 | if ($oldversion < 2013021801.00) { |
58b1904f FM |
1590 | // Fixing possible wrong MIME types for SMART Notebook files. |
1591 | $extensions = array('%.gallery', '%.galleryitem', '%.gallerycollection', '%.nbk', '%.notebook', '%.xbk'); | |
1592 | $select = $DB->sql_like('filename', '?', false); | |
1593 | foreach ($extensions as $extension) { | |
1594 | $DB->set_field_select( | |
1595 | 'files', | |
1596 | 'mimetype', | |
1597 | 'application/x-smarttech-notebook', | |
1598 | $select, | |
1599 | array($extension) | |
1600 | ); | |
1601 | } | |
219faacc | 1602 | upgrade_main_savepoint(true, 2013021801.00); |
58b1904f | 1603 | } |
e0d9b7c0 | 1604 | |
82a63328 | 1605 | if ($oldversion < 2013021801.01) { |
59a0ba3b ARN |
1606 | // Retrieve the list of course_sections as a recordset to save memory |
1607 | $coursesections = $DB->get_recordset('course_sections', null, 'course, id', 'id, course, sequence'); | |
1608 | foreach ($coursesections as $coursesection) { | |
1609 | // Retrieve all of the actual modules in this course and section combination to reduce DB calls | |
1610 | $actualsectionmodules = $DB->get_records('course_modules', | |
1611 | array('course' => $coursesection->course, 'section' => $coursesection->id), '', 'id, section'); | |
1612 | ||
1613 | // Break out the current sequence so that we can compare it | |
1614 | $currentsequence = explode(',', $coursesection->sequence); | |
1615 | $newsequence = array(); | |
1616 | ||
1617 | // Check each of the modules in the current sequence | |
1618 | foreach ($currentsequence as $module) { | |
1619 | if (isset($actualsectionmodules[$module])) { | |
1620 | $newsequence[] = $module; | |
1621 | // We unset the actualsectionmodules so that we don't get duplicates and that we can add orphaned | |
1622 | // modules later | |
1623 | unset($actualsectionmodules[$module]); | |
1624 | } | |
1625 | } | |
1626 | ||
1627 | // Append any modules which have somehow been orphaned | |
1628 | foreach ($actualsectionmodules as $module) { | |
1629 | $newsequence[] = $module->id; | |
1630 | } | |
1631 | ||
1632 | // Piece it all back together | |
1633 | $sequence = implode(',', $newsequence); | |
1634 | ||
1635 | // Only update if there have been changes | |
1636 | if ($sequence !== $coursesection->sequence) { | |
1637 | $coursesection->sequence = $sequence; | |
1638 | $DB->update_record('course_sections', $coursesection); | |
1639 | ||
1640 | // And clear the sectioncache and modinfo cache - they'll be regenerated on next use | |
1641 | $course = new stdClass(); | |
1642 | $course->id = $coursesection->course; | |
1643 | $course->sectioncache = null; | |
1644 | $course->modinfo = null; | |
1645 | $DB->update_record('course', $course); | |
1646 | } | |
1647 | } | |
1648 | $coursesections->close(); | |
1649 | ||
1650 | // Main savepoint reached. | |
82a63328 | 1651 | upgrade_main_savepoint(true, 2013021801.01); |
59a0ba3b ARN |
1652 | } |
1653 | ||
345768b9 | 1654 | if ($oldversion < 2013021902.00) { |
47570cc6 DP |
1655 | // ISO country change: Netherlands Antilles is split into BQ, CW & SX |
1656 | // http://www.iso.org/iso/iso_3166-1_newsletter_vi-8_split_of_the_dutch_antilles_final-en.pdf | |
1657 | $sql = "UPDATE {user} SET country = '' WHERE country = ?"; | |
1658 | $DB->execute($sql, array('AN')); | |
1659 | ||
345768b9 | 1660 | upgrade_main_savepoint(true, 2013021902.00); |
47570cc6 DP |
1661 | } |
1662 | ||
be1ef2f3 DW |
1663 | if ($oldversion < 2013022600.00) { |
1664 | // Delete entries regarding invalid 'interests' option which breaks course. | |
1665 | $DB->delete_records('course_sections_avail_fields', array('userfield' => 'interests')); | |
1666 | $DB->delete_records('course_modules_avail_fields', array('userfield' => 'interests')); | |
6fea7a5f | 1667 | // Clear course cache (will be rebuilt on first visit) in case of changes to these. |
4202471a | 1668 | $DB->execute('UPDATE {course} set modinfo = ?, sectioncache = ?', array(null, null)); |
6fea7a5f | 1669 | |
be1ef2f3 | 1670 | upgrade_main_savepoint(true, 2013022600.00); |
6fea7a5f | 1671 | } |
1672 | ||
e1580085 | 1673 | // Add index to field "timemodified" for grade_grades_history table. |
4ce76171 | 1674 | if ($oldversion < 2013030400.00) { |
e1580085 TG |
1675 | $table = new xmldb_table('grade_grades_history'); |
1676 | $field = new xmldb_field('timemodified'); | |
1677 | ||
1678 | if ($dbman->field_exists($table, $field)) { | |
1679 | $index = new xmldb_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified')); | |
1680 | if (!$dbman->index_exists($table, $index)) { | |
1681 | $dbman->add_index($table, $index); | |
1682 | } | |
1683 | } | |
1684 | ||
1685 | // Main savepoint reached. | |
4ce76171 | 1686 | upgrade_main_savepoint(true, 2013030400.00); |
e1580085 TG |
1687 | } |
1688 | ||
adc4aca4 | 1689 | if ($oldversion < 2013030400.02) { |
4f315786 JMV |
1690 | // Cleanup qformat blackboard settings. |
1691 | unset_all_config_for_plugin('qformat_blackboard'); | |
1692 | ||
adc4aca4 | 1693 | upgrade_main_savepoint(true, 2013030400.02); |
4f315786 JMV |
1694 | } |
1695 | ||
005c6640 DW |
1696 | // This is checking to see if the site has been running a specific version with a bug in it |
1697 | // because this upgrade step is slow and is only needed if the site has been running with the affected versions. | |
8673a98d | 1698 | if ($oldversion >= 2012062504.08 && $oldversion < 2012062504.13) { |
005c6640 DW |
1699 | // Retrieve the list of course_sections as a recordset to save memory. |
1700 | // This is to fix a regression caused by MDL-37939. | |
1701 | // In this case the upgrade step is fixing records where: | |
1702 | // The data in course_sections.sequence contains the correct module id | |
1703 | // The section field for on the course modules table may have been updated to point to the incorrect id. | |
1704 | ||
1705 | // This query is looking for sections where the sequence is not in sync with the course_modules table. | |
1706 | // The syntax for the like query is looking for a value in a comma separated list. | |
1707 | // It adds a comma to either site of the list and then searches for LIKE '%,id,%'. | |
1708 | $sequenceconcat = $DB->sql_concat("','", 's.sequence', "','"); | |
1709 | $moduleconcat = $DB->sql_concat("'%,'", 'cm.id', "',%'"); | |
1710 | $sql = 'SELECT s2.id, s2.course, s2.sequence | |
8673a98d | 1711 | FROM {course_sections} s2 |
005c6640 DW |
1712 | JOIN( |
1713 | SELECT DISTINCT s.id | |
1714 | FROM | |
1715 | {course_modules} cm | |
1716 | JOIN {course_sections} s | |
1717 | ON | |
1718 | cm.course = s.course | |
1719 | WHERE cm.section != s.id AND ' . $sequenceconcat . ' LIKE ' . $moduleconcat . ' | |
1720 | ) d | |
1721 | ON s2.id = d.id'; | |
1722 | $coursesections = $DB->get_recordset_sql($sql); | |
1723 | ||
1724 | foreach ($coursesections as $coursesection) { | |
1725 | // Retrieve all of the actual modules in this course and section combination to reduce DB calls. | |
1726 | $actualsectionmodules = $DB->get_records('course_modules', | |
1727 | array('course' => $coursesection->course, 'section' => $coursesection->id), '', 'id, section'); | |
1728 | ||
1729 | // Break out the current sequence so that we can compare it. | |
1730 | $currentsequence = explode(',', $coursesection->sequence); | |
1731 | $orphanlist = array(); | |
1732 | ||
1733 | // Check each of the modules in the current sequence. | |
1734 | foreach ($currentsequence as $cmid) { | |
1735 | if (!empty($cmid) && !isset($actualsectionmodules[$cmid])) { | |
1736 | $orphanlist[] = $cmid; | |
1737 | } | |
1738 | } | |
1739 | ||
1740 | if (!empty($orphanlist)) { | |
1741 | list($sql, $params) = $DB->get_in_or_equal($orphanlist, SQL_PARAMS_NAMED); | |
1742 | $sql = "id $sql"; | |
1743 | ||
1744 | $DB->set_field_select('course_modules', 'section', $coursesection->id, $sql, $params); | |
1745 | ||
1746 | // And clear the sectioncache and modinfo cache - they'll be regenerated on next use. | |
1747 | $course = new stdClass(); | |
1748 | $course->id = $coursesection->course; | |
1749 | $course->sectioncache = null; | |
1750 | $course->modinfo = null; | |
1751 | $DB->update_record('course', $course); | |
1752 | } | |
1753 | } | |
1754 | $coursesections->close(); | |
1755 | ||
1756 | // No savepoint needed for this change. | |
1757 | } | |
1758 | ||
689096bc PS |
1759 | if ($oldversion < 2013032200.01) { |
1760 | // GD is now always available | |
c7289da7 | 1761 | set_config('gdversion', 2); |
689096bc PS |
1762 | |
1763 | upgrade_main_savepoint(true, 2013032200.01); | |
1764 | } | |
1765 | ||
2013daeb | 1766 | if ($oldversion < 2013032600.03) { |
2aecb84d MS |
1767 | // Fixing possible wrong MIME type for MIME HTML (MHTML) files. |
1768 | $extensions = array('%.mht', '%.mhtml'); | |
1769 | $select = $DB->sql_like('filename', '?', false); | |
1770 | foreach ($extensions as $extension) { | |
1771 | $DB->set_field_select( | |
1772 | 'files', | |
1773 | 'mimetype', | |
1774 | 'message/rfc822', | |
1775 | $select, | |
1776 | array($extension) | |
1777 | ); | |
1778 | } | |
2013daeb | 1779 | upgrade_main_savepoint(true, 2013032600.03); |
2aecb84d MS |
1780 | } |
1781 | ||
cf140de9 | 1782 | if ($oldversion < 2013032600.04) { |
0559a72a TH |
1783 | // MDL-31983 broke the quiz version number. Fix it. |
1784 | $DB->set_field('modules', 'version', '2013021500', | |
1785 | array('name' => 'quiz', 'version' => '2013310100')); | |
cf140de9 | 1786 | upgrade_main_savepoint(true, 2013032600.04); |
0559a72a TH |
1787 | } |
1788 | ||
27806552 YB |
1789 | if ($oldversion < 2013040200.00) { |
1790 | // Add openbadges tables. | |
1791 | ||
1792 | // Define table 'badge' to be created. | |
1793 | $table = new xmldb_table('badge'); | |
1794 | ||
1795 | // Adding fields to table 'badge'. | |
1796 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); | |
1797 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'id'); | |
1798 | $table->add_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null, 'name'); | |
1799 | $table->add_field('image', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'description'); | |
1800 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'image'); | |
1801 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'timecreated'); | |
1802 | $table->add_field('usercreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'timemodified'); | |
1803 | $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'usercreated'); | |
1804 | $table->add_field('issuername', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'usermodified'); | |
1805 | $table->add_field('issuerurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'issuername'); | |
1806 | $table->add_field('issuercontact', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'issuerurl'); | |
1807 | $table->add_field('expiredate', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'issuercontact'); | |
1808 | $table->add_field('expireperiod', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'expiredate'); | |
1809 | $table->add_field('type', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'expireperiod'); | |
1810 | $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'type'); | |
1811 | $table->add_field('message', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'courseid'); | |
1812 | $table->add_field('messagesubject', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'message'); | |
1813 | $table->add_field('attachment', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'messagesubject'); | |
1814 | $table->add_field('notification', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'attachment'); | |
1815 | $table->add_field('status', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'notification'); | |
1816 | $table->add_field('nextcron', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'status'); | |
1817 | ||
1818 | // Adding keys to table 'badge'. | |
1819 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1820 | $table->add_key('fk_courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id')); | |
1821 | $table->add_key('fk_usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id')); | |
1822 | $table->add_key('fk_usercreated', XMLDB_KEY_FOREIGN, array('usercreated'), 'user', array('id')); | |
1823 | ||
1824 | // Adding indexes to table 'badge'. | |
1825 | $table->add_index('type', XMLDB_INDEX_NOTUNIQUE, array('type')); | |
1826 | ||
1827 | // Conditionally launch create table for 'badge'. | |
1828 | if (!$dbman->table_exists($table)) { | |
1829 | $dbman->create_table($table); | |
1830 | } | |
1831 | ||
1832 | // Define table 'badge_criteria' to be created. | |
1833 | $table = new xmldb_table('badge_criteria'); | |
1834 | ||
1835 | // Adding fields to table 'badge_criteria'. | |
1836 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); | |
1837 | $table->add_field('badgeid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); | |
1838 | $table->add_field('criteriatype', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'badgeid'); | |
1839 | $table->add_field('method', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'criteriatype'); | |
1840 | ||
1841 | // Adding keys to table 'badge_criteria'. | |
1842 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1843 | $table->add_key('fk_badgeid', XMLDB_KEY_FOREIGN, array('badgeid'), 'badge', array('id')); | |
1844 | ||
1845 | // Adding indexes to table 'badge_criteria'. | |
27806552 YB |
1846 | $table->add_index('criteriatype', XMLDB_INDEX_NOTUNIQUE, array('criteriatype')); |
1847 | $table->add_index('badgecriteriatype', XMLDB_INDEX_UNIQUE, array('badgeid', 'criteriatype')); | |
1848 | ||
1849 | // Conditionally launch create table for 'badge_criteria'. | |
1850 | if (!$dbman->table_exists($table)) { | |
1851 | $dbman->create_table($table); | |
1852 | } | |
1853 | ||
1854 | // Define table 'badge_criteria_param' to be created. | |
1855 | $table = new xmldb_table('badge_criteria_param'); | |
1856 | ||
1857 | // Adding fields to table 'badge_criteria_param'. | |
1858 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); | |
1859 | $table->add_field('critid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'id'); | |
1860 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'critid'); | |
1861 | $table->add_field('value', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'name'); | |
1862 | ||
1863 | // Adding keys to table 'badge_criteria_param'. | |
1864 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1865 | $table->add_key('fk_critid', XMLDB_KEY_FOREIGN, array('critid'), 'badge_criteria', array('id')); | |
1866 | ||
27806552 YB |
1867 | // Conditionally launch create table for 'badge_criteria_param'. |
1868 | if (!$dbman->table_exists($table)) { | |
1869 | $dbman->create_table($table); | |
1870 | } | |
1871 | ||
1872 | // Define table 'badge_issued' to be created. | |
1873 | $table = new xmldb_table('badge_issued'); | |
1874 | ||
1875 | // Adding fields to table 'badge_issued'. | |
1876 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); | |
1877 | $table->add_field('badgeid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); | |
1878 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'badgeid'); | |
1879 | $table->add_field('uniquehash', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'userid'); | |
1880 | $table->add_field('dateissued', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'uniquehash'); | |
1881 | $table->add_field('dateexpire', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'dateissued'); | |
1882 | $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'dateexpire'); | |
1883 | $table->add_field('issuernotified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'visible'); | |
1884 | ||
1885 | // Adding keys to table 'badge_issued'. | |
1886 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1887 | $table->add_key('fk_badgeid', XMLDB_KEY_FOREIGN, array('badgeid'), 'badge', array('id')); | |
1888 | $table->add_key('fk_userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
1889 | ||
27806552 YB |
1890 | $table->add_index('badgeuser', XMLDB_INDEX_UNIQUE, array('badgeid', 'userid')); |
1891 | ||
1892 | // Conditionally launch create table for 'badge_issued'. | |
1893 | if (!$dbman->table_exists($table)) { | |
1894 | $dbman->create_table($table); | |
1895 | } | |
1896 | ||
1897 | // Define table 'badge_criteria_met' to be created. | |
1898 | $table = new xmldb_table('badge_criteria_met'); | |
1899 | ||
1900 | // Adding fields to table 'badge_criteria_met'. | |
1901 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); | |
1902 | $table->add_field('issuedid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'id'); | |
1903 | $table->add_field('critid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'issuedid'); | |
1904 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'critid'); | |
1905 | $table->add_field('datemet', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'userid'); | |
1906 | ||
1907 | // Adding keys to table 'badge_criteria_met' | |
1908 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1909 | $table->add_key('fk_critid', XMLDB_KEY_FOREIGN, array('critid'), 'badge_criteria', array('id')); | |
1910 | $table->add_key('fk_userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
1911 | $table->add_key('fk_issuedid', XMLDB_KEY_FOREIGN, array('issuedid'), 'badge_issued', array('id')); | |
1912 | ||
1913 | // Conditionally launch create table for 'badge_criteria_met'. | |
1914 | if (!$dbman->table_exists($table)) { | |
1915 | $dbman->create_table($table); | |
1916 | } | |
1917 | ||
1918 | // Define table 'badge_manual_award' to be created. | |
1919 | $table = new xmldb_table('badge_manual_award'); | |
1920 | ||
1921 | // Adding fields to table 'badge_manual_award'. | |
1922 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); | |
1923 | $table->add_field('badgeid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'id'); | |
1924 | $table->add_field('recipientid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'badgeid'); | |
1925 | $table->add_field('issuerid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'recipientid'); | |
1926 | $table->add_field('issuerrole', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'issuerid'); | |
1927 | $table->add_field('datemet', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'issuerrole'); | |
1928 | ||
1929 | // Adding keys to table 'badge_manual_award'. | |
1930 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2916ca61 | 1931 | $table->add_key('fk_badgeid', XMLDB_KEY_FOREIGN, array('badgeid'), 'badge', array('id')); |
27806552 YB |
1932 | $table->add_key('fk_recipientid', XMLDB_KEY_FOREIGN, array('recipientid'), 'user', array('id')); |
1933 | $table->add_key('fk_issuerid', XMLDB_KEY_FOREIGN, array('issuerid'), 'user', array('id')); | |
1934 | $table->add_key('fk_issuerrole', XMLDB_KEY_FOREIGN, array('issuerrole'), 'role', array('id')); | |
1935 | ||
1936 | // Conditionally launch create table for 'badge_manual_award'. | |
1937 | if (!$dbman->table_exists($table)) { | |
1938 | $dbman->create_table($table); | |
1939 | } | |
1940 | ||
1941 | // Define table 'badge_backpack' to be created. | |
1942 | $table = new xmldb_table('badge_backpack'); | |
1943 | ||
1944 | // Adding fields to table 'badge_backpack'. | |
1945 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); | |
1946 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id'); | |
1947 | $table->add_field('email', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'userid'); | |
1948 | $table->add_field('backpackurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'email'); | |
1949 | $table->add_field('backpackuid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'backpackurl'); | |
1950 | $table->add_field('backpackgid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'backpackuid'); | |
1951 | $table->add_field('autosync', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'backpackgid'); | |
1952 | $table->add_field('password', XMLDB_TYPE_CHAR, '50', null, null, null, null, 'autosync'); | |
1953 | ||
1954 | // Adding keys to table 'badge_backpack'. | |
1955 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1956 | $table->add_key('fk_userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
1957 | ||
27806552 YB |
1958 | // Conditionally launch create table for 'badge_backpack'. |
1959 | if (!$dbman->table_exists($table)) { | |
1960 | $dbman->create_table($table); | |
1961 | } | |
1962 | ||
1963 | // Main savepoint reached. | |
1964 | upgrade_main_savepoint(true, 2013040200.00); | |
1965 | } | |
1966 | ||
eee20b12 | 1967 | if ($oldversion < 2013040201.00) { |
e2e9ff65 RT |
1968 | // Convert name field in event table to text type as RFC-2445 doesn't have any limitation on it. |
1969 | $table = new xmldb_table('event'); | |
1970 | $field = new xmldb_field('name', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null); | |
1971 | if ($dbman->field_exists($table, $field)) { | |
1972 | $dbman->change_field_type($table, $field); | |
1973 | } | |
1974 | // Main savepoint reached. | |
eee20b12 | 1975 | upgrade_main_savepoint(true, 2013040201.00); |
e2e9ff65 RT |
1976 | } |
1977 | ||
dcf63185 | 1978 | if ($oldversion < 2013040300.01) { |
8819a836 FM |
1979 | |
1980 | // Define field completionstartonenrol to be dropped from course. | |
1981 | $table = new xmldb_table('course'); | |
1982 | $field = new xmldb_field('completionstartonenrol'); | |
1983 | ||
1984 | // Conditionally launch drop field completionstartonenrol. | |
1985 | if ($dbman->field_exists($table, $field)) { | |
1986 | $dbman->drop_field($table, $field); | |
1987 | } | |
1988 | ||
1989 | // Main savepoint reached. | |
dcf63185 | 1990 | upgrade_main_savepoint(true, 2013040300.01); |
8819a836 FM |
1991 | } |
1992 | ||
42f563f6 | 1993 | if ($oldversion < 2013041200.00) { |
63354ab5 | 1994 | // MDL-29877 Some bad restores created grade items with no category information. |
c7ee04bd | 1995 | $sql = "UPDATE {grade_items} |
63354ab5 AD |
1996 | SET categoryid = courseid |
1997 | WHERE itemtype <> 'course' and itemtype <> 'category' | |
1998 | AND categoryid IS NULL"; | |
1999 | $DB->execute($sql); | |
42f563f6 | 2000 | upgrade_main_savepoint(true, 2013041200.00); |
63354ab5 AD |
2001 | } |
2002 | ||
0fd26350 MG |
2003 | if ($oldversion < 2013041600.00) { |
2004 | // Copy constants from /course/lib.php instead of including the whole library: | |
2005 | $c = array( 'FRONTPAGENEWS' => 0, | |
2006 | 'FRONTPAGECOURSELIST' => 1, | |
2007 | 'FRONTPAGECATEGORYNAMES' => 2, | |
2008 | 'FRONTPAGETOPICONLY' => 3, | |
2009 | 'FRONTPAGECATEGORYCOMBO' => 4, | |
2010 | 'FRONTPAGEENROLLEDCOURSELIST' => 5, | |
2011 | 'FRONTPAGEALLCOURSELIST' => 6, | |
2012 | 'FRONTPAGECOURSESEARCH' => 7); | |
2013 | // Update frontpage settings $CFG->frontpage and $CFG->frontpageloggedin. In 2.4 there was too much of hidden logic about them. | |
2014 | // This script tries to make sure that with the new (more user-friendly) frontpage settings the frontpage looks as similar as possible to what it was before upgrade. | |
2015 | $ncourses = $DB->count_records('course'); | |
2016 | foreach (array('frontpage', 'frontpageloggedin') as $configkey) { | |
2017 | if ($frontpage = explode(',', $CFG->{$configkey})) { | |
2018 | $newfrontpage = array(); | |
2019 | foreach ($frontpage as $v) { | |
2020 | switch ($v) { | |
2021 | case $c['FRONTPAGENEWS']: | |
2022 | // Not related to course listings, leave as it is. | |
2023 | $newfrontpage[] = $c['FRONTPAGENEWS']; | |
2024 | break; | |
2025 | case $c['FRONTPAGECOURSELIST']: | |
2026 | if ($configkey === 'frontpageloggedin' && empty($CFG->disablemycourses)) { | |
2027 | // In 2.4 unless prohibited in config, the "list of courses" was considered "list of enrolled courses" plus course search box. | |
2028 | $newfrontpage[] = $c['FRONTPAGEENROLLEDCOURSELIST']; | |
2029 | } else if ($ncourses <= 200) { | |
2030 | // Still list of courses was only displayed in there were less than 200 courses in system. Otherwise - search box only. | |
2031 | $newfrontpage[] = $c['FRONTPAGEALLCOURSELIST']; | |
2032 | break; // skip adding search box | |
2033 | } | |
2034 | if (!in_array($c['FRONTPAGECOURSESEARCH'], $newfrontpage)) { | |
2035 | $newfrontpage[] = $c['FRONTPAGECOURSESEARCH']; | |
2036 | } | |
2037 | break; | |
2038 | case $c['FRONTPAGECATEGORYNAMES']: | |
2039 | // In 2.4 search box was displayed automatically after categories list. In 2.5 it is displayed as a separate setting. | |
2040 | $newfrontpage[] = $c['FRONTPAGECATEGORYNAMES']; | |
2041 | if (!in_array($c['FRONTPAGECOURSESEARCH'], $newfrontpage)) { | |
2042 | $newfrontpage[] = $c['FRONTPAGECOURSESEARCH']; | |
2043 | } | |
2044 | break; | |
2045 | case $c['FRONTPAGECATEGORYCOMBO']: | |
2046 | $maxcourses = empty($CFG->numcoursesincombo) ? 500 : $CFG->numcoursesincombo; | |
2047 | // In 2.4 combo list was not displayed if there are more than $CFG->numcoursesincombo courses in the system. | |
2048 | if ($ncourses < $maxcourses) { | |
2049 | $newfrontpage[] = $c['FRONTPAGECATEGORYCOMBO']; | |
2050 | } | |
2051 | if (!in_array($c['FRONTPAGECOURSESEARCH'], $newfrontpage)) { | |
2052 | $newfrontpage[] = $c['FRONTPAGECOURSESEARCH']; | |
2053 | } | |
2054 | break; | |
2055 | } | |
2056 | } | |
2057 | set_config($configkey, join(',', $newfrontpage)); | |
2058 | } | |
2059 | } | |
2060 | // $CFG->numcoursesincombo no longer affects whether the combo list is displayed. Setting is deprecated. | |
2061 | unset_config('numcoursesincombo'); | |
2062 | ||
2063 | upgrade_main_savepoint(true, 2013041600.00); | |
2064 | } | |
2065 | ||
19226a30 | 2066 | if ($oldversion < 2013041601.00) { |
e2805314 YB |
2067 | // Create a new 'badge_external' table first. |
2068 | // Define table 'badge_external' to be created. | |
2069 | $table = new xmldb_table('badge_external'); | |
7e43a15f | 2070 | |
e2805314 YB |
2071 | // Adding fields to table 'badge_external'. |
2072 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); | |
2073 | $table->add_field('backpackid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'id'); | |
2074 | $table->add_field('collectionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'backpackid'); | |
7e43a15f | 2075 | |
e2805314 YB |
2076 | // Adding keys to table 'badge_external'. |
2077 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2078 | $table->add_key('fk_backpackid', XMLDB_KEY_FOREIGN, array('backpackid'), 'badge_backpack', array('id')); | |
7e43a15f | 2079 | |
e2805314 YB |
2080 | // Conditionally launch create table for 'badge_external'. |
2081 | if (!$dbman->table_exists($table)) { | |
2082 | $dbman->create_table($table); | |
2083 | } | |
7e43a15f | 2084 | |
e2805314 YB |
2085 | // Perform user data migration. |
2086 | $usercollections = $DB->get_records('badge_backpack'); | |
2087 | foreach ($usercollections as $usercollection) { | |
2088 | $collection = new stdClass(); | |
2089 | $collection->backpackid = $usercollection->id; | |
2090 | $collection->collectionid = $usercollection->backpackgid; | |
2091 | $DB->insert_record('badge_external', $collection); | |
2092 | } | |
7e43a15f | 2093 | |
e2805314 YB |
2094 | // Finally, drop the column. |
2095 | // Define field backpackgid to be dropped from 'badge_backpack'. | |
2096 | $table = new xmldb_table('badge_backpack'); | |
2097 | $field = new xmldb_field('backpackgid'); | |
7e43a15f | 2098 | |
e2805314 YB |
2099 | // Conditionally launch drop field backpackgid. |
2100 | if ($dbman->field_exists($table, $field)) { | |
2101 | $dbman->drop_field($table, $field); | |
2102 | } | |
7e43a15f | 2103 | |
e2805314 | 2104 | // Main savepoint reached. |
19226a30 | 2105 | upgrade_main_savepoint(true, 2013041601.00); |
e2805314 YB |
2106 | } |
2107 | ||
359c1d47 | 2108 | if ($oldversion < 2013041601.01) { |
0c4c981f PS |
2109 | // Changing the default of field descriptionformat on table user to 1. |
2110 | $table = new xmldb_table('user'); | |
2111 | $field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '1', 'description'); | |
2112 | ||
2113 | // Launch change of default for field descriptionformat. | |
2114 | $dbman->change_field_default($table, $field); | |
2115 | ||
2116 | // Main savepoint reached. | |
359c1d47 | 2117 | upgrade_main_savepoint(true, 2013041601.01); |
0c4c981f PS |
2118 | } |
2119 | ||
fbf76dcd | 2120 | if ($oldversion < 2013041900.00) { |
5cba0c4b | 2121 | require_once($CFG->dirroot . '/cache/locallib.php'); |
fbf76dcd SH |
2122 | // The features bin needs updating. |
2123 | cache_config_writer::update_default_config_stores(); | |
2124 | // Main savepoint reached. | |
2125 | upgrade_main_savepoint(true, 2013041900.00); | |
2126 | } | |
2127 | ||
b0c4e474 | 2128 | if ($oldversion < 2013042300.00) { |
d750d41e MC |
2129 | // Adding index to unreadmessageid field of message_working table (MDL-34933) |
2130 | $table = new xmldb_table('message_working'); | |
2131 | $index = new xmldb_index('unreadmessageid_idx', XMLDB_INDEX_NOTUNIQUE, array('unreadmessageid')); | |
2132 | ||
2133 | // Conditionally launch add index unreadmessageid | |
2134 | if (!$dbman->index_exists($table, $index)) { | |
2135 | $dbman->add_index($table, $index); | |
2136 | } | |
2137 | ||
2138 | // Main savepoint reached. | |
b0c4e474 | 2139 | upgrade_main_savepoint(true, 2013042300.00); |
d750d41e MC |
2140 | } |
2141 | ||
4f5bcf2e DP |
2142 | // Moodle v2.5.0 release upgrade line. |
2143 | // Put any upgrade step following this. | |
2144 | ||
82198dec DP |
2145 | if ($oldversion < 2013051400.01) { |
2146 | // Fix incorrect cc-nc url. Unfortunately the license 'plugins' do | |
2147 | // not give a mechanism to do this. | |
2148 | ||
2149 | $sql = "UPDATE {license} | |
2150 | SET source = :url, version = :newversion | |
2151 | WHERE shortname = :shortname AND version = :oldversion"; | |
2152 | ||
2153 | $params = array( | |
2154 | 'url' => 'http://creativecommons.org/licenses/by-nc/3.0/', | |
2155 | 'shortname' => 'cc-nc', | |
2156 | 'newversion' => '2013051500', | |
2157 | 'oldversion' => '2010033100' | |
2158 | ); | |
2159 | ||
2160 | $DB->execute($sql, $params); | |
2161 | ||
2162 | // Main savepoint reached. | |
2163 | upgrade_main_savepoint(true, 2013051400.01); | |
2164 | } | |
2165 | ||
a48dad1f | 2166 | if ($oldversion < 2013061400.01) { |
9feda85d DP |
2167 | // Clean up old tokens which haven't been deleted. |
2168 | $DB->execute("DELETE FROM {user_private_key} WHERE NOT EXISTS | |
2169 | (SELECT 'x' FROM {user} WHERE deleted = 0 AND id = userid)"); | |
2170 | ||
2171 | // Main savepoint reached. | |
a48dad1f | 2172 | upgrade_main_savepoint(true, 2013061400.01); |
9feda85d DP |
2173 | } |
2174 | ||
96c90fab | 2175 | if ($oldversion < 2013061700.00) { |
283e448a | 2176 | // MDL-40103: Remove unused template tables from the database. |
672bee2d | 2177 | // These are now created inline with xmldb_table. |
283e448a | 2178 | |
62d6f183 RS |
2179 | $tablestocleanup = array('temp_enroled_template','temp_log_template','backup_files_template','backup_ids_template'); |
2180 | $dbman = $DB->get_manager(); | |
283e448a | 2181 | |
62d6f183 | 2182 | foreach ($tablestocleanup as $table) { |
283e448a | 2183 | $xmltable = new xmldb_table($table); |
672bee2d | 2184 | if ($dbman->table_exists($xmltable)) { |
62d6f183 RS |
2185 | $dbman->drop_table($xmltable); |
2186 | } | |
283e448a RS |
2187 | } |
2188 | ||
2189 | // Main savepoint reached. | |
96c90fab | 2190 | upgrade_main_savepoint(true, 2013061700.00); |
283e448a | 2191 | } |
96c90fab | 2192 | |
64830bf6 | 2193 | if ($oldversion < 2013070800.00) { |
4aa4d88d FM |
2194 | |
2195 | // Remove orphan repository instances. | |
0193dd1c FM |
2196 | if ($DB->get_dbfamily() === 'mysql') { |
2197 | $sql = "DELETE {repository_instances} FROM {repository_instances} | |
2198 | LEFT JOIN {context} ON {context}.id = {repository_instances}.contextid | |
2199 | WHERE {context}.id IS NULL"; | |
2200 | } else { | |
2201 | $sql = "DELETE FROM {repository_instances} | |
2202 | WHERE NOT EXISTS ( | |
2203 | SELECT 'x' FROM {context} | |
2204 | WHERE {context}.id = {repository_instances}.contextid)"; | |
2205 | } | |
2206 | $DB->execute($sql); | |
4aa4d88d FM |
2207 | |
2208 | // Main savepoint reached. | |
64830bf6 | 2209 | upgrade_main_savepoint(true, 2013070800.00); |
4aa4d88d FM |
2210 | } |
2211 | ||
a327f25e AG |
2212 | if ($oldversion < 2013070800.01) { |
2213 | ||
2214 | // Define field lastnamephonetic to be added to user. | |
2215 | $table = new xmldb_table('user'); | |
2216 | $field = new xmldb_field('lastnamephonetic', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'imagealt'); | |
2217 | $index = new xmldb_index('lastnamephonetic', XMLDB_INDEX_NOTUNIQUE, array('lastnamephonetic')); | |
2218 | ||
2219 | // Conditionally launch add field lastnamephonetic. | |
2220 | if (!$dbman->field_exists($table, $field)) { | |
2221 | $dbman->add_field($table, $field); | |
2222 | $dbman->add_index($table, $index); | |
2223 | } | |
2224 | ||
2225 | // Define field firstnamephonetic to be added to user. | |
2226 | $table = new xmldb_table('user'); | |
2227 | $field = new xmldb_field('firstnamephonetic', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'lastnamephonetic'); | |
2228 | $index = new xmldb_index('firstnamephonetic', XMLDB_INDEX_NOTUNIQUE, array('firstnamephonetic')); | |
2229 | ||
2230 | // Conditionally launch add field firstnamephonetic. | |
2231 | if (!$dbman->field_exists($table, $field)) { | |
2232 | $dbman->add_field($table, $field); | |
2233 | $dbman->add_index($table, $index); | |
2234 | } | |
2235 | ||
2236 | // Define field alternatename to be added to user. | |
2237 | $table = new xmldb_table('user'); | |
2238 | $field = new xmldb_field('middlename', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'firstnamephonetic'); | |
2239 | $index = new xmldb_index('middlename', XMLDB_INDEX_NOTUNIQUE, array('middlename')); | |
2240 | ||
2241 | // Conditionally launch add field firstnamephonetic. | |
2242 | if (!$dbman->field_exists($table, $field)) { | |
2243 | $dbman->add_field($table, $field); | |
2244 | $dbman->add_index($table, $index); | |
2245 | } | |
2246 | ||
2247 | // Define field alternatename to be added to user. | |
2248 | $table = new xmldb_table('user'); | |
2249 | $field = new xmldb_field('alternatename', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'middlename'); | |
2250 | $index = new xmldb_index('alternatename', XMLDB_INDEX_NOTUNIQUE, array('alternatename')); | |
2251 | ||
2252 | // Conditionally launch add field alternatename. | |
2253 | if (!$dbman->field_exists($table, $field)) { | |
2254 | $dbman->add_field($table, $field); | |
2255 | $dbman->add_index($table, $index); | |
2256 | } | |
2257 | ||
2258 | // Main savepoint reached. | |
2259 | upgrade_main_savepoint(true, 2013070800.01); | |
2260 | } | |
2261 | ||
c2ca2d8e DP |
2262 | if ($oldversion < 2013071500.01) { |
2263 | // The enrol_authorize plugin has been removed, if there are no records | |
2264 | // and no plugin files then remove the plugin data. | |
2265 | $enrolauthorize = new xmldb_table('enrol_authorize'); | |
2266 | $enrolauthorizerefunds = new xmldb_table('enrol_authorize_refunds'); | |
2267 | ||
2268 | if (!file_exists($CFG->dirroot.'/enrol/authorize/version.php') && | |
2269 | $dbman->table_exists($enrolauthorize) && | |
2270 | $dbman->table_exists($enrolauthorizerefunds)) { | |
2271 | ||
2272 | $enrolauthorizecount = $DB->count_records('enrol_authorize'); | |
2273 | $enrolauthorizerefundcount = $DB->count_records('enrol_authorize_refunds'); | |
2274 | ||
2275 | if (empty($enrolauthorizecount) && empty($enrolauthorizerefundcount)) { | |
2276 | ||
2277 | // Drop the database tables. | |
2278 | $dbman->drop_table($enrolauthorize); | |
2279 | $dbman->drop_table($enrolauthorizerefunds); | |
2280 | ||
2281 | // Drop the message provider and associated data manually. | |
2282 | $DB->delete_records('message_providers', array('component' => 'enrol_authorize')); | |
2283 | $DB->delete_records_select('config_plugins', "plugin = 'message' AND ".$DB->sql_like('name', '?', false), array("%_provider_enrol_authorize_%")); | |
2284 | $DB->delete_records_select('user_preferences', $DB->sql_like('name', '?', false), array("message_provider_enrol_authorize_%")); | |
2285 | ||
2286 | // Remove capabilities. | |
2287 | capabilities_cleanup('enrol_authorize'); | |
2288 | ||
2289 | // Remove all other associated config. | |
2290 | unset_all_config_for_plugin('enrol_authorize'); | |
2291 | } | |
2292 | } | |
2293 | upgrade_main_savepoint(true, 2013071500.01); | |
2294 | } | |
2295 | ||
e780e5cb | 2296 | if ($oldversion < 2013071500.02) { |
e50220f8 YB |
2297 | // Define field attachment to be dropped from badge. |
2298 | $table = new xmldb_table('badge'); | |
2299 | $field = new xmldb_field('image'); | |
2300 | ||
2301 | // Conditionally launch drop field eventtype. | |
2302 | if ($dbman->field_exists($table, $field)) { | |
2303 | $dbman->drop_field($table, $field); | |
2304 | } | |
2305 | ||
e780e5cb | 2306 | upgrade_main_savepoint(true, 2013071500.02); |
e50220f8 YB |
2307 | } |
2308 | ||
656250de PS |
2309 | if ($oldversion < 2013072600.01) { |
2310 | upgrade_mssql_nvarcharmax(); | |
2311 | upgrade_mssql_varbinarymax(); | |
2312 | ||
2313 | upgrade_main_savepoint(true, 2013072600.01); | |
2314 | } | |
2315 | ||
8b7378cf | 2316 | if ($oldversion < 2013081200.00) { |
106c55fb DW |
2317 | // Define field uploadfiles to be added to external_services. |
2318 | $table = new xmldb_table('external_services'); | |
2319 | $field = new xmldb_field('uploadfiles', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'downloadfiles'); | |
2320 | ||
2321 | // Conditionally launch add field uploadfiles. | |
2322 | if (!$dbman->field_exists($table, $field)) { | |
2323 | $dbman->add_field($table, $field); | |
2324 | } | |
2325 | ||
2326 | // Main savepoint reached. | |
8b7378cf | 2327 | upgrade_main_savepoint(true, 2013081200.00); |
106c55fb DW |
2328 | } |
2329 | ||
6d8627cb MN |
2330 | if ($oldversion < 2013082300.01) { |
2331 | // Define the table 'backup_logs' and the field 'message' which we will be changing from a char to a text field. | |
2332 | $table = new xmldb_table('backup_logs'); | |
2333 | $field = new xmldb_field('message', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null, 'loglevel'); | |
2334 | ||
2335 | // Perform the change. | |
2336 | $dbman->change_field_type($table, $field); | |
2337 | ||
2338 | // Main savepoint reached. | |
2339 | upgrade_main_savepoint(true, 2013082300.01); | |
2340 | } | |
2341 | ||
3d1808c6 | 2342 | // Convert SCORM course format courses to singleactivity. |
f6c2af86 | 2343 | if ($oldversion < 2013082700.00) { |
3d1808c6 DM |
2344 | // First set relevant singleactivity settings. |
2345 | $formatoptions = new stdClass(); | |
2346 | $formatoptions->format = 'singleactivity'; | |
2347 | $formatoptions->sectionid = 0; | |
2348 | $formatoptions->name = 'activitytype'; | |
2349 | $formatoptions->value = 'scorm'; | |
2350 | ||
2351 | $courses = $DB->get_recordset('course', array('format' => 'scorm'), 'id'); | |
2352 | foreach ($courses as $course) { | |
2353 | $formatoptions->courseid = $course->id; | |
2354 | $DB->insert_record('course_format_options', $formatoptions); | |
2355 | } | |
2356 | $courses->close(); | |
2357 | ||
2358 | // Now update course format for these courses. | |
2359 | $sql = "UPDATE {course} | |
2360 | SET format = 'singleactivity', modinfo = '', sectioncache = '' | |
2361 | WHERE format = 'scorm'"; | |
2362 | $DB->execute($sql); | |
f6c2af86 | 2363 | upgrade_main_savepoint(true, 2013082700.00); |
3d1808c6 DM |
2364 | } |
2365 | ||
62321a7b MN |
2366 | if ($oldversion < 2013090500.01) { |
2367 | // Define field calendartype to be added to course. | |
2368 | $table = new xmldb_table('course'); | |
2369 | $field = new xmldb_field('calendartype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null); | |
2370 | ||
2371 | // Conditionally launch add field calendartype. | |
2372 | if (!$dbman->field_exists($table, $field)) { | |
2373 | $dbman->add_field($table, $field); | |
2374 | } | |
2375 | ||
2376 | // Define field calendartype to be added to user. | |
2377 | $table = new xmldb_table('user'); | |
2378 | $field = new xmldb_field('calendartype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, 'gregorian'); | |
2379 | ||
2380 | // Conditionally launch add field calendartype. | |
2381 | if (!$dbman->field_exists($table, $field)) { | |
2382 | $dbman->add_field($table, $field); | |
2383 | } | |
2384 | ||
2385 | // Main savepoint reached. | |
2386 | upgrade_main_savepoint(true, 2013090500.01); | |
2387 | } | |
2388 | ||
299cfee5 MG |
2389 | if ($oldversion < 2013091000.02) { |
2390 | ||
2391 | // Define field cacherev to be added to course. | |
2392 | $table = new xmldb_table('course'); | |
2393 | $field = new xmldb_field('cacherev', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'completionnotify'); | |
2394 | ||
2395 | // Conditionally launch add field cacherev. | |
2396 | if (!$dbman->field_exists($table, $field)) { | |
2397 | $dbman->add_field($table, $field); | |
2398 | } | |
2399 | ||
2400 | // Main savepoint reached. | |
2401 | upgrade_main_savepoint(true, 2013091000.02); | |
2402 | } | |
2403 | ||
64501eee MG |
2404 | if ($oldversion < 2013091000.03) { |
2405 | ||
2406 | // Define field modinfo to be dropped from course. | |
2407 | $table = new xmldb_table('course'); | |
2408 | $field = new xmldb_field('modinfo'); | |
2409 | ||
2410 | // Conditionally launch drop field modinfo. | |
2411 | if ($dbman->field_exists($table, $field)) { | |
2412 | $dbman->drop_field($table, $field); | |
2413 | } | |
2414 | ||
2415 | // Define field sectioncache to be dropped from course. | |
2416 | $field = new xmldb_field('sectioncache'); | |
2417 | ||
2418 | // Conditionally launch drop field sectioncache. | |
2419 | if ($dbman->field_exists($table, $field)) { | |
2420 | $dbman->drop_field($table, $field); | |
2421 | } | |
2422 | ||
2423 | // Main savepoint reached. | |
2424 | upgrade_main_savepoint(true, 2013091000.03); | |
2425 | } | |
2426 | ||
a8fd33b0 MG |
2427 | if ($oldversion < 2013091300.01) { |
2428 | ||
2429 | $table = new xmldb_table('user'); | |
2430 | ||
2431 | // Changing precision of field institution on table user to (255). | |
2432 | $field = new xmldb_field('institution', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'phone2'); | |
2433 | ||
2434 | // Launch change of precision for field institution. | |
2435 | $dbman->change_field_precision($table, $field); | |
2436 | ||
2437 | // Changing precision of field department on table user to (255). | |
2438 | $field = new xmldb_field('department', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'institution'); | |
2439 | ||
2440 | // Launch change of precision for field department. | |
2441 | $dbman->change_field_precision($table, $field); | |
2442 | ||
2443 | // Changing precision of field address on table user to (255). | |
2444 | $field = new xmldb_field('address', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'department'); | |
2445 | ||
2446 | // Launch change of precision for field address. | |
2447 | $dbman->change_field_precision($table, $field); | |
2448 | ||
2449 | // Main savepoint reached. | |
2450 | upgrade_main_savepoint(true, 2013091300.01); | |
2451 | } | |
2452 | ||
e68e4ccf JP |
2453 | if ($oldversion < 2013092000.01) { |
2454 | ||
2455 | // Define table question_statistics to be created. | |
2456 | $table = new xmldb_table('question_statistics'); | |
2457 | ||
2458 | // Adding fields to table question_statistics. | |
2459 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
2460 | $table->add_field('hashcode', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); | |
2461 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); | |
2462 | $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); | |
2463 | $table->add_field('slot', XMLDB_TYPE_INTEGER, '10', null, null, null, null); | |
2464 | $table->add_field('subquestion', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null); | |
2465 | $table->add_field('s', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); | |
2466 | $table->add_field('effectiveweight', XMLDB_TYPE_NUMBER, '15, 5', null, null, null, null); | |
2467 | $table->add_field('negcovar', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0'); | |
2468 | $table->add_field('discriminationindex', XMLDB_TYPE_NUMBER, '15, 5', null, null, null, null); | |
2469 | $table->add_field('discriminativeefficiency', XMLDB_TYPE_NUMBER, '15, 5', null, null, null, null); | |
2470 | $table->add_field('sd', XMLDB_TYPE_NUMBER, '15, 10', null, null, null, null); | |
2471 | $table->add_field('facility', XMLDB_TYPE_NUMBER, '15, 10', null, null, null, null); | |
2472 | $table->add_field('subquestions', XMLDB_TYPE_TEXT, null, null, null, null, null); | |
2473 | $table->add_field('maxmark', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null); | |
2474 | $table->add_field('positions', XMLDB_TYPE_TEXT, null, null, null, null, null); | |
2475 | $table->add_field('randomguessscore', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null); | |
2476 | ||
2477 | // Adding keys to table question_statistics. | |
2478 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2479 | ||
2480 | // Conditionally launch create table for question_statistics. | |
2481 | if (!$dbman->table_exists($table)) { | |
2482 | $dbman->create_table($table); | |
2483 | } | |
2484 | ||
2485 | // Define table question_response_analysis to be created. | |
2486 | $table = new xmldb_table('question_response_analysis'); | |
2487 | ||
2488 | // Adding fields to table question_response_analysis. | |
2489 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
2490 | $table->add_field('hashcode', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); | |
2491 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); | |
2492 | $table->add_field('questionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); | |
2493 | $table->add_field('subqid', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); | |
2494 | $table->add_field('aid', XMLDB_TYPE_CHAR, '100', null, null, null, null); | |
2495 | $table->add_field('response', XMLDB_TYPE_TEXT, null, null, null, null, null); | |
2496 | $table->add_field('rcount', XMLDB_TYPE_INTEGER, '10', null, null, null, null); | |
2497 | $table->add_field('credit', XMLDB_TYPE_NUMBER, '15, 5', null, XMLDB_NOTNULL, null, null); | |
2498 | ||
2499 | // Adding keys to table question_response_analysis. | |
2500 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2501 | ||
2502 | // Conditionally launch create table for question_response_analysis. | |
2503 | if (!$dbman->table_exists($table)) { | |
2504 | $dbman->create_table($table); | |
2505 | } | |
2506 | ||
2507 | // Main savepoint reached. | |
2508 | upgrade_main_savepoint(true, 2013092000.01); | |
2509 | } | |
2510 | ||
bde002b8 PS |
2511 | if ($oldversion < 2013092001.01) { |
2512 | // Force uninstall of deleted tool. | |
2513 | if (!file_exists("$CFG->dirroot/$CFG->admin/tool/bloglevelupgrade")) { | |
2514 | // Remove capabilities. | |
2515 | capabilities_cleanup('tool_bloglevelupgrade'); | |
2516 | // Remove all other associated config. | |
2517 | unset_all_config_for_plugin('tool_bloglevelupgrade'); | |
2518 | } | |
2519 | upgrade_main_savepoint(true, 2013092001.01); | |
2520 | } | |
2521 | ||
2522 | if ($oldversion < 2013092001.02) { | |
2523 | // Define field version to be dropped from modules. | |
2524 | $table = new xmldb_table('modules'); | |
2525 | $field = new xmldb_field('version'); | |
2526 | ||
2527 | // Conditionally launch drop field version. | |
2528 | if ($dbman->field_exists($table, $field)) { | |
2529 | // Migrate all plugin version info to config_plugins table. | |
2530 | $modules = $DB->get_records('modules'); | |
2531 | foreach ($modules as $module) { | |
2532 | set_config('version', $module->version, 'mod_'.$module->name); | |
2533 | } | |
2534 | unset($modules); | |
2535 | ||
2536 | $dbman->drop_field($table, $field); | |
2537 | } | |
2538 | ||
2539 | // Define field version to be dropped from block. | |
2540 | $table = new xmldb_table('block'); | |
2541 | $field = new xmldb_field('version'); | |
2542 | ||
2543 | // Conditionally launch drop field version. | |
2544 | if ($dbman->field_exists($table, $field)) { | |
2545 | $blocks = $DB->get_records('block'); | |
2546 | foreach ($blocks as $block) { | |
2547 | set_config('version', $block->version, 'block_'.$block->name); | |
2548 | } | |
2549 | unset($blocks); | |
2550 | ||
2551 | $dbman->drop_field($table, $field); | |
2552 | } | |
2553 | ||
2554 | // Main savepoint reached. | |
2555 | upgrade_main_savepoint(true, 2013092001.02); | |
2556 | } | |
2557 | ||
a4cdd6d2 | 2558 | return true; |
51003653 | 2559 | } |