upgrade.php 268 KB
Newer Older
1
<?php
2

3
// This file is part of Moodle - http://moodle.org/
4
//
5
6
7
8
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
9
//
10
11
12
13
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
14
//
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * This file keeps track of upgrades to Moodle.
 *
 * Sometimes, changes between versions involve
 * alterations to database structures and other
 * major things that may break installations.
 *
 * The upgrade function in this file will attempt
 * to perform all the necessary actions to upgrade
 * your older installation to the current version.
 *
 * If there's something it cannot do itself, it
 * will tell you what you need to do.
 *
 * The commands in here will all be database-neutral,
 * using the methods of database_manager class
 *
 * Please do not forget to use upgrade_set_timeout()
 * before any action that may take longer time to finish.
 *
 * @package    core
 * @subpackage admin
 * @copyright  2006 onwards Martin Dougiamas  http://dougiamas.com
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

defined('MOODLE_INTERNAL') || die();
45

46
47
48
49
50
51
52
/**
 *
 * @global stdClass $CFG
 * @global stdClass $USER
 * @global moodle_database $DB
 * @global core_renderer $OUTPUT
 * @param int $oldversion
53
 * @return bool always true
54
 */
55
function xmldb_main_upgrade($oldversion) {
56
    global $CFG, $USER, $DB, $OUTPUT;
57

58
    require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions
59

stronk7's avatar
stronk7 committed
60
    $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
61

62
63
64
    ////////////////////////////////////////
    ///upgrade supported only from 1.9.x ///
    ////////////////////////////////////////
65

66
    if ($oldversion < 2008030600) {
67
        //NOTE: this table was added much later later in dev cycle, but we need it here, upgrades from pre PR1 not supported
68
69
70
71
72

    /// Define table upgrade_log to be created
        $table = new xmldb_table('upgrade_log');

    /// Adding fields to table upgrade_log
73
74
75
76
77
78
79
80
81
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('type', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null);
        $table->add_field('version', XMLDB_TYPE_CHAR, '100', null, null, null, null);
        $table->add_field('info', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('details', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
        $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
82
83
84
85
86
87
88
89
90
91
92
93
94

    /// Adding keys to table upgrade_log
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));

    /// Adding indexes to table upgrade_log
        $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
        $table->add_index('type-timemodified', XMLDB_INDEX_NOTUNIQUE, array('type', 'timemodified'));

    /// Create table for upgrade_log
        $dbman->create_table($table);

    /// Main savepoint reached
95
        upgrade_main_savepoint(true, 2008030600);
96
97
    }

98
    if ($oldversion < 2008030601) {
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
        //NOTE: this table was added much later later in dev cycle, but we need it here, upgrades from pre PR1 not supported

    /// Define table log_queries to be created
        $table = new xmldb_table('log_queries');

    /// Adding fields to table log_queries
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('qtype', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('sqltext', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null);
        $table->add_field('sqlparams', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
        $table->add_field('error', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('info', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
        $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
        $table->add_field('exectime', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null);
        $table->add_field('timelogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);

    /// Adding keys to table log_queries
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));

    /// Conditionally launch create table for log_queries
        $dbman->create_table($table);

    /// Main savepoint reached
        upgrade_main_savepoint(true, 2008030601);
    }

    if ($oldversion < 2008030602) {
126
127
        @unlink($CFG->dataroot.'/cache/languages');

128
129
130
131
132
133
134
        if (file_exists("$CFG->dataroot/lang")) {
            // rename old lang directory so that the new and old langs do not mix
            if (rename("$CFG->dataroot/lang", "$CFG->dataroot/oldlang")) {
                $oldlang = "$CFG->dataroot/oldlang";
            } else {
                $oldlang = "$CFG->dataroot/lang";
            }
135
        } else {
136
            $oldlang = '';
137
138
139
140
141
142
143
144
145
        }
        // TODO: fetch previously installed languages ("*_utf8") found in $oldlang from moodle.org
        upgrade_set_timeout(60*20); // this may take a while


        // TODO: add some info file to $oldlang describing what to do with "$oldlang/*_utf8_local" dirs


        // Main savepoint reached
146
        upgrade_main_savepoint(true, 2008030602);
147
148
    }

149
    if ($oldversion < 2008030700) {
150
        upgrade_set_timeout(60*20); // this may take a while
151
152

    /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters
153
        $table = new xmldb_table('grade_letters');
154
        $index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
155
156

    /// Launch drop index contextid-lowerboundary
157
158
159
        if ($dbman->index_exists($table, $index)) {
            $dbman->drop_index($table, $index);
        }
160
161

    /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
162
        $table = new xmldb_table('grade_letters');
163
        $index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
164
165

    /// Launch add index contextid-lowerboundary-letter
skodak's avatar
skodak committed
166
        $dbman->add_index($table, $index);
167
168

    /// Main savepoint reached
169
        upgrade_main_savepoint(true, 2008030700);
170
    }
171

172
    if ($oldversion < 2008050100) {
173
        // Update courses that used weekscss to weeks
174
        $DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss'));
175
        upgrade_main_savepoint(true, 2008050100);
176
177
    }

178
    if ($oldversion < 2008050200) {
179
180
        // remove unused config options
        unset_config('statsrolesupgraded');
181
        upgrade_main_savepoint(true, 2008050200);
182
183
    }

184
    if ($oldversion < 2008050700) {
185
186
        upgrade_set_timeout(60*20); // this may take a while

187
188
    /// Fix minor problem caused by MDL-5482.
        require_once($CFG->dirroot . '/question/upgrade.php');
189
        question_fix_random_question_parents();
190
        upgrade_main_savepoint(true, 2008050700);
191
192
    }

193
    if ($oldversion < 2008051201) {
194
        echo $OUTPUT->notification('Increasing size of user idnumber field, this may take a while...', 'notifysuccess');
195
        upgrade_set_timeout(60*20); // this may take a while
196

197
    /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859
198
199
        $dbfamily = $DB->get_dbfamily();
        if ($dbfamily === 'mysql' || $dbfamily === 'postgres') {
skodak's avatar
skodak committed
200
            $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL");
201
202
        }

203
    /// Define index idnumber (not unique) to be dropped form user
204
        $table = new xmldb_table('user');
205
        $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
206
207

    /// Launch drop index idnumber
208
        if ($dbman->index_exists($table, $index)) {
skodak's avatar
skodak committed
209
            $dbman->drop_index($table, $index);
210
211
212
        }

    /// Changing precision of field idnumber on table user to (255)
213
        $table = new xmldb_table('user');
214
        $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'password');
215
216

    /// Launch change of precision for field idnumber
skodak's avatar
skodak committed
217
        $dbman->change_field_precision($table, $field);
218
219

    /// Launch add index idnumber again
220
        $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
skodak's avatar
skodak committed
221
        $dbman->add_index($table, $index);
222
223

    /// Main savepoint reached
224
        upgrade_main_savepoint(true, 2008051201);
225
226
    }

227
    if ($oldversion < 2008051203) {
228
        $table = new xmldb_table('mnet_enrol_course');
229
        $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
skodak's avatar
skodak committed
230
        $dbman->change_field_precision($table, $field);
231
        upgrade_main_savepoint(true, 2008051203);
232
233
    }

234
    if ($oldversion < 2008063001) {
235
236
        upgrade_set_timeout(60*20); // this may take a while

237
238
239
240
241
        // table to be modified
        $table = new xmldb_table('tag_instance');
        // add field
        $field = new xmldb_field('tiuserid');
        if (!$dbman->field_exists($table, $field)) {
242
            $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'itemid');
243
244
245
246
247
            $dbman->add_field($table, $field);
        }
        // modify index
        $index = new xmldb_index('itemtype-itemid-tagid');
        $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));
248
249
250
        if ($dbman->index_exists($table, $index)) {
            $dbman->drop_index($table, $index);
        }
251
252
        $index = new xmldb_index('itemtype-itemid-tagid-tiuserid');
        $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
253
254
255
        if (!$dbman->index_exists($table, $index)) {
            $dbman->add_index($table, $index);
        }
256
257

        /// Main savepoint reached
258
        upgrade_main_savepoint(true, 2008063001);
259
260
    }

261
    if ($oldversion < 2008070300) {
262
        $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false));
263
        upgrade_main_savepoint(true, 2008070300);
264
    }
sam_marshall's avatar
sam_marshall committed
265

266
    if ($oldversion < 2008070701) {
267
268
269
270
271

    /// Define table portfolio_instance to be created
        $table = new xmldb_table('portfolio_instance');

    /// Adding fields to table portfolio_instance
272
273
274
275
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
276
277
278
279
280
281
282
283
284
285
286
287

    /// Adding keys to table portfolio_instance
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));

    /// Conditionally launch create table for portfolio_instance
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
  /// Define table portfolio_instance_config to be created
        $table = new xmldb_table('portfolio_instance_config');

    /// Adding fields to table portfolio_instance_config
288
289
290
291
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308

    /// Adding keys to table portfolio_instance_config
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));

    /// Adding indexes to table portfolio_instance_config
        $table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name'));

    /// Conditionally launch create table for portfolio_instance_config
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }

   /// Define table portfolio_instance_user to be created
        $table = new xmldb_table('portfolio_instance_user');

    /// Adding fields to table portfolio_instance_user
309
310
311
312
313
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
        $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
314
315
316
317
318
319
320
321
322
323
324
325

    /// Adding keys to table portfolio_instance_user
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->add_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
        $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));

    /// Conditionally launch create table for portfolio_instance_user
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }

    /// Main savepoint reached
326
        upgrade_main_savepoint(true, 2008070701);
327
    }
328

329
    if ($oldversion < 2008072400) {
330
    /// Create the database tables for message_processors
331
        $table = new xmldb_table('message_processors');
332
333
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null);
334
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
335
336
337
        $dbman->create_table($table);

    /// delete old and create new fields
338
339
        $table = new xmldb_table('message');
        $field = new xmldb_field('messagetype');
340
341
342
        $dbman->drop_field($table, $field);

    /// fields to rename
343
        $field = new xmldb_field('message');
344
        $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
345
        $dbman->rename_field($table, $field, 'fullmessage');
346
        $field = new xmldb_field('format');
347
        $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null);
348
349
350
        $dbman->rename_field($table, $field, 'fullmessageformat');

    /// new message fields
351
        $field = new xmldb_field('subject');
352
        $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
353
        $dbman->add_field($table, $field);
354
        $field = new xmldb_field('fullmessagehtml');
355
        $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null);
356
        $dbman->add_field($table, $field);
357
        $field = new xmldb_field('smallmessage');
358
        $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
359
360
361
        $dbman->add_field($table, $field);


362
363
        $table = new xmldb_table('message_read');
        $field = new xmldb_field('messagetype');
364
        $dbman->drop_field($table, $field);
365
        $field = new xmldb_field('mailed');
366
367
368
        $dbman->drop_field($table, $field);

    /// fields to rename
369
        $field = new xmldb_field('message');
370
        $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
371
        $dbman->rename_field($table, $field, 'fullmessage');
372
        $field = new xmldb_field('format');
373
        $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null);
374
375
376
377
        $dbman->rename_field($table, $field, 'fullmessageformat');


    /// new message fields
378
        $field = new xmldb_field('subject');
379
        $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
380
        $dbman->add_field($table, $field);
381
        $field = new xmldb_field('fullmessagehtml');
382
        $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null);
383
        $dbman->add_field($table, $field);
384
        $field = new xmldb_field('smallmessage');
385
        $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
386
387
388
        $dbman->add_field($table, $field);

    /// new table
389
        $table = new xmldb_table('message_working');
390
391
392
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('unreadmessageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('processorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
393
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
394
395
396
        $dbman->create_table($table);


397
        upgrade_main_savepoint(true, 2008072400);
398
399
    }

400
    if ($oldversion < 2008072800) {
sam_marshall's avatar
sam_marshall committed
401
402
403
404

    /// Define field enablecompletion to be added to course
        $table = new xmldb_table('course');
        $field = new xmldb_field('enablecompletion');
405
        $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'defaultrole');
sam_marshall's avatar
sam_marshall committed
406
407

    /// Launch add field enablecompletion
408
        if (!$dbman->field_exists($table,$field)) {
sam_marshall's avatar
sam_marshall committed
409
410
            $dbman->add_field($table, $field);
        }
411

sam_marshall's avatar
sam_marshall committed
412
413
414
    /// Define field completion to be added to course_modules
        $table = new xmldb_table('course_modules');
        $field = new xmldb_field('completion');
415
        $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'groupmembersonly');
sam_marshall's avatar
sam_marshall committed
416
417

    /// Launch add field completion
418
        if (!$dbman->field_exists($table,$field)) {
sam_marshall's avatar
sam_marshall committed
419
420
421
422
423
            $dbman->add_field($table, $field);
        }

    /// Define field completiongradeitemnumber to be added to course_modules
        $field = new xmldb_field('completiongradeitemnumber');
424
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'completion');
sam_marshall's avatar
sam_marshall committed
425
426

    /// Launch add field completiongradeitemnumber
427
        if (!$dbman->field_exists($table,$field)) {
sam_marshall's avatar
sam_marshall committed
428
429
430
431
432
            $dbman->add_field($table, $field);
        }

    /// Define field completionview to be added to course_modules
        $field = new xmldb_field('completionview');
433
        $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completiongradeitemnumber');
sam_marshall's avatar
sam_marshall committed
434
435

    /// Launch add field completionview
436
        if (!$dbman->field_exists($table,$field)) {
sam_marshall's avatar
sam_marshall committed
437
438
439
440
441
            $dbman->add_field($table, $field);
        }

    /// Define field completionexpected to be added to course_modules
        $field = new xmldb_field('completionexpected');
442
        $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionview');
sam_marshall's avatar
sam_marshall committed
443
444

    /// Launch add field completionexpected
445
        if (!$dbman->field_exists($table,$field)) {
sam_marshall's avatar
sam_marshall committed
446
447
448
449
450
            $dbman->add_field($table, $field);
        }

   /// Define table course_modules_completion to be created
        $table = new xmldb_table('course_modules_completion');
451
        if (!$dbman->table_exists($table)) {
sam_marshall's avatar
sam_marshall committed
452
453

        /// Adding fields to table course_modules_completion
454
455
456
457
458
459
            $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
            $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
            $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
            $table->add_field('completionstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
            $table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null);
            $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
460

sam_marshall's avatar
sam_marshall committed
461
        /// Adding keys to table course_modules_completion
462
            $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
463

sam_marshall's avatar
sam_marshall committed
464
        /// Adding indexes to table course_modules_completion
465
466
            $table->add_index('coursemoduleid', XMLDB_INDEX_NOTUNIQUE, array('coursemoduleid'));
            $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
467

sam_marshall's avatar
sam_marshall committed
468
469
470
471
472
        /// Launch create table for course_modules_completion
            $dbman->create_table($table);
        }

        /// Main savepoint reached
473
        upgrade_main_savepoint(true, 2008072800);
sam_marshall's avatar
sam_marshall committed
474
    }
475

476
    if ($oldversion < 2008073000) {
477

478
479
480
481
    /// Define table portfolio_log to be created
        $table = new xmldb_table('portfolio_log');

    /// Adding fields to table portfolio_log
482
483
484
485
486
487
488
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('portfolio', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('caller_class', XMLDB_TYPE_CHAR, '150', null, XMLDB_NOTNULL, null, null);
        $table->add_field('caller_file', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('caller_sha1', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
489
490
491
        $table->add_field('tempdataid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
        $table->add_field('returnurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('continueurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
492
493
494
495
496
497
498
499
500
501
502
503

    /// Adding keys to table portfolio_log
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
        $table->add_key('portfoliofk', XMLDB_KEY_FOREIGN, array('portfolio'), 'portfolio_instance', array('id'));

    /// Conditionally launch create table for portfolio_log
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }

    /// Main savepoint reached
504
        upgrade_main_savepoint(true, 2008073000);
505
    }
506

507
    if ($oldversion < 2008073104) {
508
509
510
511
512
513
514
515
516
517
    /// Drop old table that might exist for some people
        $table = new xmldb_table('message_providers');
        if ($dbman->table_exists($table)) {
            $dbman->drop_table($table);
        }

    /// Define table message_providers to be created
        $table = new xmldb_table('message_providers');

    /// Adding fields to table message_providers
518
519
520
521
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
        $table->add_field('component', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
        $table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null);
522
523
524
525
526
527
528
529
530
531

    /// Adding keys to table message_providers
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));

    /// Adding indexes to table message_providers
        $table->add_index('componentname', XMLDB_INDEX_UNIQUE, array('component', 'name'));

    /// Create table for message_providers
        $dbman->create_table($table);

532
        upgrade_main_savepoint(true, 2008073104);
533
    }
534

535
    if ($oldversion < 2008073111) {
536
537
538
539
    /// Define table files to be created
        $table = new xmldb_table('files');

    /// Adding fields to table files
540
541
542
543
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
        $table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
        $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
544
        $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
545
546
547
548
549
550
551
552
        $table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
        $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('filepath', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('filename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
        $table->add_field('filesize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('mimetype', XMLDB_TYPE_CHAR, '100', null, null, null, null);
        $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
553
554
555
        $table->add_field('source', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
        $table->add_field('author', XMLDB_TYPE_CHAR, '255', null, null, null, null);
        $table->add_field('license', XMLDB_TYPE_CHAR, '255', null, null, null, null);
556
557
        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
558
559
560
561
562
563
564

    /// Adding keys to table files
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
        $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));

    /// Adding indexes to table files
565
        $table->add_index('component-filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('component', 'filearea', 'contextid', 'itemid'));
566
567
568
569
570
571
572
        $table->add_index('contenthash', XMLDB_INDEX_NOTUNIQUE, array('contenthash'));
        $table->add_index('pathnamehash', XMLDB_INDEX_UNIQUE, array('pathnamehash'));

    /// Conditionally launch create table for files
        $dbman->create_table($table);

    /// Main savepoint reached
573
        upgrade_main_savepoint(true, 2008073111);
574
575
    }

576
    if ($oldversion < 2008073112) {
577
578
579
580
581
582
583
584
585
586
        // Define field legacyfiles to be added to course
        $table = new xmldb_table('course');
        $field = new xmldb_field('legacyfiles', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'maxbytes');

        // Launch add field legacyfiles
        $dbman->add_field($table, $field);
        // enable legacy files in all courses
        $DB->execute("UPDATE {course} SET legacyfiles = 2");

        // Main savepoint reached
587
        upgrade_main_savepoint(true, 2008073112);
588
589
    }

590
    if ($oldversion < 2008073113) {
591
592
593
    /// move all course, backup and other files to new filepool based storage
        upgrade_migrate_files_courses();
    /// Main savepoint reached
594
        upgrade_main_savepoint(true, 2008073113);
595
596
    }

597
    if ($oldversion < 2008073114) {
598
599
600
    /// move all course, backup and other files to new filepool based storage
        upgrade_migrate_files_blog();
    /// Main savepoint reached
601
        upgrade_main_savepoint(true, 2008073114);
602
    }
603

604
    if ($oldversion < 2008080400) {
605
606
607
608
        // Add field ssl_jump_url to mnet application, and populate existing default applications
        $table = new xmldb_table('mnet_application');
        $field = new xmldb_field('sso_jump_url');
        if (!$dbman->field_exists($table, $field)) {
609
            $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
scyrma's avatar
scyrma committed
610
            $dbman->add_field($table, $field);
611
612
            $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle'));
            $DB->set_field('mnet_application', 'sso_jump_url', '/auth/xmlrpc/jump.php', array('name' => 'mahara'));
613
614
615
        }

        /// Main savepoint reached
616
        upgrade_main_savepoint(true, 2008080400);
617
    }
618

619
    if ($oldversion < 2008080500) {
620

Petr Skoda's avatar
Petr Skoda committed
621
    /// Define table portfolio_tempdata to be created
622
623
624
        $table = new xmldb_table('portfolio_tempdata');

    /// Adding fields to table portfolio_tempdata
625
626
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
627
628
629
        $table->add_field('expirytime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', null, null, null, '0');
630
631
632

    /// Adding keys to table portfolio_tempdata
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
633
634
        $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
        $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
635
636
637
638
639
640
641

    /// Conditionally launch create table for portfolio_tempdata
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }

    /// Main savepoint reached
642
        upgrade_main_savepoint(true, 2008080500);
643
644
    }

645
    if ($oldversion < 2008081500) {
646
647
    /// Changing the type of all the columns that the question bank uses to store grades to be NUMBER(12, 7).
        $table = new xmldb_table('question');
648
        $field = new xmldb_field('defaultgrade', XMLDB_TYPE_NUMBER, '12, 7', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1.0000000', 'generalfeedback');
649
        $dbman->change_field_type($table, $field);
650
        upgrade_main_savepoint(true, 2008081500);
651
652
    }

653
    if ($oldversion < 2008081501) {
654
        $table = new xmldb_table('question');
655
        $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0.1000000', 'defaultgrade');
656
        $dbman->change_field_type($table, $field);
657
        upgrade_main_savepoint(true, 2008081501);
658
659
    }

660
    if ($oldversion < 2008081502) {
661
        $table = new xmldb_table('question_answers');
662
        $field = new xmldb_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'answer');
663
        $dbman->change_field_type($table, $field);
664
        upgrade_main_savepoint(true, 2008081502);
665
666
    }

667
    if ($oldversion < 2008081503) {
668
        $table = new xmldb_table('question_sessions');
669
        $field = new xmldb_field('sumpenalty', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'newgraded');
670
        $dbman->change_field_type($table, $field);
671
        upgrade_main_savepoint(true, 2008081503);
672
673
    }

674
    if ($oldversion < 2008081504) {
675
        $table = new xmldb_table('question_states');
676
        $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'event');
677
        $dbman->change_field_type($table, $field);
678
        upgrade_main_savepoint(true, 2008081504);
679
680
    }

681
    if ($oldversion < 2008081505) {
682
        $table = new xmldb_table('question_states');
683
        $field = new xmldb_field('raw_grade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'grade');
684
        $dbman->change_field_type($table, $field);
685
        upgrade_main_savepoint(true, 2008081505);
686
687
    }

688
    if ($oldversion < 2008081506) {
689
        $table = new xmldb_table('question_states');
690
        $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'raw_grade');
691
        $dbman->change_field_type($table, $field);
692
        upgrade_main_savepoint(true, 2008081506);
693
694
    }

695
    if ($oldversion < 2008081600) {
696
697
698
699
700

    /// all 1.9 sites and fresh installs must already be unicode, not needed anymore
        unset_config('unicodedb');

    /// Main savepoint reached
701
        upgrade_main_savepoint(true, 2008081600);
702
703
    }

704
    if ($oldversion < 2008082602) {
dongsheng's avatar
dongsheng committed
705
706
707
708
709
710
711
712
713
714
715
716
717

    /// Define table repository to be dropped
        $table = new xmldb_table('repository');

    /// Conditionally launch drop table for repository
        if ($dbman->table_exists($table)) {
            $dbman->drop_table($table);
        }

    /// Define table repository to be created
        $table = new xmldb_table('repository');

    /// Adding fields to table repository
718
719
720
721
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '1');
        $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
dongsheng's avatar
dongsheng committed
722
723
724
725
726
727
728
729

    /// Adding keys to table repository
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));

    /// Conditionally launch create table for repository
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
730

dongsheng's avatar
dongsheng committed
731
732
733
734
    /// Define table repository_instances to be created
        $table = new xmldb_table('repository_instances');

    /// Adding fields to table repository_instances
735
736
737
738
739
740
741
742
743
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null);
        $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null);
        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
        $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
744
        $table->add_field('readonly', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
dongsheng's avatar
dongsheng committed
745
746
747
748
749
750
751
752
753
754
755
756
757

    /// Adding keys to table repository_instances
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));

    /// Conditionally launch create table for repository_instances
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }

    /// Define table repository_instance_config to be created
        $table = new xmldb_table('repository_instance_config');

    /// Adding fields to table repository_instance_config
758
759
760
761
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('instanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
        $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
        $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
dongsheng's avatar
dongsheng committed
762
763
764
765
766
767
768
769
770
771

    /// Adding keys to table repository_instance_config
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));

    /// Conditionally launch create table for repository_instance_config
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }

    /// Main savepoint reached
772
        upgrade_main_savepoint(true, 2008082602);
dongsheng's avatar
dongsheng committed
773
774
    }

775
    if ($oldversion < 2008082700) {
776
777
778
779
780
    /// Add a new column to the question sessions table to record whether a
    /// question has been flagged.

    /// Define field flagged to be added to question_sessions
        $table = new xmldb_table('question_sessions');
781
        $field = new xmldb_field('flagged', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'manualcomment');
782
783
784
785
786
787
788

    /// Conditionally launch add field flagged
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }

    /// Main savepoint reached
789
        upgrade_main_savepoint(true, 2008082700);
790
    }
791

792
    if ($oldversion < 2008082900) {
793
794
795

    /// Changing precision of field parent_type on table mnet_rpc to (20)
        $table = new xmldb_table('mnet_rpc');
796
        $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path');
797
798
799
800
801

    /// Launch change of precision for field parent_type
        $dbman->change_field_precision($table, $field);

    /// Main savepoint reached
802
        upgrade_main_savepoint(true, 2008082900);
803
804
    }

805
    // MDL-16411 Move all plugintype_pluginname_version values from config to config_plugins.
806
    if ($oldversion < 2008091000) {
807
808
809
810
811
812
813
814
815
816
817
818
819
        foreach (get_object_vars($CFG) as $name => $value) {
            if (substr($name, strlen($name) - 8) !== '_version') {
                continue;
            }
            $pluginname = substr($name, 0, strlen($name) - 8);
            if (!strpos($pluginname, '_')) {
                // Skip things like backup_version that don't contain an extra _
                continue;
            }
            if ($pluginname == 'enrol_ldap_version') {
                // Special case - this is something different from a plugin version number.
                continue;
            }
820
            if (!preg_match('/^\d{10}$/', $value)) {
821
822
823
824
                // Extra safety check, skip anything that does not look like a Moodle
                // version number (10 digits).
                continue;
            }
825
826
            set_config('version', $value, $pluginname);
            unset_config($name);
827
        }
828
        upgrade_main_savepoint(true, 2008091000);
829
830
    }

831
    if ($oldversion < 2008092300) {
832
833
834
        unset_config('editorspelling');
        unset_config('editordictionary');
    /// Main savepoint reached
835
        upgrade_main_savepoint(true, 2008092300);
836
837
    }

838
    if ($oldversion < 2008101300) {
839

dongsheng's avatar
dongsheng committed
840
        if (!get_config(NULL, 'statsruntimedays')) {
841
842
843
844
            set_config('statsruntimedays', '31');
        }

    /// Main savepoint reached
845
        upgrade_main_savepoint(true, 2008101300);
846
    }
847

848
    /// Drop the deprecated teacher, teachers, student and students columns from the course table.
849
    if ($oldversion < 2008111200) {
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
        $table = new xmldb_table('course');

    /// Conditionally launch drop field teacher
        $field = new xmldb_field('teacher');
        if ($dbman->field_exists($table, $field)) {
            $dbman->drop_field($table, $field);
        }

    /// Conditionally launch drop field teacher
        $field = new xmldb_field('teachers');
        if ($dbman->field_exists($table, $field)) {
            $dbman->drop_field($table, $field);
        }

    /// Conditionally launch drop field teacher
        $field = new xmldb_field('student');
        if ($dbman->field_exists($table, $field)) {
            $dbman->drop_field($table, $field);
        }

    /// Conditionally launch drop field teacher
        $field = new xmldb_field('students');
        if ($dbman->field_exists($table, $field)) {
            $dbman->drop_field($table, $field);
        }

    /// Main savepoint reached
877
        upgrade_main_savepoint(true, 2008111200);
878
879
    }

880
/// Add a unique index to the role.name column.
881
    if ($oldversion < 2008111800) {
882
883
884
885
886
887
888
889
890
891
892

    /// Define index name (unique) to be added to role
        $table = new xmldb_table('role');
        $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name'));

    /// Conditionally launch add index name
        if (!$dbman->index_exists($table, $index)) {
            $dbman->add_index($table, $index);
        }

    /// Main savepoint reached
893
        upgrade_main_savepoint(true, 2008111800);
894
895
896
    }

/// Add a unique index to the role.shortname column.
897
    if ($oldversion < 2008111801) {
898
899
900
901
902
903
904
905
906
907
908

    /// Define index shortname (unique) to be added to role
        $table = new xmldb_table('role');
        $index = new xmldb_index('shortname', XMLDB_INDEX_UNIQUE, array('shortname'));

    /// Conditionally launch add index shortname
        if (!$dbman->index_exists($table, $index)) {
            $dbman->add_index($table, $index);
        }

    /// Main savepoint reached
909
        upgrade_main_savepoint(true, 2008111801);
910
911
    }

912
    if ($oldversion < 2008120700) {
913
914
915

    /// Changing precision of field shortname on table course_request to (100)
        $table = new xmldb_table('course_request');
916
        $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname');
917

918
919
920
921
922
923
924
925
    /// Before changing the field, drop dependent indexes
    /// Define index shortname (not unique) to be dropped form course_request
        $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname'));
    /// Conditionally launch drop index shortname
        if ($dbman->index_exists($table, $index)) {
            $dbman->drop_index($table, $index);
        }

926
927
928
    /// Launch change of precision for field shortname
        $dbman->change_field_precision($table, $field);

929
930
931
932
933
934
935
936
    /// After changing the field, recreate dependent indexes
    /// Define index shortname (not unique) to be added to course_request
        $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname'));
    /// Conditionally launch add index shortname
        if (!$dbman->index_exists($table, $index)) {
            $dbman->add_index($table, $index);
        }

937
    /// Main savepoint reached
938
        upgrade_main_savepoint(true, 2008120700);
939
940
    }

941
    if ($oldversion < 2008120801) {
942
943
944

    /// Changing precision of field shortname on table mnet_enrol_course to (100)
        $table = new xmldb_table('mnet_enrol_course');
945
        $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname');
946
947
948
949
950

    /// Launch change of precision for field shortname
        $dbman->change_field_precision($table, $field);

    /// Main savepoint reached
951
        upgrade_main_savepoint(true, 2008120801);
952
953
    }

954
    if ($oldversion < 2008121701) {
955
956
957

    /// Define field availablefrom to be added to course_modules
        $table = new xmldb_table('course_modules');
958
        $field = new xmldb_field('availablefrom', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionexpected');
959
960
961
962
963
964
965

    /// Conditionally launch add field availablefrom
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }

    /// Define field availableuntil to be added to course_modules
stronk7's avatar