XHTML Strrict!
[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
4e423cbf 18
19
20function xmldb_main_upgrade($oldversion=0) {
f33e1ed4 21 global $CFG, $THEME, $USER, $DB;
4e423cbf 22
23 $result = true;
24
46d318bc 25 $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
f33e1ed4 26
1ea260d8 27 ////////////////////////////////////////
28 ///upgrade supported only from 1.9.x ///
29 ////////////////////////////////////////
da4aa3e4 30
a1f27717 31 if ($result && $oldversion < 2008030700) {
32
33 /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters
a8cb94f6 34 $table = new xmldb_table('grade_letters');
69b80cc2 35 $index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
a1f27717 36
37 /// Launch drop index contextid-lowerboundary
eee5d9bb 38 $dbman->drop_index($table, $index);
a1f27717 39
a1f27717 40 /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
a8cb94f6 41 $table = new xmldb_table('grade_letters');
69b80cc2 42 $index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
a1f27717 43
44 /// Launch add index contextid-lowerboundary-letter
eee5d9bb 45 $dbman->add_index($table, $index);
a1f27717 46
47 /// Main savepoint reached
0f77b186 48 upgrade_main_savepoint($result, 2008030700);
49 }
a1f27717 50
1ea260d8 51 if ($result && $oldversion < 2008050100) {
52 // Update courses that used weekscss to weeks
a8cb94f6 53 $result = $DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss'));
1ea260d8 54 upgrade_main_savepoint($result, 2008050100);
55 }
56
0b51c247 57 if ($result && $oldversion < 2008050200) {
58 // remove unused config options
59 unset_config('statsrolesupgraded');
60 upgrade_main_savepoint($result, 2008050200);
61 }
62
994fbaab 63 if ($result && $oldversion < 2008050700) {
64 /// Fix minor problem caused by MDL-5482.
65 require_once($CFG->dirroot . '/question/upgrade.php');
66 $result = $result && question_fix_random_question_parents();
67 upgrade_main_savepoint($result, 2008050700);
68 }
69
ab37dc60 70 if ($result && $oldversion < 2008051200) {
71 // if guest role used as default user role unset it and force admin to choose new setting
72 if (!empty($CFG->defaultuserroleid)) {
910dd4dd 73 if ($role = $DB->get_record('role', array('id'=>$CFG->defaultuserroleid))) {
ab37dc60 74 if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
75 if (isset($guestroles[$role->id])) {
76 set_config('defaultuserroleid', null);
77 notify('Guest role removed from "Default role for all users" setting, please select another role.', 'notifysuccess');
78 }
79 }
80 } else {
81 set_config('defaultuserroleid', null);
82 }
83 }
84 }
85
8b9cfac4 86 if ($result && $oldversion < 2008051201) {
87 notify('Increasing size of user idnumber field, this may take a while...', 'notifysuccess');
88
469dcbcc 89 /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859
90 if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') {
eee5d9bb 91 $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL");
469dcbcc 92 }
93
8b9cfac4 94 /// Define index idnumber (not unique) to be dropped form user
a8cb94f6 95 $table = new xmldb_table('user');
69b80cc2 96 $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
8b9cfac4 97
98 /// Launch drop index idnumber
f33e1ed4 99 if ($dbman->index_exists($table, $index)) {
eee5d9bb 100 $dbman->drop_index($table, $index);
8b9cfac4 101 }
102
103 /// Changing precision of field idnumber on table user to (255)
a8cb94f6 104 $table = new xmldb_table('user');
69b80cc2 105 $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'password');
8b9cfac4 106
107 /// Launch change of precision for field idnumber
eee5d9bb 108 $dbman->change_field_precision($table, $field);
8b9cfac4 109
110 /// Launch add index idnumber again
69b80cc2 111 $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
eee5d9bb 112 $dbman->add_index($table, $index);
8b9cfac4 113
114 /// Main savepoint reached
115 upgrade_main_savepoint($result, 2008051201);
116 }
117
7ade55ad 118 if ($result && $oldversion < 2008051202) {
910dd4dd 119 $log_action = new object();
7ade55ad 120 $log_action->module = 'course';
121 $log_action->action = 'unenrol';
122 $log_action->mtable = 'course';
123 $log_action->field = 'fullname';
910dd4dd 124 if (!$DB->record_exists('log_display', array('action'=>'unenrol', 'module'=>'course'))) {
125 $result = $result && $DB->insert_record('log_display', $log_action);
7ade55ad 126 }
127 upgrade_main_savepoint($result, 2008051202);
128 }
129
fa162144 130 if ($result && $oldversion < 2008051203) {
131 $table = new xmldb_table('mnet_enrol_course');
132 $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', true, true, null, false, false, 0);
eee5d9bb 133 $dbman->change_field_precision($table, $field);
fa162144 134 upgrade_main_savepoint($result, 2008051203);
135 }
136
38fb8190 137 if ($result && $oldversion < 2008063001) {
138 // table to be modified
139 $table = new xmldb_table('tag_instance');
140 // add field
141 $field = new xmldb_field('tiuserid');
142 if (!$dbman->field_exists($table, $field)) {
143 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0, 'itemid');
144 $dbman->add_field($table, $field);
145 }
146 // modify index
147 $index = new xmldb_index('itemtype-itemid-tagid');
148 $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));
149 $dbman->drop_index($table, $index);
150 $index = new xmldb_index('itemtype-itemid-tagid-tiuserid');
151 $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
152 $dbman->add_index($table, $index);
153
154 /// Main savepoint reached
155 upgrade_main_savepoint($result, 2008063001);
156 }
98978c2e 157 if ($result && $oldversion < 2008063002) {
158
159 /// Define table repository to be created
160 $table = new xmldb_table('repository');
161
162 /// Adding fields to table repository
163 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
164 $table->add_field('repositoryname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
165 $table->add_field('repositorytype', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
166 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
167 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
168 $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
169 $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
170 $table->add_field('data1', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
171 $table->add_field('data2', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
172 $table->add_field('data3', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
173 $table->add_field('data4', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
174 $table->add_field('data5', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
175 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
176 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
177
178 /// Adding keys to table repository
179 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
180
181 /// Conditionally launch create table for repository
182 if (!$dbman->table_exists($table)) {
183 $dbman->create_table($table);
184 }
38fb8190 185
98978c2e 186 /// Main savepoint reached
187 upgrade_main_savepoint($result, 2008063002);
188 }
38fb8190 189
a036d7f3 190 if ($result && $oldversion < 2008070300) {
191 $result = $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false));
192 upgrade_main_savepoint($result, 2008070300);
193 }
4e781c7b 194
fe074586 195 if ($result && $oldversion < 2008070700) {
196 if (isset($CFG->defaultuserroleid) and isset($CFG->guestroleid) and $CFG->defaultuserroleid == $CFG->guestroleid) {
197 // guest can not be selected in defaultuserroleid!
198 unset_config('defaultuserroleid');
199 }
200 upgrade_main_savepoint($result, 2008070700);
201 }
202
ac5efef6 203 if ($result && $oldversion < 2008070701) {
204
205 /// Define table portfolio_instance to be created
206 $table = new xmldb_table('portfolio_instance');
207
208 /// Adding fields to table portfolio_instance
209 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
210 $table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null);
211 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
212 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1');
213
214 /// Adding keys to table portfolio_instance
215 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
216
217 /// Conditionally launch create table for portfolio_instance
218 if (!$dbman->table_exists($table)) {
219 $dbman->create_table($table);
220 }
221 /// Define table portfolio_instance_config to be created
222 $table = new xmldb_table('portfolio_instance_config');
223
224 /// Adding fields to table portfolio_instance_config
225 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
226 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
227 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
228 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
229
230 /// Adding keys to table portfolio_instance_config
231 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
232 $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
233
234 /// Adding indexes to table portfolio_instance_config
235 $table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name'));
236
237 /// Conditionally launch create table for portfolio_instance_config
238 if (!$dbman->table_exists($table)) {
239 $dbman->create_table($table);
240 }
241
242 /// Define table portfolio_instance_user to be created
243 $table = new xmldb_table('portfolio_instance_user');
244
245 /// Adding fields to table portfolio_instance_user
246 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
247 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
248 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
249 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
250 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
251
252 /// Adding keys to table portfolio_instance_user
253 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
254 $table->add_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
255 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
256
257 /// Conditionally launch create table for portfolio_instance_user
258 if (!$dbman->table_exists($table)) {
259 $dbman->create_table($table);
260 }
261
262 /// Main savepoint reached
263 upgrade_main_savepoint($result, 2008070701);
264 }
3b120e46 265
266 if ($result && $oldversion < 2008072400) {
172dd12c 267 /// Create the database tables for message_processors and message_providers
268 $table = new xmldb_table('message_providers');
269 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
270 $table->add_field('modulename', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null);
271 $table->add_field('modulefile', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
272 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
273 $dbman->create_table($table);
274
f65b2dae 275 $table = new xmldb_table('message_processors');
276 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
277 $table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null);
278 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3b120e46 279 $dbman->create_table($table);
280
172dd12c 281
282 $provider = new object();
283 $provider->modulename = 'moodle';
284 $provider->modulefile = 'index.php';
285 $DB->insert_record('message_providers', $provider);
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
358 if(!$dbman->field_exists($table,$field)) {
359 $dbman->add_field($table, $field);
360 }
361
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
368 if(!$dbman->field_exists($table,$field)) {
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
377 if(!$dbman->field_exists($table,$field)) {
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
386 if(!$dbman->field_exists($table,$field)) {
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
395 if(!$dbman->field_exists($table,$field)) {
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');
401 if(!$dbman->table_exists($table)) {
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);
4e781c7b 410
411 /// Adding keys to table course_modules_completion
1e0c56ea 412 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
4e781c7b 413
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'));
4e781c7b 417
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 }
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 }
348c350b 605 if ($result && $oldversion < 2008080701) {
606
607 /// Define field visible to be added to repository
608 $table = new xmldb_table('repository');
609 $field = new xmldb_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, '1', 'timemodified');
610
611 /// Conditionally launch add field visible
612 if (!$dbman->field_exists($table, $field)) {
613 $dbman->add_field($table, $field);
614 }
615
616 /// Main savepoint reached
617 upgrade_main_savepoint($result, 2008080701);
618 }
04f35360 619
ac9b0805 620 return $result;
4e423cbf 621}
271e6dec 622
623
4e423cbf 624?>