MDL-18302 filterlib - fixed rebuild of nested ignoretags ; merged from 19_STABLE
[moodle.git] / lib / db / upgrade.php
CommitLineData
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 22function 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
795a08ad 33 if ($result && $oldversion < 2008030600) {
34 //NOTE: this table was added much later, that is why this step is repeated later in this file
35
36 /// Define table upgrade_log to be created
37 $table = new xmldb_table('upgrade_log');
38
39 /// Adding fields to table upgrade_log
40 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
41 $table->add_field('type', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
42 $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null);
43 $table->add_field('version', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null);
44 $table->add_field('info', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
45 $table->add_field('details', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
46 $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
47 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
48 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
49
50 /// Adding keys to table upgrade_log
51 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
52 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
53
54 /// Adding indexes to table upgrade_log
55 $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
56 $table->add_index('type-timemodified', XMLDB_INDEX_NOTUNIQUE, array('type', 'timemodified'));
57
58 /// Create table for upgrade_log
59 $dbman->create_table($table);
60
61 /// Main savepoint reached
62 upgrade_main_savepoint($result, 2008030600);
63 }
64
a1f27717 65 if ($result && $oldversion < 2008030700) {
775f811a 66 upgrade_set_timeout(60*20); // this may take a while
a1f27717 67
68 /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters
a8cb94f6 69 $table = new xmldb_table('grade_letters');
69b80cc2 70 $index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
a1f27717 71
72 /// Launch drop index contextid-lowerboundary
eee5d9bb 73 $dbman->drop_index($table, $index);
a1f27717 74
a1f27717 75 /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
a8cb94f6 76 $table = new xmldb_table('grade_letters');
69b80cc2 77 $index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
a1f27717 78
79 /// Launch add index contextid-lowerboundary-letter
eee5d9bb 80 $dbman->add_index($table, $index);
a1f27717 81
82 /// Main savepoint reached
0f77b186 83 upgrade_main_savepoint($result, 2008030700);
84 }
a1f27717 85
1ea260d8 86 if ($result && $oldversion < 2008050100) {
87 // Update courses that used weekscss to weeks
a8cb94f6 88 $result = $DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss'));
1ea260d8 89 upgrade_main_savepoint($result, 2008050100);
90 }
91
0b51c247 92 if ($result && $oldversion < 2008050200) {
93 // remove unused config options
94 unset_config('statsrolesupgraded');
95 upgrade_main_savepoint($result, 2008050200);
96 }
97
994fbaab 98 if ($result && $oldversion < 2008050700) {
775f811a 99 upgrade_set_timeout(60*20); // this may take a while
100
994fbaab 101 /// Fix minor problem caused by MDL-5482.
102 require_once($CFG->dirroot . '/question/upgrade.php');
103 $result = $result && question_fix_random_question_parents();
104 upgrade_main_savepoint($result, 2008050700);
105 }
106
ab37dc60 107 if ($result && $oldversion < 2008051200) {
108 // if guest role used as default user role unset it and force admin to choose new setting
109 if (!empty($CFG->defaultuserroleid)) {
910dd4dd 110 if ($role = $DB->get_record('role', array('id'=>$CFG->defaultuserroleid))) {
ab37dc60 111 if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
112 if (isset($guestroles[$role->id])) {
113 set_config('defaultuserroleid', null);
114 notify('Guest role removed from "Default role for all users" setting, please select another role.', 'notifysuccess');
115 }
116 }
117 } else {
118 set_config('defaultuserroleid', null);
119 }
120 }
121 }
122
8b9cfac4 123 if ($result && $oldversion < 2008051201) {
124 notify('Increasing size of user idnumber field, this may take a while...', 'notifysuccess');
775f811a 125 upgrade_set_timeout(60*20); // this may take a while
8b9cfac4 126
469dcbcc 127 /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859
cbc08f3b 128 $dbfamily = $DB->get_dbfamily();
129 if ($dbfamily === 'mysql' || $dbfamily === 'postgres') {
eee5d9bb 130 $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL");
469dcbcc 131 }
132
8b9cfac4 133 /// Define index idnumber (not unique) to be dropped form user
a8cb94f6 134 $table = new xmldb_table('user');
69b80cc2 135 $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
8b9cfac4 136
137 /// Launch drop index idnumber
f33e1ed4 138 if ($dbman->index_exists($table, $index)) {
eee5d9bb 139 $dbman->drop_index($table, $index);
8b9cfac4 140 }
141
142 /// Changing precision of field idnumber on table user to (255)
a8cb94f6 143 $table = new xmldb_table('user');
69b80cc2 144 $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'password');
8b9cfac4 145
146 /// Launch change of precision for field idnumber
eee5d9bb 147 $dbman->change_field_precision($table, $field);
8b9cfac4 148
149 /// Launch add index idnumber again
69b80cc2 150 $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
eee5d9bb 151 $dbman->add_index($table, $index);
8b9cfac4 152
153 /// Main savepoint reached
154 upgrade_main_savepoint($result, 2008051201);
155 }
156
7ade55ad 157 if ($result && $oldversion < 2008051202) {
910dd4dd 158 $log_action = new object();
7ade55ad 159 $log_action->module = 'course';
160 $log_action->action = 'unenrol';
161 $log_action->mtable = 'course';
162 $log_action->field = 'fullname';
910dd4dd 163 if (!$DB->record_exists('log_display', array('action'=>'unenrol', 'module'=>'course'))) {
164 $result = $result && $DB->insert_record('log_display', $log_action);
7ade55ad 165 }
166 upgrade_main_savepoint($result, 2008051202);
167 }
168
fa162144 169 if ($result && $oldversion < 2008051203) {
170 $table = new xmldb_table('mnet_enrol_course');
171 $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', true, true, null, false, false, 0);
eee5d9bb 172 $dbman->change_field_precision($table, $field);
fa162144 173 upgrade_main_savepoint($result, 2008051203);
174 }
175
38fb8190 176 if ($result && $oldversion < 2008063001) {
775f811a 177 upgrade_set_timeout(60*20); // this may take a while
178
38fb8190 179 // table to be modified
180 $table = new xmldb_table('tag_instance');
181 // add field
182 $field = new xmldb_field('tiuserid');
183 if (!$dbman->field_exists($table, $field)) {
184 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0, 'itemid');
185 $dbman->add_field($table, $field);
186 }
187 // modify index
188 $index = new xmldb_index('itemtype-itemid-tagid');
189 $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));
b91de8a5 190 if ($dbman->index_exists($table, $index)) {
191 $dbman->drop_index($table, $index);
192 }
38fb8190 193 $index = new xmldb_index('itemtype-itemid-tagid-tiuserid');
194 $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
b91de8a5 195 if (!$dbman->index_exists($table, $index)) {
196 $dbman->add_index($table, $index);
197 }
38fb8190 198
199 /// Main savepoint reached
200 upgrade_main_savepoint($result, 2008063001);
201 }
38fb8190 202
a036d7f3 203 if ($result && $oldversion < 2008070300) {
204 $result = $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false));
205 upgrade_main_savepoint($result, 2008070300);
206 }
4e781c7b 207
fe074586 208 if ($result && $oldversion < 2008070700) {
209 if (isset($CFG->defaultuserroleid) and isset($CFG->guestroleid) and $CFG->defaultuserroleid == $CFG->guestroleid) {
210 // guest can not be selected in defaultuserroleid!
211 unset_config('defaultuserroleid');
212 }
213 upgrade_main_savepoint($result, 2008070700);
214 }
215
ac5efef6 216 if ($result && $oldversion < 2008070701) {
217
218 /// Define table portfolio_instance to be created
219 $table = new xmldb_table('portfolio_instance');
220
221 /// Adding fields to table portfolio_instance
222 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
223 $table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null);
224 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
225 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1');
226
227 /// Adding keys to table portfolio_instance
228 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
229
230 /// Conditionally launch create table for portfolio_instance
231 if (!$dbman->table_exists($table)) {
232 $dbman->create_table($table);
233 }
234 /// Define table portfolio_instance_config to be created
235 $table = new xmldb_table('portfolio_instance_config');
236
237 /// Adding fields to table portfolio_instance_config
238 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
239 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
240 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
241 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
242
243 /// Adding keys to table portfolio_instance_config
244 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
245 $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
246
247 /// Adding indexes to table portfolio_instance_config
248 $table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name'));
249
250 /// Conditionally launch create table for portfolio_instance_config
251 if (!$dbman->table_exists($table)) {
252 $dbman->create_table($table);
253 }
254
255 /// Define table portfolio_instance_user to be created
256 $table = new xmldb_table('portfolio_instance_user');
257
258 /// Adding fields to table portfolio_instance_user
259 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
260 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
261 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
262 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
263 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
264
265 /// Adding keys to table portfolio_instance_user
266 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
267 $table->add_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
268 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
269
270 /// Conditionally launch create table for portfolio_instance_user
271 if (!$dbman->table_exists($table)) {
272 $dbman->create_table($table);
273 }
274
275 /// Main savepoint reached
276 upgrade_main_savepoint($result, 2008070701);
277 }
172dd12c 278
775f811a 279 if ($result && $oldversion < 2008072400) {
280 /// Create the database tables for message_processors
f65b2dae 281 $table = new xmldb_table('message_processors');
282 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
283 $table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null);
284 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3b120e46 285 $dbman->create_table($table);
286
3b120e46 287 /// delete old and create new fields
f65b2dae 288 $table = new xmldb_table('message');
289 $field = new xmldb_field('messagetype');
3b120e46 290 $dbman->drop_field($table, $field);
291
292 /// fields to rename
f65b2dae 293 $field = new xmldb_field('message');
294 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 295 $dbman->rename_field($table, $field, 'fullmessage');
f65b2dae 296 $field = new xmldb_field('format');
297 $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '0', null);
3b120e46 298 $dbman->rename_field($table, $field, 'fullmessageformat');
299
300 /// new message fields
f65b2dae 301 $field = new xmldb_field('subject');
302 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 303 $dbman->add_field($table, $field);
f65b2dae 304 $field = new xmldb_field('fullmessagehtml');
305 $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, null);
3b120e46 306 $dbman->add_field($table, $field);
f65b2dae 307 $field = new xmldb_field('smallmessage');
308 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 309 $dbman->add_field($table, $field);
310
311
f65b2dae 312 $table = new xmldb_table('message_read');
313 $field = new xmldb_field('messagetype');
3b120e46 314 $dbman->drop_field($table, $field);
f65b2dae 315 $field = new xmldb_field('mailed');
3b120e46 316 $dbman->drop_field($table, $field);
317
318 /// fields to rename
f65b2dae 319 $field = new xmldb_field('message');
320 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 321 $dbman->rename_field($table, $field, 'fullmessage');
f65b2dae 322 $field = new xmldb_field('format');
323 $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '0', null);
3b120e46 324 $dbman->rename_field($table, $field, 'fullmessageformat');
325
326
327 /// new message fields
f65b2dae 328 $field = new xmldb_field('subject');
329 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 330 $dbman->add_field($table, $field);
f65b2dae 331 $field = new xmldb_field('fullmessagehtml');
332 $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, null);
3b120e46 333 $dbman->add_field($table, $field);
f65b2dae 334 $field = new xmldb_field('smallmessage');
335 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 336 $dbman->add_field($table, $field);
337
338 /// new table
f65b2dae 339 $table = new xmldb_table('message_working');
340 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
341 $table->add_field('unreadmessageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
342 $table->add_field('processorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
343 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3b120e46 344 $dbman->create_table($table);
345
346
347 upgrade_main_savepoint($result, 2008072400);
348 }
349
4e781c7b 350 if ($result && $oldversion < 2008072800) {
351
352 /// Define field enablecompletion to be added to course
353 $table = new xmldb_table('course');
354 $field = new xmldb_field('enablecompletion');
355 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'defaultrole');
356
357 /// Launch add field enablecompletion
775f811a 358 if (!$dbman->field_exists($table,$field)) {
4e781c7b 359 $dbman->add_field($table, $field);
360 }
775f811a 361
4e781c7b 362 /// Define field completion to be added to course_modules
363 $table = new xmldb_table('course_modules');
364 $field = new xmldb_field('completion');
365 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'groupmembersonly');
366
367 /// Launch add field completion
775f811a 368 if (!$dbman->field_exists($table,$field)) {
4e781c7b 369 $dbman->add_field($table, $field);
370 }
371
372 /// Define field completiongradeitemnumber to be added to course_modules
373 $field = new xmldb_field('completiongradeitemnumber');
374 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'completion');
375
376 /// Launch add field completiongradeitemnumber
775f811a 377 if (!$dbman->field_exists($table,$field)) {
4e781c7b 378 $dbman->add_field($table, $field);
379 }
380
381 /// Define field completionview to be added to course_modules
382 $field = new xmldb_field('completionview');
383 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completiongradeitemnumber');
384
385 /// Launch add field completionview
775f811a 386 if (!$dbman->field_exists($table,$field)) {
4e781c7b 387 $dbman->add_field($table, $field);
388 }
389
390 /// Define field completionexpected to be added to course_modules
391 $field = new xmldb_field('completionexpected');
392 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionview');
393
394 /// Launch add field completionexpected
775f811a 395 if (!$dbman->field_exists($table,$field)) {
4e781c7b 396 $dbman->add_field($table, $field);
397 }
398
399 /// Define table course_modules_completion to be created
400 $table = new xmldb_table('course_modules_completion');
775f811a 401 if (!$dbman->table_exists($table)) {
4e781c7b 402
403 /// Adding fields to table course_modules_completion
1e0c56ea 404 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
405 $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
406 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
407 $table->add_field('completionstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
408 $table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null);
409 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
775f811a 410
4e781c7b 411 /// Adding keys to table course_modules_completion
1e0c56ea 412 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
775f811a 413
4e781c7b 414 /// Adding indexes to table course_modules_completion
1e0c56ea 415 $table->add_index('coursemoduleid', XMLDB_INDEX_NOTUNIQUE, array('coursemoduleid'));
416 $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
775f811a 417
4e781c7b 418 /// Launch create table for course_modules_completion
419 $dbman->create_table($table);
420 }
421
422 /// Main savepoint reached
423 upgrade_main_savepoint($result, 2008072800);
424 }
775f811a 425
4ab16a09 426 if ($result && $oldversion < 2008073000) {
ac5efef6 427
4ab16a09 428 /// Define table portfolio_log to be created
429 $table = new xmldb_table('portfolio_log');
430
431 /// Adding fields to table portfolio_log
432 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
433 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
434 $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
435 $table->add_field('portfolio', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
436 $table->add_field('caller_class', XMLDB_TYPE_CHAR, '150', null, XMLDB_NOTNULL, null, null, null, null);
437 $table->add_field('caller_file', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
438 $table->add_field('caller_sha1', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
439
440 /// Adding keys to table portfolio_log
441 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
442 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
443 $table->add_key('portfoliofk', XMLDB_KEY_FOREIGN, array('portfolio'), 'portfolio_instance', array('id'));
444
445 /// Conditionally launch create table for portfolio_log
446 if (!$dbman->table_exists($table)) {
447 $dbman->create_table($table);
448 }
449
450 /// Main savepoint reached
451 upgrade_main_savepoint($result, 2008073000);
452 }
120b3758 453
454 if ($result && $oldversion < 2008073104) {
455 /// Drop old table that might exist for some people
456 $table = new xmldb_table('message_providers');
457 if ($dbman->table_exists($table)) {
458 $dbman->drop_table($table);
459 }
460
461 /// Define table message_providers to be created
462 $table = new xmldb_table('message_providers');
463
464 /// Adding fields to table message_providers
465 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
466 $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null);
467 $table->add_field('component', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null, null, null);
468 $table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
469
470 /// Adding keys to table message_providers
471 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
472
473 /// Adding indexes to table message_providers
474 $table->add_index('componentname', XMLDB_INDEX_UNIQUE, array('component', 'name'));
475
476 /// Create table for message_providers
477 $dbman->create_table($table);
478
479 upgrade_main_savepoint($result, 2008073104);
480 }
172dd12c 481
482 if ($result && $oldversion < 2008073111) {
483 /// Define table files to be created
484 $table = new xmldb_table('files');
485
486 /// Adding fields to table files
487 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
488 $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null);
489 $table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null);
490 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
491 $table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null);
492 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
493 $table->add_field('filepath', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
494 $table->add_field('filename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
495 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
496 $table->add_field('filesize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
497 $table->add_field('mimetype', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null);
498 $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
499 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
500 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
501
502 /// Adding keys to table files
503 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
504 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
505 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
506
507 /// Adding indexes to table files
508 $table->add_index('filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('filearea', 'contextid', 'itemid'));
509 $table->add_index('contenthash', XMLDB_INDEX_NOTUNIQUE, array('contenthash'));
510 $table->add_index('pathnamehash', XMLDB_INDEX_UNIQUE, array('pathnamehash'));
511
512 /// Conditionally launch create table for files
513 $dbman->create_table($table);
514
515 /// Main savepoint reached
516 upgrade_main_savepoint($result, 2008073111);
517 }
518
519 if ($result && $oldversion < 2008073112) {
520 /// Define table files_cleanup to be created
521 $table = new xmldb_table('files_cleanup');
522
523 /// Adding fields to table files_cleanup
524 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
525 $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null);
526
527 /// Adding keys to table files_cleanup
528 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
529
530 /// Adding indexes to table files_cleanup
531 $table->add_index('contenthash', XMLDB_INDEX_UNIQUE, array('contenthash'));
532
533 /// Conditionally launch create table for files_cleanup
534 $dbman->create_table($table);
535
536 /// Main savepoint reached
537 upgrade_main_savepoint($result, 2008073112);
538 }
539
540 if ($result && $oldversion < 2008073113) {
541 /// move all course, backup and other files to new filepool based storage
542 upgrade_migrate_files_courses();
543 /// Main savepoint reached
544 upgrade_main_savepoint($result, 2008073113);
545 }
546
547 if ($result && $oldversion < 2008073114) {
548 /// move all course, backup and other files to new filepool based storage
549 upgrade_migrate_files_blog();
550 /// Main savepoint reached
551 upgrade_main_savepoint($result, 2008073114);
552 }
f33e1ed4 553
1ce2da58 554 if ($result && $oldversion < 2008080400) {
555 // Add field ssl_jump_url to mnet application, and populate existing default applications
556 $table = new xmldb_table('mnet_application');
557 $field = new xmldb_field('sso_jump_url');
558 if (!$dbman->field_exists($table, $field)) {
559 $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
c5a04d12 560 $dbman->add_field($table, $field);
561 $result = $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle'));
1ce2da58 562 $result = $result && $DB->set_field('mnet_application', 'sso_jump_url', '/auth/xmlrpc/jump.php', array('name' => 'mahara'));
563 }
564
565 /// Main savepoint reached
566 upgrade_main_savepoint($result, 2008080400);
567 }
04f35360 568
569 if ($result && $oldversion < 2008080500) {
570
571 /// Define table portfolio_tempdata to be created
572 $table = new xmldb_table('portfolio_tempdata');
573
574 /// Adding fields to table portfolio_tempdata
575 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
576 $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
577
578 /// Adding keys to table portfolio_tempdata
579 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
580
581 /// Conditionally launch create table for portfolio_tempdata
582 if (!$dbman->table_exists($table)) {
583 $dbman->create_table($table);
584 }
585
586 /// Main savepoint reached
587 upgrade_main_savepoint($result, 2008080500);
588 }
589
84a44985 590 if ($result && $oldversion < 2008080600) {
591
592 $DB->delete_records('portfolio_tempdata'); // there shouldnt' be any, and it will cause problems with this upgrade.
593 /// Define field expirytime to be added to portfolio_tempdata
594 $table = new xmldb_table('portfolio_tempdata');
595 $field = new xmldb_field('expirytime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'data');
596
597 /// Conditionally launch add field expirytime
598 if (!$dbman->field_exists($table, $field)) {
599 $dbman->add_field($table, $field);
600 }
601
602 /// Main savepoint reached
603 upgrade_main_savepoint($result, 2008080600);
604 }
775f811a 605
f9a2cf86 606/// Changing the type of all the columns that the question bank uses to store grades to be NUMBER(12, 7).
607 if ($result && $oldversion < 2008081500) {
608 $table = new xmldb_table('question');
609 $field = new xmldb_field('defaultgrade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'generalfeedback');
610 $dbman->change_field_type($table, $field);
611 upgrade_main_savepoint($result, 2008081500);
612 }
613
614 if ($result && $oldversion < 2008081501) {
615 $table = new xmldb_table('question');
616 $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'defaultgrade');
617 $dbman->change_field_type($table, $field);
618 upgrade_main_savepoint($result, 2008081501);
619 }
620
621 if ($result && $oldversion < 2008081502) {
622 $table = new xmldb_table('question_answers');
623 $field = new xmldb_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'answer');
624 $dbman->change_field_type($table, $field);
625 upgrade_main_savepoint($result, 2008081502);
626 }
627
628 if ($result && $oldversion < 2008081503) {
629 $table = new xmldb_table('question_sessions');
630 $field = new xmldb_field('sumpenalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'newgraded');
631 $dbman->change_field_type($table, $field);
632 upgrade_main_savepoint($result, 2008081503);
633 }
634
635 if ($result && $oldversion < 2008081504) {
636 $table = new xmldb_table('question_states');
637 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'event');
638 $dbman->change_field_type($table, $field);
639 upgrade_main_savepoint($result, 2008081504);
640 }
641
642 if ($result && $oldversion < 2008081505) {
643 $table = new xmldb_table('question_states');
644 $field = new xmldb_field('raw_grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'grade');
645 $dbman->change_field_type($table, $field);
646 upgrade_main_savepoint($result, 2008081505);
647 }
648
649 if ($result && $oldversion < 2008081506) {
650 $table = new xmldb_table('question_states');
651 $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'raw_grade');
652 $dbman->change_field_type($table, $field);
653 upgrade_main_savepoint($result, 2008081506);
654 }
655
775f811a 656 if ($result && $oldversion < 2008081600) {
657
658 /// all 1.9 sites and fresh installs must already be unicode, not needed anymore
659 unset_config('unicodedb');
660
661 /// Main savepoint reached
662 upgrade_main_savepoint($result, 2008081600);
663 }
664
ff2f69bc 665 if ($result && $oldversion < 2008081900) {
666 /// Define field userid to be added to portfolio_tempdata
667 $table = new xmldb_table('portfolio_tempdata');
668 $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'expirytime');
669
670 /// Conditionally launch add field userid
671 if (!$dbman->field_exists($table, $field)) {
672 $dbman->add_field($table, $field);
673 }
674 $DB->set_field('portfolio_tempdata', 'userid', 0);
675 /// now change it to be notnull
676
677 /// Changing nullability of field userid on table portfolio_tempdata to not null
678 $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'expirytime');
679
680 /// Launch change of nullability for field userid
681 $dbman->change_field_notnull($table, $field);
682
683 /// Define key userfk (foreign) to be added to portfolio_tempdata
684 $table = new xmldb_table('portfolio_tempdata');
685 $key = new xmldb_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
686
687 /// Launch add key userfk
688 $dbman->add_key($table, $key);
689
690 upgrade_main_savepoint($result, 2008081900);
691 }
8f3f6cc3 692 if ($result && $oldversion < 2008082602) {
27051e43 693
694 /// Define table repository to be dropped
695 $table = new xmldb_table('repository');
696
697 /// Conditionally launch drop table for repository
698 if ($dbman->table_exists($table)) {
699 $dbman->drop_table($table);
700 }
701
702 /// Define table repository to be created
703 $table = new xmldb_table('repository');
704
705 /// Adding fields to table repository
706 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
707 $table->add_field('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
708 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, '1');
709 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
710
711 /// Adding keys to table repository
712 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
713
714 /// Conditionally launch create table for repository
715 if (!$dbman->table_exists($table)) {
716 $dbman->create_table($table);
717 }
718 /// Define table repository_instances to be created
719 $table = new xmldb_table('repository_instances');
720
721 /// Adding fields to table repository_instances
722 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
723 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
724 $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
725 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
726 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
727 $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
728 $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
729 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
730 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
731
732 /// Adding keys to table repository_instances
733 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
734
735 /// Conditionally launch create table for repository_instances
736 if (!$dbman->table_exists($table)) {
737 $dbman->create_table($table);
738 }
739
740 /// Define table repository_instance_config to be created
741 $table = new xmldb_table('repository_instance_config');
742
743 /// Adding fields to table repository_instance_config
744 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
745 $table->add_field('instanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
746 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
747 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
748
749 /// Adding keys to table repository_instance_config
750 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
751
752 /// Conditionally launch create table for repository_instance_config
753 if (!$dbman->table_exists($table)) {
754 $dbman->create_table($table);
755 }
756
757 /// Main savepoint reached
8f3f6cc3 758 upgrade_main_savepoint($result, 2008082602);
27051e43 759 }
760
62e76c67 761 if ($result && $oldversion < 2008082700) {
762 /// Add a new column to the question sessions table to record whether a
763 /// question has been flagged.
764
765 /// Define field flagged to be added to question_sessions
766 $table = new xmldb_table('question_sessions');
767 $field = new xmldb_field('flagged', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, null, null, '0', 'manualcomment');
768
769 /// Conditionally launch add field flagged
770 if (!$dbman->field_exists($table, $field)) {
771 $dbman->add_field($table, $field);
772 }
773
774 /// Main savepoint reached
775 upgrade_main_savepoint($result, 2008082700);
776 }
ff2f69bc 777
2c48aeab 778 if ($result && $oldversion < 2008082900) {
779
780 /// Changing precision of field parent_type on table mnet_rpc to (20)
781 $table = new xmldb_table('mnet_rpc');
782 $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, null, 'xmlrpc_path');
783
784 /// Launch change of precision for field parent_type
785 $dbman->change_field_precision($table, $field);
786
787 /// Main savepoint reached
788 upgrade_main_savepoint($result, 2008082900);
789 }
790
ff7e7f92 791 if ($result && $oldversion < 2008090108) {
792 $repo = new object();
793 $repo->type = 'upload';
794 $repo->visible = 1;
795 $repo->sortorder = 1;
796 if (!$DB->record_exists('repository', array('type'=>'upload'))) {
797 $typeid = $DB->insert_record('repository', $repo);
798 }else{
799 $record = $DB->get_record('repository', array('type'=>'upload'));
800 $typeid = $record->id;
801 }
802 if (!$DB->record_exists('repository_instances', array('typeid'=>$typeid))) {
803 $instance = new object();
fb7cae3b 804 $instance->name = get_string('repositoryname', 'repository_upload');
ff7e7f92 805 $instance->typeid = $typeid;
806 $instance->userid = 0;
807 $instance->contextid = SITEID;
808 $instance->timecreated = time();
809 $instance->timemodified = time();
810 $result = $result && $DB->insert_record('repository_instances', $instance);
811 }
812 $repo->type = 'local';
813 $repo->visible = 1;
814 $repo->sortorder = 1;
815 if (!$DB->record_exists('repository', array('type'=>'local'))) {
816 $typeid = $DB->insert_record('repository', $repo);
817 }else{
818 $record = $DB->get_record('repository', array('type'=>'local'));
819 $typeid = $record->id;
820 }
821 if (!$DB->record_exists('repository_instances', array('typeid'=>$typeid))) {
822 $instance = new object();
fb7cae3b 823 $instance->name = get_string('repositoryname', 'repository_local');
ff7e7f92 824 $instance->typeid = $typeid;
825 $instance->userid = 0;
826 $instance->contextid = SITEID;
827 $instance->timecreated = time();
828 $instance->timemodified = time();
829 $result = $result && $DB->insert_record('repository_instances', $instance);
830 }
831
832 upgrade_main_savepoint($result, 2008090108);
833 }
834
d849880e 835 // MDL-16411 Move all plugintype_pluginname_version values from config to config_plugins.
836 if ($result && $oldversion < 2008091000) {
837 foreach (get_object_vars($CFG) as $name => $value) {
838 if (substr($name, strlen($name) - 8) !== '_version') {
839 continue;
840 }
841 $pluginname = substr($name, 0, strlen($name) - 8);
842 if (!strpos($pluginname, '_')) {
843 // Skip things like backup_version that don't contain an extra _
844 continue;
845 }
846 if ($pluginname == 'enrol_ldap_version') {
847 // Special case - this is something different from a plugin version number.
848 continue;
849 }
6f49dd0f 850 if (!preg_match('/^\d{10}$/', $value)) {
d849880e 851 // Extra safety check, skip anything that does not look like a Moodle
852 // version number (10 digits).
853 continue;
854 }
855 $result = $result && set_config('version', $value, $pluginname);
856 $result = $result && unset_config($name);
857 }
858 upgrade_main_savepoint($result, 2008091000);
859 }
860
948c2860 861 //Add a readonly field to the repository_instances table
862 //in order to support instance created automatically by a repository plugin
863 if ($result && $oldversion < 2008091611) {
864
865 /// Define field readonly to be added to repository_instances
866 $table = new xmldb_table('repository_instances');
867 $field = new xmldb_field('readonly', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timemodified');
868
869 /// Conditionally launch add field readonly
870 if (!$dbman->field_exists($table, $field)) {
871 $dbman->add_field($table, $field);
872 }
873
874 /// Main savepoint reached
875 upgrade_main_savepoint($result, 2008091611);
876 }
877
53b20fe3 878 if ($result && $oldversion < 2008092300) {
879 unset_config('editorspelling');
880 unset_config('editordictionary');
881 /// Main savepoint reached
882 upgrade_main_savepoint($result, 2008092300);
883 }
884
a7df430b 885 if ($result && $oldversion < 2008101000) {
886
887 /// Changing the default of field lang on table user to en_utf8
888 $table = new xmldb_table('user');
889 $field = new xmldb_field('lang', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'en_utf8', 'country');
890
891 /// Launch change of default for field lang
892 $dbman->change_field_default($table, $field);
893
894 /// Main savepoint reached
895 upgrade_main_savepoint($result, 2008101000);
896 }
897
5e7206a8 898 if ($result && $oldversion < 2008101300) {
899
d9e673c1 900 if (!get_config(NULL, 'statsruntimedays')) {
5e7206a8 901 set_config('statsruntimedays', '31');
902 }
903
904 /// Main savepoint reached
905 upgrade_main_savepoint($result, 2008101300);
906 }
53b20fe3 907
01a80f51 908 /// New table for storing which roles can be assigned in which contexts.
909 if ($result && $oldversion < 2008110601) {
910
911 /// Define table role_context_levels to be created
912 $table = new xmldb_table('role_context_levels');
913
914 /// Adding fields to table role_context_levels
915 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
916 $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
917 $table->add_field('contextlevel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
918
919 /// Adding keys to table role_context_levels
920 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
921 $table->add_key('contextlevel-roleid', XMLDB_KEY_UNIQUE, array('contextlevel', 'roleid'));
922 $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
923
924 /// Conditionally launch create table for role_context_levels
925 if (!$dbman->table_exists($table)) {
926 $dbman->create_table($table);
927 }
928
929 /// Main savepoint reached
930 upgrade_main_savepoint($result, 2008110601);
931 }
932
933 /// Now populate the role_context_levels table with the defaults that match
934 /// moodle_install_roles, and any other combinations that exist in this system.
935 if ($result && $oldversion < 2008110602) {
936 $roleids = $DB->get_records_menu('role', array(), '', 'shortname,id');
937
938 /// Defaults, should match moodle_install_roles.
939 $rolecontextlevels = array();
940 if (isset($roleids['admin'])) {
941 $rolecontextlevels[$roleids['admin']] = get_default_contextlevels('admin');
942 }
943 if (isset($roleids['coursecreator'])) {
944 $rolecontextlevels[$roleids['coursecreator']] = get_default_contextlevels('coursecreator');
945 }
946 if (isset($roleids['editingteacher'])) {
947 $rolecontextlevels[$roleids['editingteacher']] = get_default_contextlevels('editingteacher');
948 }
949 if (isset($roleids['teacher'])) {
950 $rolecontextlevels[$roleids['teacher']] = get_default_contextlevels('teacher');
951 }
952 if (isset($roleids['student'])) {
953 $rolecontextlevels[$roleids['student']] = get_default_contextlevels('student');
954 }
955 if (isset($roleids['guest'])) {
956 $rolecontextlevels[$roleids['guest']] = get_default_contextlevels('guest');
957 }
958 if (isset($roleids['user'])) {
959 $rolecontextlevels[$roleids['user']] = get_default_contextlevels('user');
960 }
656be893 961
01a80f51 962 /// See what other role assignments are in this database, extend the allowed
963 /// lists to allow them too.
964 $existingrolecontextlevels = $DB->get_recordset_sql('SELECT DISTINCT ra.roleid, con.contextlevel FROM
965 {role_assignments} ra JOIN {context} con ON ra.contextid = con.id');
966 foreach ($existingrolecontextlevels as $rcl) {
967 if (!isset($rolecontextlevels[$rcl->roleid])) {
968 $rolecontextlevels[$rcl->roleid] = array($rcl->contextlevel);
969 } else if (!in_array($rcl->contextlevel, $rolecontextlevels[$rcl->roleid])) {
970 $rolecontextlevels[$rcl->roleid][] = $rcl->contextlevel;
971 }
972 }
973
974 /// Put the data into the database.
975 foreach ($rolecontextlevels as $roleid => $contextlevels) {
976 set_role_contextlevels($roleid, $contextlevels);
977 }
978
979 /// Main savepoint reached
980 upgrade_main_savepoint($result, 2008110602);
981 }
982
06de498b 983 /// Remove any role overrides for moodle/site:doanything, or any permissions
984 /// for it in a role without legacy:admin.
985 if ($result && $oldversion < 2008110603) {
986 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
987
988 // Remove all overrides.
989 $DB->delete_records_select('role_capabilities', 'capability = ? AND contextid <> ?', array('moodle/site:doanything', $systemcontext->id));
990
991 // Get the ids of all the roles that are moodle/legacy:admin.
992 $adminroleids = $DB->get_records_menu('role_capabilities',
993 array('capability' => 'moodle/legacy:admin', 'permission' => 1, 'contextid' => $systemcontext->id),
994 '', 'id, roleid');
995
996 // Remove moodle/site:doanything from all other roles.
997 list($notroletest, $params) = $DB->get_in_or_equal($adminroleids, SQL_PARAMS_QM, '', false);
998 $DB->delete_records_select('role_capabilities', "roleid $notroletest AND capability = ? AND contextid = ?",
999 array_merge($params, array('moodle/site:doanything', $systemcontext->id)));
1000
1001 // Ensure that for all admin-y roles, the permission for moodle/site:doanything is 1
1002 list($isroletest, $params) = $DB->get_in_or_equal($adminroleids);
1003 $DB->set_field_select('role_capabilities', 'permission', 1,
1004 "roleid $isroletest AND capability = ? AND contextid = ?",
1005 array_merge($params, array('moodle/site:doanything', $systemcontext->id)));
1006
1007 // And for any admin-y roles where moodle/site:doanything is not set, set it.
1008 $doanythingroleids = $DB->get_records_menu('role_capabilities',
1009 array('capability' => 'moodle/site:doanything', 'permission' => 1, 'contextid' => $systemcontext->id),
1010 '', 'id, roleid');
1011 foreach ($adminroleids as $roleid) {
1012 if (!in_array($roleid, $doanythingroleids)) {
1013 $rc = new stdClass;
1014 $rc->contextid = $systemcontext->id;
1015 $rc->roleid = $roleid;
1016 $rc->capability = 'moodle/site:doanything';
1017 $rc->permission = 1;
1018 $rc->timemodified = time();
1019 $DB->insert_record('role_capabilities', $rc);
1020 }
1021 }
1022
1023 /// Main savepoint reached
1024 upgrade_main_savepoint($result, 2008110603);
1025 }
1026
9101efd3 1027 /// Drop the deprecated teacher, teachers, student and students columns from the course table.
1028 if ($result && $oldversion < 2008111200) {
1029 $table = new xmldb_table('course');
1030
1031 /// Conditionally launch drop field teacher
1032 $field = new xmldb_field('teacher');
1033 if ($dbman->field_exists($table, $field)) {
1034 $dbman->drop_field($table, $field);
1035 }
1036
1037 /// Conditionally launch drop field teacher
1038 $field = new xmldb_field('teachers');
1039 if ($dbman->field_exists($table, $field)) {
1040 $dbman->drop_field($table, $field);
1041 }
1042
1043 /// Conditionally launch drop field teacher
1044 $field = new xmldb_field('student');
1045 if ($dbman->field_exists($table, $field)) {
1046 $dbman->drop_field($table, $field);
1047 }
1048
1049 /// Conditionally launch drop field teacher
1050 $field = new xmldb_field('students');
1051 if ($dbman->field_exists($table, $field)) {
1052 $dbman->drop_field($table, $field);
1053 }
1054
1055 /// Main savepoint reached
1056 upgrade_main_savepoint($result, 2008111200);
1057 }
1058
40c792c3 1059/// Add a unique index to the role.name column.
1060 if ($result && $oldversion < 2008111800) {
1061
1062 /// Define index name (unique) to be added to role
1063 $table = new xmldb_table('role');
1064 $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name'));
1065
1066 /// Conditionally launch add index name
1067 if (!$dbman->index_exists($table, $index)) {
1068 $dbman->add_index($table, $index);
1069 }
1070
1071 /// Main savepoint reached
1072 upgrade_main_savepoint($result, 2008111800);
1073 }
1074
1075/// Add a unique index to the role.shortname column.
1076 if ($result && $oldversion < 2008111801) {
1077
1078 /// Define index shortname (unique) to be added to role
1079 $table = new xmldb_table('role');
1080 $index = new xmldb_index('shortname', XMLDB_INDEX_UNIQUE, array('shortname'));
1081
1082 /// Conditionally launch add index shortname
1083 if (!$dbman->index_exists($table, $index)) {
1084 $dbman->add_index($table, $index);
1085 }
1086
1087 /// Main savepoint reached
1088 upgrade_main_savepoint($result, 2008111801);
1089 }
1090
82bd6a5e 1091 if ($result && $oldversion < 2008120700) {
1092
1093 /// Changing precision of field shortname on table course_request to (100)
1094 $table = new xmldb_table('course_request');
1095 $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null, 'fullname');
1096
1097 /// Launch change of precision for field shortname
1098 $dbman->change_field_precision($table, $field);
1099
1100 /// Main savepoint reached
1101 upgrade_main_savepoint($result, 2008120700);
1102 }
1103
1104 /// For MDL-17501. Ensure that any role that has moodle/course:update also
1105 /// has moodle/course:visibility.
1106 if ($result && $oldversion < 2008120800) {
1107 /// Get the roles with 'moodle/course:update'.
1108 $systemcontext = get_context_instance(CONTEXT_SYSTEM);
1109 $roles = get_roles_with_capability('moodle/course:update', CAP_ALLOW, $systemcontext);
1110
1111 /// Give those roles 'moodle/course:visibility'.
1112 foreach ($roles as $role) {
1113 assign_capability('moodle/course:visibility', CAP_ALLOW, $role->id, $systemcontext->id);
1114 }
1115
1116 /// Force all sessions to refresh access data.
1117 mark_context_dirty($systemcontext->path);
1118
1119 /// Main savepoint reached
1120 upgrade_main_savepoint($result, 2008120800);
1121 }
1122
1123 if ($result && $oldversion < 2008120801) {
1124
1125 /// Changing precision of field shortname on table mnet_enrol_course to (100)
1126 $table = new xmldb_table('mnet_enrol_course');
1127 $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null, 'fullname');
1128
1129 /// Launch change of precision for field shortname
1130 $dbman->change_field_precision($table, $field);
1131
1132 /// Main savepoint reached
1133 upgrade_main_savepoint($result, 2008120801);
1134 }
1135
1136 if ($result && $oldversion < 2008121701) {
0953a4e7 1137
1138 /// Define field availablefrom to be added to course_modules
1139 $table = new xmldb_table('course_modules');
1140 $field = new xmldb_field('availablefrom', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionexpected');
1141
1142 /// Conditionally launch add field availablefrom
1143 if (!$dbman->field_exists($table, $field)) {
1144 $dbman->add_field($table, $field);
1145 }
1146
1147 /// Define field availableuntil to be added to course_modules
1148 $field = new xmldb_field('availableuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'availablefrom');
1149
1150 /// Conditionally launch add field availableuntil
1151 if (!$dbman->field_exists($table, $field)) {
1152 $dbman->add_field($table, $field);
1153 }
82bd6a5e 1154
0953a4e7 1155 /// Define field showavailability to be added to course_modules
1156 $field = new xmldb_field('showavailability', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'availableuntil');
1157
1158 /// Conditionally launch add field showavailability
1159 if (!$dbman->field_exists($table, $field)) {
1160 $dbman->add_field($table, $field);
1161 }
82bd6a5e 1162
0953a4e7 1163 /// Define table course_modules_availability to be created
1164 $table = new xmldb_table('course_modules_availability');
1165
1166 /// Adding fields to table course_modules_availability
1167 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1168 $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1169 $table->add_field('sourcecmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1170 $table->add_field('requiredcompletion', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null);
1171 $table->add_field('gradeitemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1172 $table->add_field('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
1173 $table->add_field('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
1174
1175 /// Adding keys to table course_modules_availability
1176 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
cbb17d54 1177 $table->add_key('coursemoduleid', XMLDB_KEY_FOREIGN, array('coursemoduleid'), 'course_modules', array('id'));
1178 $table->add_key('sourcecmid', XMLDB_KEY_FOREIGN, array('sourcecmid'), 'course_modules', array('id'));
1179 $table->add_key('gradeitemid', XMLDB_KEY_FOREIGN, array('gradeitemid'), 'grade_items', array('id'));
0953a4e7 1180
1181 /// Conditionally launch create table for course_modules_availability
1182 if (!$dbman->table_exists($table)) {
1183 $dbman->create_table($table);
1184 }
1185
82bd6a5e 1186 /// Changes to modinfo mean we need to rebuild course cache
1187 rebuild_course_cache(0,true);
9136a60c 1188
82bd6a5e 1189 /// For developer upgrades, turn on the conditional activities and completion
1190 /// features automatically (to gain more testing)
1191 if(debugging('',DEBUG_DEVELOPER)) {
1192 set_config('enableavailability',1);
1193 set_config('enablecompletion',1);
9136a60c 1194 }
1195
9d510a2e 1196 /// Main savepoint reached
82bd6a5e 1197 upgrade_main_savepoint($result, 2008121701);
9d510a2e 1198 }
1199
656be893 1200 if ($result && $oldversion < 2009010500) {
1201 /// clean up config table a bit
1202 unset_config('session_error_counter');
1203
1204 /// Main savepoint reached
1205 upgrade_main_savepoint($result, 2009010500);
1206 }
1207
1208 if ($result && $oldversion < 2009010600) {
1209
1210 /// Define field originalquestion to be dropped from question_states
1211 $table = new xmldb_table('question_states');
1212 $field = new xmldb_field('originalquestion');
1213
1214 /// Conditionally launch drop field originalquestion
1215 if ($dbman->field_exists($table, $field)) {
1216 $dbman->drop_field($table, $field);
1217 }
1218
1219 /// Main savepoint reached
1220 upgrade_main_savepoint($result, 2009010600);
1221 }
1222
1223 if ($result && $oldversion < 2009010601) {
1224
1225 /// Changing precision of field ip on table log to (45)
1226 $table = new xmldb_table('log');
1227 $field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, null, null, 'userid');
1228
1229 /// Launch change of precision for field ip
1230 $dbman->change_field_precision($table, $field);
1231
1232 /// Main savepoint reached
1233 upgrade_main_savepoint($result, 2009010601);
1234 }
1235
1236 if ($result && $oldversion < 2009010602) {
1237
1238 /// Changing precision of field lastip on table user to (45)
1239 $table = new xmldb_table('user');
1240 $field = new xmldb_field('lastip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, null, null, 'currentlogin');
1241
1242 /// Launch change of precision for field lastip
1243 $dbman->change_field_precision($table, $field);
1244
1245 /// Main savepoint reached
1246 upgrade_main_savepoint($result, 2009010602);
1247 }
1248
1249 if ($result && $oldversion < 2009010603) {
1250
1251 /// Changing precision of field ip_address on table mnet_host to (45)
1252 $table = new xmldb_table('mnet_host');
1253 $field = new xmldb_field('ip_address', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, null, null, 'wwwroot');
1254
1255 /// Launch change of precision for field ip_address
1256 $dbman->change_field_precision($table, $field);
1257
1258 /// Main savepoint reached
1259 upgrade_main_savepoint($result, 2009010603);
1260 }
1261
1262 if ($result && $oldversion < 2009010604) {
1263
1264 /// Changing precision of field ip on table mnet_log to (45)
1265 $table = new xmldb_table('mnet_log');
1266 $field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, null, null, 'userid');
1267
1268 /// Launch change of precision for field ip
1269 $dbman->change_field_precision($table, $field);
1270
1271 /// Main savepoint reached
1272 upgrade_main_savepoint($result, 2009010604);
1273 }
1274
4413941f 1275 if ($result && $oldversion < 2009010800) {
1276 /// Update the notifyloginfailures setting.
1277 if ($CFG->notifyloginfailures == 'mainadmin') {
1278 set_config('notifyloginfailures', get_admin()->username);
1279 } else if ($CFG->notifyloginfailures == 'alladmins') {
1280 set_config('notifyloginfailures', '$@ALL@$');
1281 } else {
1282 set_config('notifyloginfailures', '');
1283 }
1284
1285 /// Main savepoint reached
1286 upgrade_main_savepoint($result, 2009010800);
1287 }
1288
ab2eb65c 1289 if ($result && $oldversion < 2009011000) {
1290
1291 /// Changing nullability of field configdata on table block_instance to null
1292 $table = new xmldb_table('block_instance');
1293 $field = new xmldb_field('configdata');
1294 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'visible');
1295
1296 /// Launch change of nullability for field configdata
1297 $dbman->change_field_notnull($table, $field);
1298
1299 /// Main savepoint reached
1300 upgrade_main_savepoint($result, 2009011000);
1301 }
1302
1caea91e 1303 if ($result && $oldversion < 2009011100) {
1304 /// Remove unused settings
1305 unset_config('zip');
1306 unset_config('unzip');
1307 unset_config('adminblocks_initialised');
1308
1309 /// Main savepoint reached
1310 upgrade_main_savepoint($result, 2009011100);
1311 }
1312
eb6a973c 1313 if ($result && $oldversion < 2009011101) {
1314 /// Migrate backup settings to core plugin config table
1315 $configs = $DB->get_records('backup_config');
1316 foreach ($configs as $config) {
1317 set_config($config->name, $config->value, 'backup');
1318 }
1319
1320 /// Define table to be dropped
1321 $table = new xmldb_table('backup_config');
1322
1323 /// Launch drop table for old backup config
1324 $dbman->drop_table($table);
1325
1326 /// Main savepoint reached
1327 upgrade_main_savepoint($result, 2009011101);
1328 }
1329
301bf0b2 1330 if ($result && $oldversion < 2009011303) {
1331
1332 /// Define table config_log to be created
1333 $table = new xmldb_table('config_log');
1334
1335 /// Adding fields to table config_log
1336 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1337 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1338 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1339 $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null);
1340 $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null);
1341 $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
1342 $table->add_field('oldvalue', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
1343
1344 /// Adding keys to table config_log
1345 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1346 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1347
1348 /// Adding indexes to table config_log
1349 $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
1350
1351 /// Launch create table for config_log
1352 $dbman->create_table($table);
1353
1354 /// Main savepoint reached
1355 upgrade_main_savepoint($result, 2009011303);
1356 }
1357
b9fb7103 1358 if ($result && $oldversion < 2009011900) {
3f57bd45 1359
1360 /// Define table sessions2 to be dropped
1361 $table = new xmldb_table('sessions2');
1362
1363 /// Conditionally launch drop table for sessions
1364 if ($dbman->table_exists($table)) {
1365 $dbman->drop_table($table);
1366 }
1367
1368 /// Define table sessions to be dropped
1369 $table = new xmldb_table('sessions');
1370
1371 /// Conditionally launch drop table for sessions
1372 if ($dbman->table_exists($table)) {
1373 $dbman->drop_table($table);
1374 }
1375
1376 /// Define table sessions to be created
1377 $table = new xmldb_table('sessions');
1378
1379 /// Adding fields to table sessions
1380 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1381 $table->add_field('state', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1382 $table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null, null, null);
1383 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1384 $table->add_field('sessdata', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
3f57bd45 1385 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1386 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1387 $table->add_field('firstip', XMLDB_TYPE_CHAR, '45', null, null, null, null, null, null);
1388 $table->add_field('lastip', XMLDB_TYPE_CHAR, '45', null, null, null, null, null, null);
1389
1390 /// Adding keys to table sessions
1391 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1392 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1393
1394 /// Adding indexes to table sessions
1395 $table->add_index('state', XMLDB_INDEX_NOTUNIQUE, array('state'));
1396 $table->add_index('sid', XMLDB_INDEX_UNIQUE, array('sid'));
1397 $table->add_index('timecreated', XMLDB_INDEX_NOTUNIQUE, array('timecreated'));
1398 $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
1399
1400 /// Launch create table for sessions
1401 $dbman->create_table($table);
1402
1403 /// Main savepoint reached
b9fb7103 1404 upgrade_main_savepoint($result, 2009011900);
3f57bd45 1405 }
1406
dc6f76b9 1407 if ($result && $oldversion < 2009012901) {
795a08ad 1408 // NOTE: this table may already exist, see beginning of this file ;-)
1f20942c 1409
1410 /// Define table upgrade_log to be created
1411 $table = new xmldb_table('upgrade_log');
1412
1413 /// Adding fields to table upgrade_log
1414 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1415 $table->add_field('type', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
1416 $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null);
dc6f76b9 1417 $table->add_field('version', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null);
1f20942c 1418 $table->add_field('info', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1419 $table->add_field('details', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
1420 $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
1421 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1422 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1423
1424 /// Adding keys to table upgrade_log
1425 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1426 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1427
1428 /// Adding indexes to table upgrade_log
1429 $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
1430 $table->add_index('type-timemodified', XMLDB_INDEX_NOTUNIQUE, array('type', 'timemodified'));
1431
1432 /// Conditionally launch create table for upgrade_log
1433 if (!$dbman->table_exists($table)) {
1434 $dbman->create_table($table);
1435 }
1436
1437 /// Main savepoint reached
dc6f76b9 1438 upgrade_main_savepoint($result, 2009012901);
1f20942c 1439 }
1caea91e 1440
ac9b0805 1441 return $result;
4e423cbf 1442}
271e6dec 1443
1444
4e423cbf 1445?>