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, |
17 | // using the functions defined in lib/ddllib.php |
18 | |
19 | |
20 | function xmldb_main_upgrade($oldversion=0) { |
21 | |
f33e1ed4 |
22 | global $CFG, $THEME, $USER, $DB; |
4e423cbf |
23 | |
24 | $result = true; |
25 | |
f33e1ed4 |
26 | $dbman = $DB->get_manager(); // loads XSMLDB classes too |
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'); |
36 | $index = new xmldb_index('contextid-lowerboundary'); |
a1f27717 |
37 | $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary')); |
38 | |
39 | /// Launch drop index contextid-lowerboundary |
f33e1ed4 |
40 | $result = $result && $dbman->drop_index($table, $index); |
a1f27717 |
41 | |
a1f27717 |
42 | /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters |
a8cb94f6 |
43 | $table = new xmldb_table('grade_letters'); |
44 | $index = new xmldb_index('contextid-lowerboundary-letter'); |
a1f27717 |
45 | $index->setAttributes(XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter')); |
46 | |
47 | /// Launch add index contextid-lowerboundary-letter |
f33e1ed4 |
48 | $result = $result && $dbman->add_index($table, $index); |
a1f27717 |
49 | |
50 | /// Main savepoint reached |
0f77b186 |
51 | upgrade_main_savepoint($result, 2008030700); |
52 | } |
a1f27717 |
53 | |
1ea260d8 |
54 | if ($result && $oldversion < 2008050100) { |
55 | // Update courses that used weekscss to weeks |
a8cb94f6 |
56 | $result = $DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss')); |
1ea260d8 |
57 | upgrade_main_savepoint($result, 2008050100); |
58 | } |
59 | |
0b51c247 |
60 | if ($result && $oldversion < 2008050200) { |
61 | // remove unused config options |
62 | unset_config('statsrolesupgraded'); |
63 | upgrade_main_savepoint($result, 2008050200); |
64 | } |
65 | |
994fbaab |
66 | if ($result && $oldversion < 2008050700) { |
67 | /// Fix minor problem caused by MDL-5482. |
68 | require_once($CFG->dirroot . '/question/upgrade.php'); |
69 | $result = $result && question_fix_random_question_parents(); |
70 | upgrade_main_savepoint($result, 2008050700); |
71 | } |
72 | |
ab37dc60 |
73 | if ($result && $oldversion < 2008051200) { |
74 | // if guest role used as default user role unset it and force admin to choose new setting |
75 | if (!empty($CFG->defaultuserroleid)) { |
76 | if ($role = get_record('role', 'id', $CFG->defaultuserroleid)) { |
77 | if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) { |
78 | if (isset($guestroles[$role->id])) { |
79 | set_config('defaultuserroleid', null); |
80 | notify('Guest role removed from "Default role for all users" setting, please select another role.', 'notifysuccess'); |
81 | } |
82 | } |
83 | } else { |
84 | set_config('defaultuserroleid', null); |
85 | } |
86 | } |
87 | } |
88 | |
8b9cfac4 |
89 | if ($result && $oldversion < 2008051201) { |
90 | notify('Increasing size of user idnumber field, this may take a while...', 'notifysuccess'); |
91 | |
469dcbcc |
92 | /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859 |
93 | if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') { |
94 | execute_sql("UPDATE {$CFG->prefix}user SET idnumber = '' WHERE idnumber IS NULL", true); |
95 | } |
96 | |
8b9cfac4 |
97 | /// Define index idnumber (not unique) to be dropped form user |
a8cb94f6 |
98 | $table = new xmldb_table('user'); |
99 | $index = new xmldb_index('idnumber'); |
8b9cfac4 |
100 | $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('idnumber')); |
101 | |
102 | /// Launch drop index idnumber |
f33e1ed4 |
103 | if ($dbman->index_exists($table, $index)) { |
104 | $result = $result && $dbman->drop_index($table, $index); |
8b9cfac4 |
105 | } |
106 | |
107 | /// Changing precision of field idnumber on table user to (255) |
a8cb94f6 |
108 | $table = new xmldb_table('user'); |
109 | $field = new xmldb_field('idnumber'); |
8b9cfac4 |
110 | $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'password'); |
111 | |
112 | /// Launch change of precision for field idnumber |
f33e1ed4 |
113 | $result = $result && $dbman->change_field_precision($table, $field); |
8b9cfac4 |
114 | |
115 | /// Launch add index idnumber again |
a8cb94f6 |
116 | $index = new xmldb_index('idnumber'); |
8b9cfac4 |
117 | $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('idnumber')); |
f33e1ed4 |
118 | $result = $result && $dbman->add_index($table, $index); |
8b9cfac4 |
119 | |
120 | /// Main savepoint reached |
121 | upgrade_main_savepoint($result, 2008051201); |
122 | } |
123 | |
7ade55ad |
124 | if ($result && $oldversion < 2008051202) { |
125 | $log_action = new stdClass(); |
126 | $log_action->module = 'course'; |
127 | $log_action->action = 'unenrol'; |
128 | $log_action->mtable = 'course'; |
129 | $log_action->field = 'fullname'; |
130 | if (!record_exists("log_display", "action", "unenrol", |
131 | "module", "course")){ |
132 | $result = $result && insert_record('log_display', $log_action); |
133 | } |
134 | upgrade_main_savepoint($result, 2008051202); |
135 | } |
136 | |
f33e1ed4 |
137 | /* |
138 | * TODO: |
139 | * drop adodb_logsql table and create a ner general sql log table |
140 | * |
141 | */ |
142 | |
ac9b0805 |
143 | return $result; |
4e423cbf |
144 | } |
271e6dec |
145 | |
146 | |
4e423cbf |
147 | ?> |