thumbnails -> icons
[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
a1f27717 33 if ($result && $oldversion < 2008030700) {
775f811a 34 upgrade_set_timeout(60*20); // this may take a while
a1f27717 35
36 /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters
a8cb94f6 37 $table = new xmldb_table('grade_letters');
69b80cc2 38 $index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
a1f27717 39
40 /// Launch drop index contextid-lowerboundary
eee5d9bb 41 $dbman->drop_index($table, $index);
a1f27717 42
a1f27717 43 /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
a8cb94f6 44 $table = new xmldb_table('grade_letters');
69b80cc2 45 $index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
a1f27717 46
47 /// Launch add index contextid-lowerboundary-letter
eee5d9bb 48 $dbman->add_index($table, $index);
a1f27717 49
50 /// Main savepoint reached
0f77b186 51 upgrade_main_savepoint($result, 2008030700);
52 }
a1f27717 53
1ea260d8 54 if ($result && $oldversion < 2008050100) {
55 // Update courses that used weekscss to weeks
a8cb94f6 56 $result = $DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss'));
1ea260d8 57 upgrade_main_savepoint($result, 2008050100);
58 }
59
0b51c247 60 if ($result && $oldversion < 2008050200) {
61 // remove unused config options
62 unset_config('statsrolesupgraded');
63 upgrade_main_savepoint($result, 2008050200);
64 }
65
994fbaab 66 if ($result && $oldversion < 2008050700) {
775f811a 67 upgrade_set_timeout(60*20); // this may take a while
68
994fbaab 69 /// Fix minor problem caused by MDL-5482.
70 require_once($CFG->dirroot . '/question/upgrade.php');
71 $result = $result && question_fix_random_question_parents();
72 upgrade_main_savepoint($result, 2008050700);
73 }
74
ab37dc60 75 if ($result && $oldversion < 2008051200) {
76 // if guest role used as default user role unset it and force admin to choose new setting
77 if (!empty($CFG->defaultuserroleid)) {
910dd4dd 78 if ($role = $DB->get_record('role', array('id'=>$CFG->defaultuserroleid))) {
ab37dc60 79 if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
80 if (isset($guestroles[$role->id])) {
81 set_config('defaultuserroleid', null);
82 notify('Guest role removed from "Default role for all users" setting, please select another role.', 'notifysuccess');
83 }
84 }
85 } else {
86 set_config('defaultuserroleid', null);
87 }
88 }
89 }
90
8b9cfac4 91 if ($result && $oldversion < 2008051201) {
92 notify('Increasing size of user idnumber field, this may take a while...', 'notifysuccess');
775f811a 93 upgrade_set_timeout(60*20); // this may take a while
8b9cfac4 94
469dcbcc 95 /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859
96 if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') {
eee5d9bb 97 $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL");
469dcbcc 98 }
99
8b9cfac4 100 /// Define index idnumber (not unique) to be dropped form user
a8cb94f6 101 $table = new xmldb_table('user');
69b80cc2 102 $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
8b9cfac4 103
104 /// Launch drop index idnumber
f33e1ed4 105 if ($dbman->index_exists($table, $index)) {
eee5d9bb 106 $dbman->drop_index($table, $index);
8b9cfac4 107 }
108
109 /// Changing precision of field idnumber on table user to (255)
a8cb94f6 110 $table = new xmldb_table('user');
69b80cc2 111 $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'password');
8b9cfac4 112
113 /// Launch change of precision for field idnumber
eee5d9bb 114 $dbman->change_field_precision($table, $field);
8b9cfac4 115
116 /// Launch add index idnumber again
69b80cc2 117 $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
eee5d9bb 118 $dbman->add_index($table, $index);
8b9cfac4 119
120 /// Main savepoint reached
121 upgrade_main_savepoint($result, 2008051201);
122 }
123
7ade55ad 124 if ($result && $oldversion < 2008051202) {
910dd4dd 125 $log_action = new object();
7ade55ad 126 $log_action->module = 'course';
127 $log_action->action = 'unenrol';
128 $log_action->mtable = 'course';
129 $log_action->field = 'fullname';
910dd4dd 130 if (!$DB->record_exists('log_display', array('action'=>'unenrol', 'module'=>'course'))) {
131 $result = $result && $DB->insert_record('log_display', $log_action);
7ade55ad 132 }
133 upgrade_main_savepoint($result, 2008051202);
134 }
135
fa162144 136 if ($result && $oldversion < 2008051203) {
137 $table = new xmldb_table('mnet_enrol_course');
138 $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', true, true, null, false, false, 0);
eee5d9bb 139 $dbman->change_field_precision($table, $field);
fa162144 140 upgrade_main_savepoint($result, 2008051203);
141 }
142
38fb8190 143 if ($result && $oldversion < 2008063001) {
775f811a 144 upgrade_set_timeout(60*20); // this may take a while
145
38fb8190 146 // table to be modified
147 $table = new xmldb_table('tag_instance');
148 // add field
149 $field = new xmldb_field('tiuserid');
150 if (!$dbman->field_exists($table, $field)) {
151 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0, 'itemid');
152 $dbman->add_field($table, $field);
153 }
154 // modify index
155 $index = new xmldb_index('itemtype-itemid-tagid');
156 $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));
157 $dbman->drop_index($table, $index);
158 $index = new xmldb_index('itemtype-itemid-tagid-tiuserid');
159 $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
160 $dbman->add_index($table, $index);
161
162 /// Main savepoint reached
163 upgrade_main_savepoint($result, 2008063001);
164 }
98978c2e 165 if ($result && $oldversion < 2008063002) {
166
167 /// Define table repository to be created
168 $table = new xmldb_table('repository');
169
170 /// Adding fields to table repository
171 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
172 $table->add_field('repositoryname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
173 $table->add_field('repositorytype', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
174 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
175 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
176 $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
177 $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
178 $table->add_field('data1', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
179 $table->add_field('data2', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
180 $table->add_field('data3', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
181 $table->add_field('data4', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
182 $table->add_field('data5', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
183 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
184 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
185
186 /// Adding keys to table repository
187 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
188
189 /// Conditionally launch create table for repository
190 if (!$dbman->table_exists($table)) {
191 $dbman->create_table($table);
192 }
38fb8190 193
98978c2e 194 /// Main savepoint reached
195 upgrade_main_savepoint($result, 2008063002);
196 }
38fb8190 197
a036d7f3 198 if ($result && $oldversion < 2008070300) {
199 $result = $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false));
200 upgrade_main_savepoint($result, 2008070300);
201 }
4e781c7b 202
fe074586 203 if ($result && $oldversion < 2008070700) {
204 if (isset($CFG->defaultuserroleid) and isset($CFG->guestroleid) and $CFG->defaultuserroleid == $CFG->guestroleid) {
205 // guest can not be selected in defaultuserroleid!
206 unset_config('defaultuserroleid');
207 }
208 upgrade_main_savepoint($result, 2008070700);
209 }
210
ac5efef6 211 if ($result && $oldversion < 2008070701) {
212
213 /// Define table portfolio_instance to be created
214 $table = new xmldb_table('portfolio_instance');
215
216 /// Adding fields to table portfolio_instance
217 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
218 $table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null);
219 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
220 $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1');
221
222 /// Adding keys to table portfolio_instance
223 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
224
225 /// Conditionally launch create table for portfolio_instance
226 if (!$dbman->table_exists($table)) {
227 $dbman->create_table($table);
228 }
229 /// Define table portfolio_instance_config to be created
230 $table = new xmldb_table('portfolio_instance_config');
231
232 /// Adding fields to table portfolio_instance_config
233 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
234 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
235 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
236 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
237
238 /// Adding keys to table portfolio_instance_config
239 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
240 $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
241
242 /// Adding indexes to table portfolio_instance_config
243 $table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name'));
244
245 /// Conditionally launch create table for portfolio_instance_config
246 if (!$dbman->table_exists($table)) {
247 $dbman->create_table($table);
248 }
249
250 /// Define table portfolio_instance_user to be created
251 $table = new xmldb_table('portfolio_instance_user');
252
253 /// Adding fields to table portfolio_instance_user
254 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
255 $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
256 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
257 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
258 $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
259
260 /// Adding keys to table portfolio_instance_user
261 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
262 $table->add_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
263 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
264
265 /// Conditionally launch create table for portfolio_instance_user
266 if (!$dbman->table_exists($table)) {
267 $dbman->create_table($table);
268 }
269
270 /// Main savepoint reached
271 upgrade_main_savepoint($result, 2008070701);
272 }
172dd12c 273
775f811a 274 if ($result && $oldversion < 2008072400) {
275 /// Create the database tables for message_processors
f65b2dae 276 $table = new xmldb_table('message_processors');
277 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
278 $table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null);
279 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3b120e46 280 $dbman->create_table($table);
281
3b120e46 282 /// delete old and create new fields
f65b2dae 283 $table = new xmldb_table('message');
284 $field = new xmldb_field('messagetype');
3b120e46 285 $dbman->drop_field($table, $field);
286
287 /// fields to rename
f65b2dae 288 $field = new xmldb_field('message');
289 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 290 $dbman->rename_field($table, $field, 'fullmessage');
f65b2dae 291 $field = new xmldb_field('format');
292 $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '0', null);
3b120e46 293 $dbman->rename_field($table, $field, 'fullmessageformat');
294
295 /// new message fields
f65b2dae 296 $field = new xmldb_field('subject');
297 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 298 $dbman->add_field($table, $field);
f65b2dae 299 $field = new xmldb_field('fullmessagehtml');
300 $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, null);
3b120e46 301 $dbman->add_field($table, $field);
f65b2dae 302 $field = new xmldb_field('smallmessage');
303 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 304 $dbman->add_field($table, $field);
305
306
f65b2dae 307 $table = new xmldb_table('message_read');
308 $field = new xmldb_field('messagetype');
3b120e46 309 $dbman->drop_field($table, $field);
f65b2dae 310 $field = new xmldb_field('mailed');
3b120e46 311 $dbman->drop_field($table, $field);
312
313 /// fields to rename
f65b2dae 314 $field = new xmldb_field('message');
315 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 316 $dbman->rename_field($table, $field, 'fullmessage');
f65b2dae 317 $field = new xmldb_field('format');
318 $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '0', null);
3b120e46 319 $dbman->rename_field($table, $field, 'fullmessageformat');
320
321
322 /// new message fields
f65b2dae 323 $field = new xmldb_field('subject');
324 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 325 $dbman->add_field($table, $field);
f65b2dae 326 $field = new xmldb_field('fullmessagehtml');
327 $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, null);
3b120e46 328 $dbman->add_field($table, $field);
f65b2dae 329 $field = new xmldb_field('smallmessage');
330 $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, null);
3b120e46 331 $dbman->add_field($table, $field);
332
333 /// new table
f65b2dae 334 $table = new xmldb_table('message_working');
335 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
336 $table->add_field('unreadmessageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
337 $table->add_field('processorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
338 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
3b120e46 339 $dbman->create_table($table);
340
341
342 upgrade_main_savepoint($result, 2008072400);
343 }
344
4e781c7b 345 if ($result && $oldversion < 2008072800) {
346
347 /// Define field enablecompletion to be added to course
348 $table = new xmldb_table('course');
349 $field = new xmldb_field('enablecompletion');
350 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'defaultrole');
351
352 /// Launch add field enablecompletion
775f811a 353 if (!$dbman->field_exists($table,$field)) {
4e781c7b 354 $dbman->add_field($table, $field);
355 }
775f811a 356
4e781c7b 357 /// Define field completion to be added to course_modules
358 $table = new xmldb_table('course_modules');
359 $field = new xmldb_field('completion');
360 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'groupmembersonly');
361
362 /// Launch add field completion
775f811a 363 if (!$dbman->field_exists($table,$field)) {
4e781c7b 364 $dbman->add_field($table, $field);
365 }
366
367 /// Define field completiongradeitemnumber to be added to course_modules
368 $field = new xmldb_field('completiongradeitemnumber');
369 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'completion');
370
371 /// Launch add field completiongradeitemnumber
775f811a 372 if (!$dbman->field_exists($table,$field)) {
4e781c7b 373 $dbman->add_field($table, $field);
374 }
375
376 /// Define field completionview to be added to course_modules
377 $field = new xmldb_field('completionview');
378 $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completiongradeitemnumber');
379
380 /// Launch add field completionview
775f811a 381 if (!$dbman->field_exists($table,$field)) {
4e781c7b 382 $dbman->add_field($table, $field);
383 }
384
385 /// Define field completionexpected to be added to course_modules
386 $field = new xmldb_field('completionexpected');
387 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionview');
388
389 /// Launch add field completionexpected
775f811a 390 if (!$dbman->field_exists($table,$field)) {
4e781c7b 391 $dbman->add_field($table, $field);
392 }
393
394 /// Define table course_modules_completion to be created
395 $table = new xmldb_table('course_modules_completion');
775f811a 396 if (!$dbman->table_exists($table)) {
4e781c7b 397
398 /// Adding fields to table course_modules_completion
1e0c56ea 399 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
400 $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
401 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
402 $table->add_field('completionstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
403 $table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null);
404 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
775f811a 405
4e781c7b 406 /// Adding keys to table course_modules_completion
1e0c56ea 407 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
775f811a 408
4e781c7b 409 /// Adding indexes to table course_modules_completion
1e0c56ea 410 $table->add_index('coursemoduleid', XMLDB_INDEX_NOTUNIQUE, array('coursemoduleid'));
411 $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
775f811a 412
4e781c7b 413 /// Launch create table for course_modules_completion
414 $dbman->create_table($table);
415 }
416
417 /// Main savepoint reached
418 upgrade_main_savepoint($result, 2008072800);
419 }
775f811a 420
4ab16a09 421 if ($result && $oldversion < 2008073000) {
ac5efef6 422
4ab16a09 423 /// Define table portfolio_log to be created
424 $table = new xmldb_table('portfolio_log');
425
426 /// Adding fields to table portfolio_log
427 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
428 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
429 $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
430 $table->add_field('portfolio', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
431 $table->add_field('caller_class', XMLDB_TYPE_CHAR, '150', null, XMLDB_NOTNULL, null, null, null, null);
432 $table->add_field('caller_file', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
433 $table->add_field('caller_sha1', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
434
435 /// Adding keys to table portfolio_log
436 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
437 $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
438 $table->add_key('portfoliofk', XMLDB_KEY_FOREIGN, array('portfolio'), 'portfolio_instance', array('id'));
439
440 /// Conditionally launch create table for portfolio_log
441 if (!$dbman->table_exists($table)) {
442 $dbman->create_table($table);
443 }
444
445 /// Main savepoint reached
446 upgrade_main_savepoint($result, 2008073000);
447 }
120b3758 448
449 if ($result && $oldversion < 2008073104) {
450 /// Drop old table that might exist for some people
451 $table = new xmldb_table('message_providers');
452 if ($dbman->table_exists($table)) {
453 $dbman->drop_table($table);
454 }
455
456 /// Define table message_providers to be created
457 $table = new xmldb_table('message_providers');
458
459 /// Adding fields to table message_providers
460 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
461 $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null);
462 $table->add_field('component', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null, null, null);
463 $table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
464
465 /// Adding keys to table message_providers
466 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
467
468 /// Adding indexes to table message_providers
469 $table->add_index('componentname', XMLDB_INDEX_UNIQUE, array('component', 'name'));
470
471 /// Create table for message_providers
472 $dbman->create_table($table);
473
474 upgrade_main_savepoint($result, 2008073104);
475 }
172dd12c 476
477 if ($result && $oldversion < 2008073111) {
478 /// Define table files to be created
479 $table = new xmldb_table('files');
480
481 /// Adding fields to table files
482 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
483 $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null);
484 $table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null);
485 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
486 $table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null);
487 $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
488 $table->add_field('filepath', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
489 $table->add_field('filename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
490 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
491 $table->add_field('filesize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
492 $table->add_field('mimetype', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null);
493 $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
494 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
495 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
496
497 /// Adding keys to table files
498 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
499 $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
500 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
501
502 /// Adding indexes to table files
503 $table->add_index('filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('filearea', 'contextid', 'itemid'));
504 $table->add_index('contenthash', XMLDB_INDEX_NOTUNIQUE, array('contenthash'));
505 $table->add_index('pathnamehash', XMLDB_INDEX_UNIQUE, array('pathnamehash'));
506
507 /// Conditionally launch create table for files
508 $dbman->create_table($table);
509
510 /// Main savepoint reached
511 upgrade_main_savepoint($result, 2008073111);
512 }
513
514 if ($result && $oldversion < 2008073112) {
515 /// Define table files_cleanup to be created
516 $table = new xmldb_table('files_cleanup');
517
518 /// Adding fields to table files_cleanup
519 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
520 $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null);
521
522 /// Adding keys to table files_cleanup
523 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
524
525 /// Adding indexes to table files_cleanup
526 $table->add_index('contenthash', XMLDB_INDEX_UNIQUE, array('contenthash'));
527
528 /// Conditionally launch create table for files_cleanup
529 $dbman->create_table($table);
530
531 /// Main savepoint reached
532 upgrade_main_savepoint($result, 2008073112);
533 }
534
535 if ($result && $oldversion < 2008073113) {
536 /// move all course, backup and other files to new filepool based storage
537 upgrade_migrate_files_courses();
538 /// Main savepoint reached
539 upgrade_main_savepoint($result, 2008073113);
540 }
541
542 if ($result && $oldversion < 2008073114) {
543 /// move all course, backup and other files to new filepool based storage
544 upgrade_migrate_files_blog();
545 /// Main savepoint reached
546 upgrade_main_savepoint($result, 2008073114);
547 }
f33e1ed4 548
1ce2da58 549 if ($result && $oldversion < 2008080400) {
550 // Add field ssl_jump_url to mnet application, and populate existing default applications
551 $table = new xmldb_table('mnet_application');
552 $field = new xmldb_field('sso_jump_url');
553 if (!$dbman->field_exists($table, $field)) {
554 $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
c5a04d12 555 $dbman->add_field($table, $field);
556 $result = $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle'));
1ce2da58 557 $result = $result && $DB->set_field('mnet_application', 'sso_jump_url', '/auth/xmlrpc/jump.php', array('name' => 'mahara'));
558 }
559
560 /// Main savepoint reached
561 upgrade_main_savepoint($result, 2008080400);
562 }
04f35360 563
564 if ($result && $oldversion < 2008080500) {
565
566 /// Define table portfolio_tempdata to be created
567 $table = new xmldb_table('portfolio_tempdata');
568
569 /// Adding fields to table portfolio_tempdata
570 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
571 $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null);
572
573 /// Adding keys to table portfolio_tempdata
574 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
575
576 /// Conditionally launch create table for portfolio_tempdata
577 if (!$dbman->table_exists($table)) {
578 $dbman->create_table($table);
579 }
580
581 /// Main savepoint reached
582 upgrade_main_savepoint($result, 2008080500);
583 }
584
84a44985 585 if ($result && $oldversion < 2008080600) {
586
587 $DB->delete_records('portfolio_tempdata'); // there shouldnt' be any, and it will cause problems with this upgrade.
588 /// Define field expirytime to be added to portfolio_tempdata
589 $table = new xmldb_table('portfolio_tempdata');
590 $field = new xmldb_field('expirytime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'data');
591
592 /// Conditionally launch add field expirytime
593 if (!$dbman->field_exists($table, $field)) {
594 $dbman->add_field($table, $field);
595 }
596
597 /// Main savepoint reached
598 upgrade_main_savepoint($result, 2008080600);
599 }
775f811a 600
348c350b 601 if ($result && $oldversion < 2008080701) {
602
603 /// Define field visible to be added to repository
604 $table = new xmldb_table('repository');
605 $field = new xmldb_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, '1', 'timemodified');
606
607 /// Conditionally launch add field visible
608 if (!$dbman->field_exists($table, $field)) {
609 $dbman->add_field($table, $field);
610 }
611
612 /// Main savepoint reached
613 upgrade_main_savepoint($result, 2008080701);
614 }
04f35360 615
f9a2cf86 616/// Changing the type of all the columns that the question bank uses to store grades to be NUMBER(12, 7).
617 if ($result && $oldversion < 2008081500) {
618 $table = new xmldb_table('question');
619 $field = new xmldb_field('defaultgrade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'generalfeedback');
620 $dbman->change_field_type($table, $field);
621 upgrade_main_savepoint($result, 2008081500);
622 }
623
624 if ($result && $oldversion < 2008081501) {
625 $table = new xmldb_table('question');
626 $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'defaultgrade');
627 $dbman->change_field_type($table, $field);
628 upgrade_main_savepoint($result, 2008081501);
629 }
630
631 if ($result && $oldversion < 2008081502) {
632 $table = new xmldb_table('question_answers');
633 $field = new xmldb_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'answer');
634 $dbman->change_field_type($table, $field);
635 upgrade_main_savepoint($result, 2008081502);
636 }
637
638 if ($result && $oldversion < 2008081503) {
639 $table = new xmldb_table('question_sessions');
640 $field = new xmldb_field('sumpenalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'newgraded');
641 $dbman->change_field_type($table, $field);
642 upgrade_main_savepoint($result, 2008081503);
643 }
644
645 if ($result && $oldversion < 2008081504) {
646 $table = new xmldb_table('question_states');
647 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'event');
648 $dbman->change_field_type($table, $field);
649 upgrade_main_savepoint($result, 2008081504);
650 }
651
652 if ($result && $oldversion < 2008081505) {
653 $table = new xmldb_table('question_states');
654 $field = new xmldb_field('raw_grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'grade');
655 $dbman->change_field_type($table, $field);
656 upgrade_main_savepoint($result, 2008081505);
657 }
658
659 if ($result && $oldversion < 2008081506) {
660 $table = new xmldb_table('question_states');
661 $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, null, null, 'raw_grade');
662 $dbman->change_field_type($table, $field);
663 upgrade_main_savepoint($result, 2008081506);
664 }
665
775f811a 666 if ($result && $oldversion < 2008081600) {
667
668 /// all 1.9 sites and fresh installs must already be unicode, not needed anymore
669 unset_config('unicodedb');
670
671 /// Main savepoint reached
672 upgrade_main_savepoint($result, 2008081600);
673 }
674
ff2f69bc 675 if ($result && $oldversion < 2008081900) {
676 /// Define field userid to be added to portfolio_tempdata
677 $table = new xmldb_table('portfolio_tempdata');
678 $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'expirytime');
679
680 /// Conditionally launch add field userid
681 if (!$dbman->field_exists($table, $field)) {
682 $dbman->add_field($table, $field);
683 }
684 $DB->set_field('portfolio_tempdata', 'userid', 0);
685 /// now change it to be notnull
686
687 /// Changing nullability of field userid on table portfolio_tempdata to not null
688 $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'expirytime');
689
690 /// Launch change of nullability for field userid
691 $dbman->change_field_notnull($table, $field);
692
693 /// Define key userfk (foreign) to be added to portfolio_tempdata
694 $table = new xmldb_table('portfolio_tempdata');
695 $key = new xmldb_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
696
697 /// Launch add key userfk
698 $dbman->add_key($table, $key);
699
700 upgrade_main_savepoint($result, 2008081900);
701 }
702
ac9b0805 703 return $result;
4e423cbf 704}
271e6dec 705
706
4e423cbf 707?>