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