Commit | Line | Data |
---|---|---|
5b4a78e2 | 1 | <?php |
4e423cbf | 2 | |
5b4a78e2 | 3 | // This file is part of Moodle - http://moodle.org/ |
4e423cbf | 4 | // |
5b4a78e2 PS |
5 | // Moodle is free software: you can redistribute it and/or modify |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
4e423cbf | 9 | // |
5b4a78e2 PS |
10 | // Moodle is distributed in the hope that it will be useful, |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
4e423cbf | 14 | // |
5b4a78e2 PS |
15 | // You should have received a copy of the GNU General Public License |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * This file keeps track of upgrades to Moodle. | |
20 | * | |
21 | * Sometimes, changes between versions involve | |
22 | * alterations to database structures and other | |
23 | * major things that may break installations. | |
24 | * | |
25 | * The upgrade function in this file will attempt | |
26 | * to perform all the necessary actions to upgrade | |
27 | * your older installation to the current version. | |
28 | * | |
29 | * If there's something it cannot do itself, it | |
30 | * will tell you what you need to do. | |
31 | * | |
32 | * The commands in here will all be database-neutral, | |
33 | * using the methods of database_manager class | |
34 | * | |
35 | * Please do not forget to use upgrade_set_timeout() | |
36 | * before any action that may take longer time to finish. | |
37 | * | |
38 | * @package core | |
39 | * @subpackage admin | |
40 | * @copyright 2006 onwards Martin Dougiamas http://dougiamas.com | |
41 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
42 | */ | |
43 | ||
44 | defined('MOODLE_INTERNAL') || die(); | |
4e423cbf | 45 | |
3406acde SH |
46 | /** |
47 | * | |
48 | * @global stdClass $CFG | |
49 | * @global stdClass $USER | |
50 | * @global moodle_database $DB | |
51 | * @global core_renderer $OUTPUT | |
52 | * @param int $oldversion | |
5b4a78e2 | 53 | * @return bool always true |
3406acde | 54 | */ |
775f811a | 55 | function xmldb_main_upgrade($oldversion) { |
78946b9b | 56 | global $CFG, $USER, $DB, $OUTPUT; |
4e423cbf | 57 | |
4f12838e | 58 | require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions |
13a0d3d3 | 59 | |
46d318bc | 60 | $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes |
f33e1ed4 | 61 | |
5c79b8ed PS |
62 | if ($oldversion < 2011120500) { |
63 | // just in case somebody hacks upgrade scripts or env, we really can not continue | |
64 | echo("You need to upgrade to 2.2.x first!\n"); | |
65 | exit(1); | |
66 | } | |
67 | ||
1ea260d8 | 68 | //////////////////////////////////////// |
2e210163 | 69 | ///upgrade supported only from 2.2.x /// |
1ea260d8 | 70 | //////////////////////////////////////// |
da4aa3e4 | 71 | |
43cf3165 EL |
72 | if ($oldversion < 2011120500.02) { |
73 | ||
74 | upgrade_set_timeout(60*20); // This may take a while | |
75 | // MDL-28180. Some missing restrictions in certain backup & restore operations | |
76 | // were causing incorrect duplicates in the course_completion_aggr_methd table. | |
77 | // This upgrade step takes rid of them. | |
78 | $sql = 'SELECT course, criteriatype, MIN(id) AS minid | |
79 | FROM {course_completion_aggr_methd} | |
80 | GROUP BY course, criteriatype | |
81 | HAVING COUNT(*) > 1'; | |
82 | $duprs = $DB->get_recordset_sql($sql); | |
83 | foreach ($duprs as $duprec) { | |
84 | // We need to handle NULLs in criteriatype diferently | |
85 | if (is_null($duprec->criteriatype)) { | |
86 | $where = 'course = ? AND criteriatype IS NULL AND id > ?'; | |
87 | $params = array($duprec->course, $duprec->minid); | |
88 | } else { | |
89 | $where = 'course = ? AND criteriatype = ? AND id > ?'; | |
90 | $params = array($duprec->course, $duprec->criteriatype, $duprec->minid); | |
91 | } | |
92 | $DB->delete_records_select('course_completion_aggr_methd', $where, $params); | |
93 | } | |
94 | $duprs->close(); | |
95 | ||
96 | // Main savepoint reached | |
97 | upgrade_main_savepoint(true, 2011120500.02); | |
98 | } | |
99 | ||
52a23063 | 100 | if ($oldversion < 2011120500.03) { |
8e54ce97 AD |
101 | |
102 | // Changing precision of field value on table user_preferences to (1333) | |
103 | $table = new xmldb_table('user_preferences'); | |
104 | $field = new xmldb_field('value', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'name'); | |
105 | ||
106 | // Launch change of precision for field value | |
107 | $dbman->change_field_precision($table, $field); | |
108 | ||
109 | // Main savepoint reached | |
52a23063 | 110 | upgrade_main_savepoint(true, 2011120500.03); |
8e54ce97 AD |
111 | } |
112 | ||
a4cdd6d2 | 113 | return true; |
4e423cbf | 114 | } |
271e6dec | 115 |