MDL-11719 increased size of idnumber in user table - needed for some enrolment plugin...
[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,
17// using the functions defined in lib/ddllib.php
18
19
20function xmldb_main_upgrade($oldversion=0) {
21
8a45fcdf 22 global $CFG, $THEME, $USER, $db;
4e423cbf 23
24 $result = true;
25
1ea260d8 26 ////////////////////////////////////////
27 ///upgrade supported only from 1.9.x ///
28 ////////////////////////////////////////
da4aa3e4 29
a1f27717 30 if ($result && $oldversion < 2008030700) {
31
32 /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters
33 $table = new XMLDBTable('grade_letters');
34 $index = new XMLDBIndex('contextid-lowerboundary');
35 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
36
37 /// Launch drop index contextid-lowerboundary
38 $result = $result && drop_index($table, $index);
39
a1f27717 40 /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
41 $table = new XMLDBTable('grade_letters');
42 $index = new XMLDBIndex('contextid-lowerboundary-letter');
43 $index->setAttributes(XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
44
45 /// Launch add index contextid-lowerboundary-letter
46 $result = $result && add_index($table, $index);
47
48 /// Main savepoint reached
0f77b186 49 upgrade_main_savepoint($result, 2008030700);
50 }
a1f27717 51
1ea260d8 52 if ($result && $oldversion < 2008050100) {
53 // Update courses that used weekscss to weeks
54 $result = set_field('course', 'format', 'weeks', 'format', 'weekscss');
55 upgrade_main_savepoint($result, 2008050100);
56 }
57
0b51c247 58 if ($result && $oldversion < 2008050200) {
59 // remove unused config options
60 unset_config('statsrolesupgraded');
61 upgrade_main_savepoint($result, 2008050200);
62 }
63
994fbaab 64 if ($result && $oldversion < 2008050700) {
65 /// Fix minor problem caused by MDL-5482.
66 require_once($CFG->dirroot . '/question/upgrade.php');
67 $result = $result && question_fix_random_question_parents();
68 upgrade_main_savepoint($result, 2008050700);
69 }
70
ab37dc60 71 if ($result && $oldversion < 2008051200) {
72 // if guest role used as default user role unset it and force admin to choose new setting
73 if (!empty($CFG->defaultuserroleid)) {
74 if ($role = get_record('role', 'id', $CFG->defaultuserroleid)) {
75 if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
76 if (isset($guestroles[$role->id])) {
77 set_config('defaultuserroleid', null);
78 notify('Guest role removed from "Default role for all users" setting, please select another role.', 'notifysuccess');
79 }
80 }
81 } else {
82 set_config('defaultuserroleid', null);
83 }
84 }
85 }
86
8b9cfac4 87 if ($result && $oldversion < 2008051201) {
88 notify('Increasing size of user idnumber field, this may take a while...', 'notifysuccess');
89
90 /// Define index idnumber (not unique) to be dropped form user
91 $table = new XMLDBTable('user');
92 $index = new XMLDBIndex('idnumber');
93 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
94
95 /// Launch drop index idnumber
96 if (index_exists($table, $index)) {
97 $result = $result && drop_index($table, $index);
98 }
99
100 /// Changing precision of field idnumber on table user to (255)
101 $table = new XMLDBTable('user');
102 $field = new XMLDBField('idnumber');
103 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'password');
104
105 /// Launch change of precision for field idnumber
106 $result = $result && change_field_precision($table, $field);
107
108 /// Launch add index idnumber again
109 $index = new XMLDBIndex('idnumber');
110 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
111 $result = $result && add_index($table, $index);
112
113 /// Main savepoint reached
114 upgrade_main_savepoint($result, 2008051201);
115 }
116
ac9b0805 117 return $result;
4e423cbf 118}
271e6dec 119
120
4e423cbf 121?>