4e423cbf |
1 | <?PHP //$Id$ |
2 | |
3 | // This file keeps track of upgrades to Moodle. |
4 | // |
5 | // Sometimes, changes between versions involve |
6 | // alterations to database structures and other |
7 | // major things that may break installations. |
8 | // |
9 | // The upgrade function in this file will attempt |
10 | // to perform all the necessary actions to upgrade |
11 | // your older installtion to the current version. |
12 | // |
13 | // If there's something it cannot do itself, it |
14 | // will tell you what you need to do. |
15 | // |
16 | // The commands in here will all be database-neutral, |
b1f93b15 |
17 | // using the methods of database_manager class |
775f811a |
18 | // |
19 | // Please do not forget to use upgrade_set_timeout() |
20 | // before any action that may take longer time to finish. |
4e423cbf |
21 | |
775f811a |
22 | function xmldb_main_upgrade($oldversion) { |
f33e1ed4 |
23 | global $CFG, $THEME, $USER, $DB; |
4e423cbf |
24 | |
25 | $result = true; |
26 | |
46d318bc |
27 | $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes |
f33e1ed4 |
28 | |
1ea260d8 |
29 | //////////////////////////////////////// |
30 | ///upgrade supported only from 1.9.x /// |
31 | //////////////////////////////////////// |
da4aa3e4 |
32 | |
a1f27717 |
33 | if ($result && $oldversion < 2008030700) { |
775f811a |
34 | upgrade_set_timeout(60*20); // this may take a while |
a1f27717 |
35 | |
36 | /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters |
a8cb94f6 |
37 | $table = new xmldb_table('grade_letters'); |
69b80cc2 |
38 | $index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary')); |
a1f27717 |
39 | |
40 | /// Launch drop index contextid-lowerboundary |
eee5d9bb |
41 | $dbman->drop_index($table, $index); |
a1f27717 |
42 | |
a1f27717 |
43 | /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters |
a8cb94f6 |
44 | $table = new xmldb_table('grade_letters'); |
69b80cc2 |
45 | $index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter')); |
a1f27717 |
46 | |
47 | /// Launch add index contextid-lowerboundary-letter |
eee5d9bb |
48 | $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) { |
775f811a |
67 | upgrade_set_timeout(60*20); // this may take a while |
68 | |
994fbaab |
69 | /// Fix minor problem caused by MDL-5482. |
70 | require_once($CFG->dirroot . '/question/upgrade.php'); |
71 | $result = $result && question_fix_random_question_parents(); |
72 | upgrade_main_savepoint($result, 2008050700); |
73 | } |
74 | |
ab37dc60 |
75 | if ($result && $oldversion < 2008051200) { |
76 | // if guest role used as default user role unset it and force admin to choose new setting |
77 | if (!empty($CFG->defaultuserroleid)) { |
910dd4dd |
78 | if ($role = $DB->get_record('role', array('id'=>$CFG->defaultuserroleid))) { |
ab37dc60 |
79 | if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) { |
80 | if (isset($guestroles[$role->id])) { |
81 | set_config('defaultuserroleid', null); |
82 | notify('Guest role removed from "Default role for all users" setting, please select another role.', 'notifysuccess'); |
83 | } |
84 | } |
85 | } else { |
86 | set_config('defaultuserroleid', null); |
87 | } |
88 | } |
89 | } |
90 | |
8b9cfac4 |
91 | if ($result && $oldversion < 2008051201) { |
92 | notify('Increasing size of user idnumber field, this may take a while...', 'notifysuccess'); |
775f811a |
93 | upgrade_set_timeout(60*20); // this may take a while |
8b9cfac4 |
94 | |
469dcbcc |
95 | /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859 |
cbc08f3b |
96 | $dbfamily = $DB->get_dbfamily(); |
97 | if ($dbfamily === 'mysql' || $dbfamily === 'postgres') { |
eee5d9bb |
98 | $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL"); |
469dcbcc |
99 | } |
100 | |
8b9cfac4 |
101 | /// Define index idnumber (not unique) to be dropped form user |
a8cb94f6 |
102 | $table = new xmldb_table('user'); |
69b80cc2 |
103 | $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber')); |
8b9cfac4 |
104 | |
105 | /// Launch drop index idnumber |
f33e1ed4 |
106 | if ($dbman->index_exists($table, $index)) { |
eee5d9bb |
107 | $dbman->drop_index($table, $index); |
8b9cfac4 |
108 | } |
109 | |
110 | /// Changing precision of field idnumber on table user to (255) |
a8cb94f6 |
111 | $table = new xmldb_table('user'); |
69b80cc2 |
112 | $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'password'); |
8b9cfac4 |
113 | |
114 | /// Launch change of precision for field idnumber |
eee5d9bb |
115 | $dbman->change_field_precision($table, $field); |
8b9cfac4 |
116 | |
117 | /// Launch add index idnumber again |
69b80cc2 |
118 | $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber')); |
eee5d9bb |
119 | $dbman->add_index($table, $index); |
8b9cfac4 |
120 | |
121 | /// Main savepoint reached |
122 | upgrade_main_savepoint($result, 2008051201); |
123 | } |
124 | |
7ade55ad |
125 | if ($result && $oldversion < 2008051202) { |
910dd4dd |
126 | $log_action = new object(); |
7ade55ad |
127 | $log_action->module = 'course'; |
128 | $log_action->action = 'unenrol'; |
129 | $log_action->mtable = 'course'; |
130 | $log_action->field = 'fullname'; |
910dd4dd |
131 | if (!$DB->record_exists('log_display', array('action'=>'unenrol', 'module'=>'course'))) { |
132 | $result = $result && $DB->insert_record('log_display', $log_action); |
7ade55ad |
133 | } |
134 | upgrade_main_savepoint($result, 2008051202); |
135 | } |
136 | |
fa162144 |
137 | if ($result && $oldversion < 2008051203) { |
138 | $table = new xmldb_table('mnet_enrol_course'); |
139 | $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', true, true, null, false, false, 0); |
eee5d9bb |
140 | $dbman->change_field_precision($table, $field); |
fa162144 |
141 | upgrade_main_savepoint($result, 2008051203); |
142 | } |
143 | |
38fb8190 |
144 | if ($result && $oldversion < 2008063001) { |
775f811a |
145 | upgrade_set_timeout(60*20); // this may take a while |
146 | |
38fb8190 |
147 | // table to be modified |
148 | $table = new xmldb_table('tag_instance'); |
149 | // add field |
150 | $field = new xmldb_field('tiuserid'); |
151 | if (!$dbman->field_exists($table, $field)) { |
152 | $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0, 'itemid'); |
153 | $dbman->add_field($table, $field); |
154 | } |
155 | // modify index |
156 | $index = new xmldb_index('itemtype-itemid-tagid'); |
157 | $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid')); |
b91de8a5 |
158 | if ($dbman->index_exists($table, $index)) { |
159 | $dbman->drop_index($table, $index); |
160 | } |
38fb8190 |
161 | $index = new xmldb_index('itemtype-itemid-tagid-tiuserid'); |
162 | $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid')); |
b91de8a5 |
163 | if (!$dbman->index_exists($table, $index)) { |
164 | $dbman->add_index($table, $index); |
165 | } |
38fb8190 |
166 | |
167 | /// Main savepoint reached |
168 | upgrade_main_savepoint($result, 2008063001); |
169 | } |
38fb8190 |
170 | |
a036d7f3 |
171 | if ($result && $oldversion < 2008070300) { |
172 | $result = $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false)); |
173 | upgrade_main_savepoint($result, 2008070300); |
174 | } |
4e781c7b |
175 | |
fe074586 |
176 | if ($result && $oldversion < 2008070700) { |
177 | if (isset($CFG->defaultuserroleid) and isset($CFG->guestroleid) and $CFG->defaultuserroleid == $CFG->guestroleid) { |
178 | // guest can not be selected in defaultuserroleid! |
179 | unset_config('defaultuserroleid'); |
180 | } |
181 | upgrade_main_savepoint($result, 2008070700); |
182 | } |
183 | |
ac5efef6 |
184 | if ($result && $oldversion < 2008070701) { |
185 | |
186 | /// Define table portfolio_instance to be created |
187 | $table = new xmldb_table('portfolio_instance'); |
188 | |
189 | /// Adding fields to table portfolio_instance |
190 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
191 | $table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null); |
192 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
193 | $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1'); |
194 | |
195 | /// Adding keys to table portfolio_instance |
196 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
197 | |
198 | /// Conditionally launch create table for portfolio_instance |
199 | if (!$dbman->table_exists($table)) { |
200 | $dbman->create_table($table); |
201 | } |
202 | /// Define table portfolio_instance_config to be created |
203 | $table = new xmldb_table('portfolio_instance_config'); |
204 | |
205 | /// Adding fields to table portfolio_instance_config |
206 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
207 | $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
208 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
209 | $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); |
210 | |
211 | /// Adding keys to table portfolio_instance_config |
212 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
213 | $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id')); |
214 | |
215 | /// Adding indexes to table portfolio_instance_config |
216 | $table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name')); |
217 | |
218 | /// Conditionally launch create table for portfolio_instance_config |
219 | if (!$dbman->table_exists($table)) { |
220 | $dbman->create_table($table); |
221 | } |
222 | |
223 | /// Define table portfolio_instance_user to be created |
224 | $table = new xmldb_table('portfolio_instance_user'); |
225 | |
226 | /// Adding fields to table portfolio_instance_user |
227 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
228 | $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
229 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
230 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
231 | $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); |
232 | |
233 | /// Adding keys to table portfolio_instance_user |
234 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
235 | $table->add_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id')); |
236 | $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
237 | |
238 | /// Conditionally launch create table for portfolio_instance_user |
239 | if (!$dbman->table_exists($table)) { |
240 | $dbman->create_table($table); |
241 | } |
242 | |
243 | /// Main savepoint reached |
244 | upgrade_main_savepoint($result, 2008070701); |
245 | } |
172dd12c |
246 | |
775f811a |
247 | if ($result && $oldversion < 2008072400) { |
248 | /// Create the database tables for message_processors |
f65b2dae |
249 | $table = new xmldb_table('message_processors'); |
250 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
251 | $table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null); |
252 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
3b120e46 |
253 | $dbman->create_table($table); |
254 | |
3b120e46 |
255 | /// delete old and create new fields |
f65b2dae |
256 | $table = new xmldb_table('message'); |
257 | $field = new xmldb_field('messagetype'); |
3b120e46 |
258 | $dbman->drop_field($table, $field); |
259 | |
260 | /// fields to rename |
f65b2dae |
261 | $field = new xmldb_field('message'); |
262 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null); |
3b120e46 |
263 | $dbman->rename_field($table, $field, 'fullmessage'); |
f65b2dae |
264 | $field = new xmldb_field('format'); |
265 | $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '0', null); |
3b120e46 |
266 | $dbman->rename_field($table, $field, 'fullmessageformat'); |
267 | |
268 | /// new message fields |
f65b2dae |
269 | $field = new xmldb_field('subject'); |
270 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null); |
3b120e46 |
271 | $dbman->add_field($table, $field); |
f65b2dae |
272 | $field = new xmldb_field('fullmessagehtml'); |
273 | $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, null); |
3b120e46 |
274 | $dbman->add_field($table, $field); |
f65b2dae |
275 | $field = new xmldb_field('smallmessage'); |
276 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null); |
3b120e46 |
277 | $dbman->add_field($table, $field); |
278 | |
279 | |
f65b2dae |
280 | $table = new xmldb_table('message_read'); |
281 | $field = new xmldb_field('messagetype'); |
3b120e46 |
282 | $dbman->drop_field($table, $field); |
f65b2dae |
283 | $field = new xmldb_field('mailed'); |
3b120e46 |
284 | $dbman->drop_field($table, $field); |
285 | |
286 | /// fields to rename |
f65b2dae |
287 | $field = new xmldb_field('message'); |
288 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null); |
3b120e46 |
289 | $dbman->rename_field($table, $field, 'fullmessage'); |
f65b2dae |
290 | $field = new xmldb_field('format'); |
291 | $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '0', null); |
3b120e46 |
292 | $dbman->rename_field($table, $field, 'fullmessageformat'); |
293 | |
294 | |
295 | /// new message fields |
f65b2dae |
296 | $field = new xmldb_field('subject'); |
297 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null); |
3b120e46 |
298 | $dbman->add_field($table, $field); |
f65b2dae |
299 | $field = new xmldb_field('fullmessagehtml'); |
300 | $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, null); |
3b120e46 |
301 | $dbman->add_field($table, $field); |
f65b2dae |
302 | $field = new xmldb_field('smallmessage'); |
303 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null); |
3b120e46 |
304 | $dbman->add_field($table, $field); |
305 | |
306 | /// new table |
f65b2dae |
307 | $table = new xmldb_table('message_working'); |
308 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
309 | $table->add_field('unreadmessageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
310 | $table->add_field('processorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
311 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
3b120e46 |
312 | $dbman->create_table($table); |
313 | |
314 | |
315 | upgrade_main_savepoint($result, 2008072400); |
316 | } |
317 | |
4e781c7b |
318 | if ($result && $oldversion < 2008072800) { |
319 | |
320 | /// Define field enablecompletion to be added to course |
321 | $table = new xmldb_table('course'); |
322 | $field = new xmldb_field('enablecompletion'); |
323 | $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'defaultrole'); |
324 | |
325 | /// Launch add field enablecompletion |
775f811a |
326 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
327 | $dbman->add_field($table, $field); |
328 | } |
775f811a |
329 | |
4e781c7b |
330 | /// Define field completion to be added to course_modules |
331 | $table = new xmldb_table('course_modules'); |
332 | $field = new xmldb_field('completion'); |
333 | $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'groupmembersonly'); |
334 | |
335 | /// Launch add field completion |
775f811a |
336 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
337 | $dbman->add_field($table, $field); |
338 | } |
339 | |
340 | /// Define field completiongradeitemnumber to be added to course_modules |
341 | $field = new xmldb_field('completiongradeitemnumber'); |
342 | $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'completion'); |
343 | |
344 | /// Launch add field completiongradeitemnumber |
775f811a |
345 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
346 | $dbman->add_field($table, $field); |
347 | } |
348 | |
349 | /// Define field completionview to be added to course_modules |
350 | $field = new xmldb_field('completionview'); |
351 | $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completiongradeitemnumber'); |
352 | |
353 | /// Launch add field completionview |
775f811a |
354 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
355 | $dbman->add_field($table, $field); |
356 | } |
357 | |
358 | /// Define field completionexpected to be added to course_modules |
359 | $field = new xmldb_field('completionexpected'); |
360 | $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionview'); |
361 | |
362 | /// Launch add field completionexpected |
775f811a |
363 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b |
364 | $dbman->add_field($table, $field); |
365 | } |
366 | |
367 | /// Define table course_modules_completion to be created |
368 | $table = new xmldb_table('course_modules_completion'); |
775f811a |
369 | if (!$dbman->table_exists($table)) { |
4e781c7b |
370 | |
371 | /// Adding fields to table course_modules_completion |
1e0c56ea |
372 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
373 | $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
374 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
375 | $table->add_field('completionstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
376 | $table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null); |
377 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
775f811a |
378 | |
4e781c7b |
379 | /// Adding keys to table course_modules_completion |
1e0c56ea |
380 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
775f811a |
381 | |
4e781c7b |
382 | /// Adding indexes to table course_modules_completion |
1e0c56ea |
383 | $table->add_index('coursemoduleid', XMLDB_INDEX_NOTUNIQUE, array('coursemoduleid')); |
384 | $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); |
775f811a |
385 | |
4e781c7b |
386 | /// Launch create table for course_modules_completion |
387 | $dbman->create_table($table); |
388 | } |
389 | |
390 | /// Main savepoint reached |
391 | upgrade_main_savepoint($result, 2008072800); |
392 | } |
775f811a |
393 | |
4ab16a09 |
394 | if ($result && $oldversion < 2008073000) { |
ac5efef6 |
395 | |
4ab16a09 |
396 | /// Define table portfolio_log to be created |
397 | $table = new xmldb_table('portfolio_log'); |
398 | |
399 | /// Adding fields to table portfolio_log |
400 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
401 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
402 | $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
403 | $table->add_field('portfolio', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
404 | $table->add_field('caller_class', XMLDB_TYPE_CHAR, '150', null, XMLDB_NOTNULL, null, null, null, null); |
405 | $table->add_field('caller_file', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
406 | $table->add_field('caller_sha1', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
407 | |
408 | /// Adding keys to table portfolio_log |
409 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
410 | $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
411 | $table->add_key('portfoliofk', XMLDB_KEY_FOREIGN, array('portfolio'), 'portfolio_instance', array('id')); |
412 | |
413 | /// Conditionally launch create table for portfolio_log |
414 | if (!$dbman->table_exists($table)) { |
415 | $dbman->create_table($table); |
416 | } |
417 | |
418 | /// Main savepoint reached |
419 | upgrade_main_savepoint($result, 2008073000); |
420 | } |
120b3758 |
421 | |
422 | if ($result && $oldversion < 2008073104) { |
423 | /// Drop old table that might exist for some people |
424 | $table = new xmldb_table('message_providers'); |
425 | if ($dbman->table_exists($table)) { |
426 | $dbman->drop_table($table); |
427 | } |
428 | |
429 | /// Define table message_providers to be created |
430 | $table = new xmldb_table('message_providers'); |
431 | |
432 | /// Adding fields to table message_providers |
433 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
434 | $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null); |
435 | $table->add_field('component', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null, null, null); |
436 | $table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); |
437 | |
438 | /// Adding keys to table message_providers |
439 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
440 | |
441 | /// Adding indexes to table message_providers |
442 | $table->add_index('componentname', XMLDB_INDEX_UNIQUE, array('component', 'name')); |
443 | |
444 | /// Create table for message_providers |
445 | $dbman->create_table($table); |
446 | |
447 | upgrade_main_savepoint($result, 2008073104); |
448 | } |
172dd12c |
449 | |
450 | if ($result && $oldversion < 2008073111) { |
451 | /// Define table files to be created |
452 | $table = new xmldb_table('files'); |
453 | |
454 | /// Adding fields to table files |
455 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
456 | $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null); |
457 | $table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null); |
458 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
459 | $table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null); |
460 | $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
461 | $table->add_field('filepath', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
462 | $table->add_field('filename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
463 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); |
464 | $table->add_field('filesize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
465 | $table->add_field('mimetype', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null); |
466 | $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); |
467 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
468 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
469 | |
470 | /// Adding keys to table files |
471 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
472 | $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); |
473 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
474 | |
475 | /// Adding indexes to table files |
476 | $table->add_index('filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('filearea', 'contextid', 'itemid')); |
477 | $table->add_index('contenthash', XMLDB_INDEX_NOTUNIQUE, array('contenthash')); |
478 | $table->add_index('pathnamehash', XMLDB_INDEX_UNIQUE, array('pathnamehash')); |
479 | |
480 | /// Conditionally launch create table for files |
481 | $dbman->create_table($table); |
482 | |
483 | /// Main savepoint reached |
484 | upgrade_main_savepoint($result, 2008073111); |
485 | } |
486 | |
487 | if ($result && $oldversion < 2008073112) { |
488 | /// Define table files_cleanup to be created |
489 | $table = new xmldb_table('files_cleanup'); |
490 | |
491 | /// Adding fields to table files_cleanup |
492 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
493 | $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null); |
494 | |
495 | /// Adding keys to table files_cleanup |
496 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
497 | |
498 | /// Adding indexes to table files_cleanup |
499 | $table->add_index('contenthash', XMLDB_INDEX_UNIQUE, array('contenthash')); |
500 | |
501 | /// Conditionally launch create table for files_cleanup |
502 | $dbman->create_table($table); |
503 | |
504 | /// Main savepoint reached |
505 | upgrade_main_savepoint($result, 2008073112); |
506 | } |
507 | |
508 | if ($result && $oldversion < 2008073113) { |
509 | /// move all course, backup and other files to new filepool based storage |
510 | upgrade_migrate_files_courses(); |
511 | /// Main savepoint reached |
512 | upgrade_main_savepoint($result, 2008073113); |
513 | } |
514 | |
515 | if ($result && $oldversion < 2008073114) { |
516 | /// move all course, backup and other files to new filepool based storage |
517 | upgrade_migrate_files_blog(); |
518 | /// Main savepoint reached |
519 | upgrade_main_savepoint($result, 2008073114); |
520 | } |
f33e1ed4 |
521 | |
1ce2da58 |
522 | if ($result && $oldversion < 2008080400) { |
523 | // Add field ssl_jump_url to mnet application, and populate existing default applications |
524 | $table = new xmldb_table('mnet_application'); |
525 | $field = new xmldb_field('sso_jump_url'); |
526 | if (!$dbman->field_exists($table, $field)) { |
527 | $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
c5a04d12 |
528 | $dbman->add_field($table, $field); |
529 | $result = $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle')); |
1ce2da58 |
530 | $result = $result && $DB->set_field('mnet_application', 'sso_jump_url', '/auth/xmlrpc/jump.php', array('name' => 'mahara')); |
531 | } |
532 | |
533 | /// Main savepoint reached |
534 | upgrade_main_savepoint($result, 2008080400); |
535 | } |
04f35360 |
536 | |
537 | if ($result && $oldversion < 2008080500) { |
538 | |
539 | /// Define table portfolio_tempdata to be created |
540 | $table = new xmldb_table('portfolio_tempdata'); |
541 | |
542 | /// Adding fields to table portfolio_tempdata |
543 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
544 | $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); |
545 | |
546 | /// Adding keys to table portfolio_tempdata |
547 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
548 | |
549 | /// Conditionally launch create table for portfolio_tempdata |
550 | if (!$dbman->table_exists($table)) { |
551 | $dbman->create_table($table); |
552 | } |
553 | |
554 | /// Main savepoint reached |
555 | upgrade_main_savepoint($result, 2008080500); |
556 | } |
557 | |
84a44985 |
558 | if ($result && $oldversion < 2008080600) { |
559 | |
560 | $DB->delete_records('portfolio_tempdata'); // there shouldnt' be any, and it will cause problems with this upgrade. |
561 | /// Define field expirytime to be added to portfolio_tempdata |
562 | $table = new xmldb_table('portfolio_tempdata'); |
563 | $field = new xmldb_field('expirytime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'data'); |
564 | |
565 | /// Conditionally launch add field expirytime |
566 | if (!$dbman->field_exists($table, $field)) { |
567 | $dbman->add_field($table, $field); |
568 | } |
569 | |
570 | /// Main savepoint reached |
571 | upgrade_main_savepoint($result, 2008080600); |
572 | } |
775f811a |
573 | |
f9a2cf86 |
574 | /// Changing the type of all the columns that the question bank uses to store grades to be NUMBER(12, 7). |
575 | if ($result && $oldversion < 2008081500) { |
576 | $table = new xmldb_table('question'); |
577 | $field = new xmldb_field('defaultgrade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'generalfeedback'); |
578 | $dbman->change_field_type($table, $field); |
579 | upgrade_main_savepoint($result, 2008081500); |
580 | } |
581 | |
582 | if ($result && $oldversion < 2008081501) { |
583 | $table = new xmldb_table('question'); |
584 | $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'defaultgrade'); |
585 | $dbman->change_field_type($table, $field); |
586 | upgrade_main_savepoint($result, 2008081501); |
587 | } |
588 | |
589 | if ($result && $oldversion < 2008081502) { |
590 | $table = new xmldb_table('question_answers'); |
591 | $field = new xmldb_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'answer'); |
592 | $dbman->change_field_type($table, $field); |
593 | upgrade_main_savepoint($result, 2008081502); |
594 | } |
595 | |
596 | if ($result && $oldversion < 2008081503) { |
597 | $table = new xmldb_table('question_sessions'); |
598 | $field = new xmldb_field('sumpenalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'newgraded'); |
599 | $dbman->change_field_type($table, $field); |
600 | upgrade_main_savepoint($result, 2008081503); |
601 | } |
602 | |
603 | if ($result && $oldversion < 2008081504) { |
604 | $table = new xmldb_table('question_states'); |
605 | $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'event'); |
606 | $dbman->change_field_type($table, $field); |
607 | upgrade_main_savepoint($result, 2008081504); |
608 | } |
609 | |
610 | if ($result && $oldversion < 2008081505) { |
611 | $table = new xmldb_table('question_states'); |
612 | $field = new xmldb_field('raw_grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'grade'); |
613 | $dbman->change_field_type($table, $field); |
614 | upgrade_main_savepoint($result, 2008081505); |
615 | } |
616 | |
617 | if ($result && $oldversion < 2008081506) { |
618 | $table = new xmldb_table('question_states'); |
619 | $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'raw_grade'); |
620 | $dbman->change_field_type($table, $field); |
621 | upgrade_main_savepoint($result, 2008081506); |
622 | } |
623 | |
775f811a |
624 | if ($result && $oldversion < 2008081600) { |
625 | |
626 | /// all 1.9 sites and fresh installs must already be unicode, not needed anymore |
627 | unset_config('unicodedb'); |
628 | |
629 | /// Main savepoint reached |
630 | upgrade_main_savepoint($result, 2008081600); |
631 | } |
632 | |
ff2f69bc |
633 | if ($result && $oldversion < 2008081900) { |
634 | /// Define field userid to be added to portfolio_tempdata |
635 | $table = new xmldb_table('portfolio_tempdata'); |
636 | $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'expirytime'); |
637 | |
638 | /// Conditionally launch add field userid |
639 | if (!$dbman->field_exists($table, $field)) { |
640 | $dbman->add_field($table, $field); |
641 | } |
642 | $DB->set_field('portfolio_tempdata', 'userid', 0); |
643 | /// now change it to be notnull |
644 | |
645 | /// Changing nullability of field userid on table portfolio_tempdata to not null |
646 | $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'expirytime'); |
647 | |
648 | /// Launch change of nullability for field userid |
649 | $dbman->change_field_notnull($table, $field); |
650 | |
651 | /// Define key userfk (foreign) to be added to portfolio_tempdata |
652 | $table = new xmldb_table('portfolio_tempdata'); |
653 | $key = new xmldb_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); |
654 | |
655 | /// Launch add key userfk |
656 | $dbman->add_key($table, $key); |
657 | |
658 | upgrade_main_savepoint($result, 2008081900); |
659 | } |
8f3f6cc3 |
660 | if ($result && $oldversion < 2008082602) { |
27051e43 |
661 | |
662 | /// Define table repository to be dropped |
663 | $table = new xmldb_table('repository'); |
664 | |
665 | /// Conditionally launch drop table for repository |
666 | if ($dbman->table_exists($table)) { |
667 | $dbman->drop_table($table); |
668 | } |
669 | |
670 | /// Define table repository to be created |
671 | $table = new xmldb_table('repository'); |
672 | |
673 | /// Adding fields to table repository |
674 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
675 | $table->add_field('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
676 | $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, '1'); |
677 | $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); |
678 | |
679 | /// Adding keys to table repository |
680 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
681 | |
682 | /// Conditionally launch create table for repository |
683 | if (!$dbman->table_exists($table)) { |
684 | $dbman->create_table($table); |
685 | } |
686 | /// Define table repository_instances to be created |
687 | $table = new xmldb_table('repository_instances'); |
688 | |
689 | /// Adding fields to table repository_instances |
690 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
691 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
692 | $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
693 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); |
694 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
695 | $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); |
696 | $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); |
697 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); |
698 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null); |
699 | |
700 | /// Adding keys to table repository_instances |
701 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
702 | |
703 | /// Conditionally launch create table for repository_instances |
704 | if (!$dbman->table_exists($table)) { |
705 | $dbman->create_table($table); |
706 | } |
707 | |
708 | /// Define table repository_instance_config to be created |
709 | $table = new xmldb_table('repository_instance_config'); |
710 | |
711 | /// Adding fields to table repository_instance_config |
712 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
713 | $table->add_field('instanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
714 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); |
715 | $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null); |
716 | |
717 | /// Adding keys to table repository_instance_config |
718 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
719 | |
720 | /// Conditionally launch create table for repository_instance_config |
721 | if (!$dbman->table_exists($table)) { |
722 | $dbman->create_table($table); |
723 | } |
724 | |
725 | /// Main savepoint reached |
8f3f6cc3 |
726 | upgrade_main_savepoint($result, 2008082602); |
27051e43 |
727 | } |
728 | |
62e76c67 |
729 | if ($result && $oldversion < 2008082700) { |
730 | /// Add a new column to the question sessions table to record whether a |
731 | /// question has been flagged. |
732 | |
733 | /// Define field flagged to be added to question_sessions |
734 | $table = new xmldb_table('question_sessions'); |
735 | $field = new xmldb_field('flagged', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, null, null, '0', 'manualcomment'); |
736 | |
737 | /// Conditionally launch add field flagged |
738 | if (!$dbman->field_exists($table, $field)) { |
739 | $dbman->add_field($table, $field); |
740 | } |
741 | |
742 | /// Main savepoint reached |
743 | upgrade_main_savepoint($result, 2008082700); |
744 | } |
ff2f69bc |
745 | |
2c48aeab |
746 | if ($result && $oldversion < 2008082900) { |
747 | |
748 | /// Changing precision of field parent_type on table mnet_rpc to (20) |
749 | $table = new xmldb_table('mnet_rpc'); |
750 | $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, null, 'xmlrpc_path'); |
751 | |
752 | /// Launch change of precision for field parent_type |
753 | $dbman->change_field_precision($table, $field); |
754 | |
755 | /// Main savepoint reached |
756 | upgrade_main_savepoint($result, 2008082900); |
757 | } |
758 | |
ff7e7f92 |
759 | if ($result && $oldversion < 2008090108) { |
760 | $repo = new object(); |
761 | $repo->type = 'upload'; |
762 | $repo->visible = 1; |
763 | $repo->sortorder = 1; |
764 | if (!$DB->record_exists('repository', array('type'=>'upload'))) { |
765 | $typeid = $DB->insert_record('repository', $repo); |
766 | }else{ |
767 | $record = $DB->get_record('repository', array('type'=>'upload')); |
768 | $typeid = $record->id; |
769 | } |
770 | if (!$DB->record_exists('repository_instances', array('typeid'=>$typeid))) { |
771 | $instance = new object(); |
fb7cae3b |
772 | $instance->name = get_string('repositoryname', 'repository_upload'); |
ff7e7f92 |
773 | $instance->typeid = $typeid; |
774 | $instance->userid = 0; |
775 | $instance->contextid = SITEID; |
776 | $instance->timecreated = time(); |
777 | $instance->timemodified = time(); |
778 | $result = $result && $DB->insert_record('repository_instances', $instance); |
779 | } |
780 | $repo->type = 'local'; |
781 | $repo->visible = 1; |
782 | $repo->sortorder = 1; |
783 | if (!$DB->record_exists('repository', array('type'=>'local'))) { |
784 | $typeid = $DB->insert_record('repository', $repo); |
785 | }else{ |
786 | $record = $DB->get_record('repository', array('type'=>'local')); |
787 | $typeid = $record->id; |
788 | } |
789 | if (!$DB->record_exists('repository_instances', array('typeid'=>$typeid))) { |
790 | $instance = new object(); |
fb7cae3b |
791 | $instance->name = get_string('repositoryname', 'repository_local'); |
ff7e7f92 |
792 | $instance->typeid = $typeid; |
793 | $instance->userid = 0; |
794 | $instance->contextid = SITEID; |
795 | $instance->timecreated = time(); |
796 | $instance->timemodified = time(); |
797 | $result = $result && $DB->insert_record('repository_instances', $instance); |
798 | } |
799 | |
800 | upgrade_main_savepoint($result, 2008090108); |
801 | } |
802 | |
d849880e |
803 | // MDL-16411 Move all plugintype_pluginname_version values from config to config_plugins. |
804 | if ($result && $oldversion < 2008091000) { |
805 | foreach (get_object_vars($CFG) as $name => $value) { |
806 | if (substr($name, strlen($name) - 8) !== '_version') { |
807 | continue; |
808 | } |
809 | $pluginname = substr($name, 0, strlen($name) - 8); |
810 | if (!strpos($pluginname, '_')) { |
811 | // Skip things like backup_version that don't contain an extra _ |
812 | continue; |
813 | } |
814 | if ($pluginname == 'enrol_ldap_version') { |
815 | // Special case - this is something different from a plugin version number. |
816 | continue; |
817 | } |
6f49dd0f |
818 | if (!preg_match('/^\d{10}$/', $value)) { |
d849880e |
819 | // Extra safety check, skip anything that does not look like a Moodle |
820 | // version number (10 digits). |
821 | continue; |
822 | } |
823 | $result = $result && set_config('version', $value, $pluginname); |
824 | $result = $result && unset_config($name); |
825 | } |
826 | upgrade_main_savepoint($result, 2008091000); |
827 | } |
828 | |
948c2860 |
829 | //Add a readonly field to the repository_instances table |
830 | //in order to support instance created automatically by a repository plugin |
831 | if ($result && $oldversion < 2008091611) { |
832 | |
833 | /// Define field readonly to be added to repository_instances |
834 | $table = new xmldb_table('repository_instances'); |
835 | $field = new xmldb_field('readonly', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timemodified'); |
836 | |
837 | /// Conditionally launch add field readonly |
838 | if (!$dbman->field_exists($table, $field)) { |
839 | $dbman->add_field($table, $field); |
840 | } |
841 | |
842 | /// Main savepoint reached |
843 | upgrade_main_savepoint($result, 2008091611); |
844 | } |
845 | |
53b20fe3 |
846 | if ($result && $oldversion < 2008092300) { |
847 | unset_config('editorspelling'); |
848 | unset_config('editordictionary'); |
849 | /// Main savepoint reached |
850 | upgrade_main_savepoint($result, 2008092300); |
851 | } |
852 | |
a7df430b |
853 | if ($result && $oldversion < 2008101000) { |
854 | |
855 | /// Changing the default of field lang on table user to en_utf8 |
856 | $table = new xmldb_table('user'); |
857 | $field = new xmldb_field('lang', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'en_utf8', 'country'); |
858 | |
859 | /// Launch change of default for field lang |
860 | $dbman->change_field_default($table, $field); |
861 | |
862 | /// Main savepoint reached |
863 | upgrade_main_savepoint($result, 2008101000); |
864 | } |
865 | |
5e7206a8 |
866 | if ($result && $oldversion < 2008101300) { |
867 | |
868 | if (!get_config(NULL, 'statsruntimedays')) { |
869 | set_config('statsruntimedays', '31'); |
870 | } |
871 | |
872 | /// Main savepoint reached |
873 | upgrade_main_savepoint($result, 2008101300); |
874 | } |
53b20fe3 |
875 | |
01a80f51 |
876 | /// New table for storing which roles can be assigned in which contexts. |
877 | if ($result && $oldversion < 2008110601) { |
878 | |
879 | /// Define table role_context_levels to be created |
880 | $table = new xmldb_table('role_context_levels'); |
881 | |
882 | /// Adding fields to table role_context_levels |
883 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); |
884 | $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
885 | $table->add_field('contextlevel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); |
886 | |
887 | /// Adding keys to table role_context_levels |
888 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
889 | $table->add_key('contextlevel-roleid', XMLDB_KEY_UNIQUE, array('contextlevel', 'roleid')); |
890 | $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id')); |
891 | |
892 | /// Conditionally launch create table for role_context_levels |
893 | if (!$dbman->table_exists($table)) { |
894 | $dbman->create_table($table); |
895 | } |
896 | |
897 | /// Main savepoint reached |
898 | upgrade_main_savepoint($result, 2008110601); |
899 | } |
900 | |
901 | /// Now populate the role_context_levels table with the defaults that match |
902 | /// moodle_install_roles, and any other combinations that exist in this system. |
903 | if ($result && $oldversion < 2008110602) { |
904 | $roleids = $DB->get_records_menu('role', array(), '', 'shortname,id'); |
905 | |
906 | /// Defaults, should match moodle_install_roles. |
907 | $rolecontextlevels = array(); |
908 | if (isset($roleids['admin'])) { |
909 | $rolecontextlevels[$roleids['admin']] = get_default_contextlevels('admin'); |
910 | } |
911 | if (isset($roleids['coursecreator'])) { |
912 | $rolecontextlevels[$roleids['coursecreator']] = get_default_contextlevels('coursecreator'); |
913 | } |
914 | if (isset($roleids['editingteacher'])) { |
915 | $rolecontextlevels[$roleids['editingteacher']] = get_default_contextlevels('editingteacher'); |
916 | } |
917 | if (isset($roleids['teacher'])) { |
918 | $rolecontextlevels[$roleids['teacher']] = get_default_contextlevels('teacher'); |
919 | } |
920 | if (isset($roleids['student'])) { |
921 | $rolecontextlevels[$roleids['student']] = get_default_contextlevels('student'); |
922 | } |
923 | if (isset($roleids['guest'])) { |
924 | $rolecontextlevels[$roleids['guest']] = get_default_contextlevels('guest'); |
925 | } |
926 | if (isset($roleids['user'])) { |
927 | $rolecontextlevels[$roleids['user']] = get_default_contextlevels('user'); |
928 | } |
929 | |
930 | /// See what other role assignments are in this database, extend the allowed |
931 | /// lists to allow them too. |
932 | $existingrolecontextlevels = $DB->get_recordset_sql('SELECT DISTINCT ra.roleid, con.contextlevel FROM |
933 | {role_assignments} ra JOIN {context} con ON ra.contextid = con.id'); |
934 | foreach ($existingrolecontextlevels as $rcl) { |
935 | if (!isset($rolecontextlevels[$rcl->roleid])) { |
936 | $rolecontextlevels[$rcl->roleid] = array($rcl->contextlevel); |
937 | } else if (!in_array($rcl->contextlevel, $rolecontextlevels[$rcl->roleid])) { |
938 | $rolecontextlevels[$rcl->roleid][] = $rcl->contextlevel; |
939 | } |
940 | } |
941 | |
942 | /// Put the data into the database. |
943 | foreach ($rolecontextlevels as $roleid => $contextlevels) { |
944 | set_role_contextlevels($roleid, $contextlevels); |
945 | } |
946 | |
947 | /// Main savepoint reached |
948 | upgrade_main_savepoint($result, 2008110602); |
949 | } |
950 | |
ac9b0805 |
951 | return $result; |
4e423cbf |
952 | } |
271e6dec |
953 | |
954 | |
4e423cbf |
955 | ?> |