Commit | Line | Data |
---|---|---|
117bd748 | 1 | <?PHP |
4e423cbf | 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 | |
3406acde SH |
22 | /** |
23 | * | |
24 | * @global stdClass $CFG | |
25 | * @global stdClass $USER | |
26 | * @global moodle_database $DB | |
27 | * @global core_renderer $OUTPUT | |
28 | * @param int $oldversion | |
29 | * @return bool | |
30 | */ | |
775f811a | 31 | function xmldb_main_upgrade($oldversion) { |
78946b9b | 32 | global $CFG, $USER, $DB, $OUTPUT; |
4e423cbf | 33 | |
4f12838e | 34 | require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions |
13a0d3d3 | 35 | |
4e423cbf | 36 | $result = true; |
37 | ||
46d318bc | 38 | $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes |
f33e1ed4 | 39 | |
1ea260d8 | 40 | //////////////////////////////////////// |
41 | ///upgrade supported only from 1.9.x /// | |
42 | //////////////////////////////////////// | |
da4aa3e4 | 43 | |
795a08ad | 44 | if ($result && $oldversion < 2008030600) { |
45 | //NOTE: this table was added much later, that is why this step is repeated later in this file | |
46 | ||
47 | /// Define table upgrade_log to be created | |
48 | $table = new xmldb_table('upgrade_log'); | |
49 | ||
50 | /// Adding fields to table upgrade_log | |
2a88f626 | 51 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
52 | $table->add_field('type', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); | |
53 | $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null); | |
54 | $table->add_field('version', XMLDB_TYPE_CHAR, '100', null, null, null, null); | |
55 | $table->add_field('info', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
56 | $table->add_field('details', XMLDB_TYPE_TEXT, 'small', null, null, null, null); | |
57 | $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null); | |
58 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
59 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
795a08ad | 60 | |
61 | /// Adding keys to table upgrade_log | |
62 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
63 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
64 | ||
65 | /// Adding indexes to table upgrade_log | |
66 | $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified')); | |
67 | $table->add_index('type-timemodified', XMLDB_INDEX_NOTUNIQUE, array('type', 'timemodified')); | |
68 | ||
69 | /// Create table for upgrade_log | |
70 | $dbman->create_table($table); | |
71 | ||
72 | /// Main savepoint reached | |
73 | upgrade_main_savepoint($result, 2008030600); | |
74 | } | |
75 | ||
3a915b06 PS |
76 | if ($result && $oldversion < 2008030601) { |
77 | @unlink($CFG->dataroot.'/cache/languages'); | |
78 | ||
79 | // rename old lang directory so that the new and old langs do not mix | |
80 | if (rename("$CFG->dataroot/lang", "$CFG->dataroot/oldlang")) { | |
81 | $oldlang = "$CFG->dataroot/oldlang"; | |
82 | } else { | |
83 | $oldlang = "$CFG->dataroot/lang"; | |
84 | } | |
85 | // TODO: fetch previously installed languages ("*_utf8") found in $oldlang from moodle.org | |
86 | upgrade_set_timeout(60*20); // this may take a while | |
87 | ||
88 | ||
89 | // TODO: add some info file to $oldlang describing what to do with "$oldlang/*_utf8_local" dirs | |
90 | ||
91 | ||
92 | // Main savepoint reached | |
93 | upgrade_main_savepoint($result, 2008030601); | |
94 | } | |
95 | ||
a1f27717 | 96 | if ($result && $oldversion < 2008030700) { |
775f811a | 97 | upgrade_set_timeout(60*20); // this may take a while |
a1f27717 | 98 | |
99 | /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters | |
a8cb94f6 | 100 | $table = new xmldb_table('grade_letters'); |
69b80cc2 | 101 | $index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary')); |
a1f27717 | 102 | |
103 | /// Launch drop index contextid-lowerboundary | |
5cada363 EL |
104 | if ($dbman->index_exists($table, $index)) { |
105 | $dbman->drop_index($table, $index); | |
106 | } | |
a1f27717 | 107 | |
a1f27717 | 108 | /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters |
a8cb94f6 | 109 | $table = new xmldb_table('grade_letters'); |
69b80cc2 | 110 | $index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter')); |
a1f27717 | 111 | |
112 | /// Launch add index contextid-lowerboundary-letter | |
eee5d9bb | 113 | $dbman->add_index($table, $index); |
a1f27717 | 114 | |
115 | /// Main savepoint reached | |
0f77b186 | 116 | upgrade_main_savepoint($result, 2008030700); |
117 | } | |
a1f27717 | 118 | |
1ea260d8 | 119 | if ($result && $oldversion < 2008050100) { |
120 | // Update courses that used weekscss to weeks | |
61676608 | 121 | $DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss')); |
1ea260d8 | 122 | upgrade_main_savepoint($result, 2008050100); |
123 | } | |
124 | ||
0b51c247 | 125 | if ($result && $oldversion < 2008050200) { |
126 | // remove unused config options | |
127 | unset_config('statsrolesupgraded'); | |
128 | upgrade_main_savepoint($result, 2008050200); | |
129 | } | |
130 | ||
994fbaab | 131 | if ($result && $oldversion < 2008050700) { |
775f811a | 132 | upgrade_set_timeout(60*20); // this may take a while |
133 | ||
994fbaab | 134 | /// Fix minor problem caused by MDL-5482. |
135 | require_once($CFG->dirroot . '/question/upgrade.php'); | |
61676608 | 136 | question_fix_random_question_parents(); |
994fbaab | 137 | upgrade_main_savepoint($result, 2008050700); |
138 | } | |
139 | ||
8b9cfac4 | 140 | if ($result && $oldversion < 2008051201) { |
aa9a6867 | 141 | echo $OUTPUT->notification('Increasing size of user idnumber field, this may take a while...', 'notifysuccess'); |
775f811a | 142 | upgrade_set_timeout(60*20); // this may take a while |
8b9cfac4 | 143 | |
469dcbcc | 144 | /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859 |
cbc08f3b | 145 | $dbfamily = $DB->get_dbfamily(); |
146 | if ($dbfamily === 'mysql' || $dbfamily === 'postgres') { | |
eee5d9bb | 147 | $DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL"); |
469dcbcc | 148 | } |
149 | ||
8b9cfac4 | 150 | /// Define index idnumber (not unique) to be dropped form user |
a8cb94f6 | 151 | $table = new xmldb_table('user'); |
69b80cc2 | 152 | $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber')); |
8b9cfac4 | 153 | |
154 | /// Launch drop index idnumber | |
f33e1ed4 | 155 | if ($dbman->index_exists($table, $index)) { |
eee5d9bb | 156 | $dbman->drop_index($table, $index); |
8b9cfac4 | 157 | } |
158 | ||
159 | /// Changing precision of field idnumber on table user to (255) | |
a8cb94f6 | 160 | $table = new xmldb_table('user'); |
2a88f626 | 161 | $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'password'); |
8b9cfac4 | 162 | |
163 | /// Launch change of precision for field idnumber | |
eee5d9bb | 164 | $dbman->change_field_precision($table, $field); |
8b9cfac4 | 165 | |
166 | /// Launch add index idnumber again | |
69b80cc2 | 167 | $index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber')); |
eee5d9bb | 168 | $dbman->add_index($table, $index); |
8b9cfac4 | 169 | |
170 | /// Main savepoint reached | |
171 | upgrade_main_savepoint($result, 2008051201); | |
172 | } | |
173 | ||
7ade55ad | 174 | if ($result && $oldversion < 2008051202) { |
910dd4dd | 175 | $log_action = new object(); |
7ade55ad | 176 | $log_action->module = 'course'; |
177 | $log_action->action = 'unenrol'; | |
178 | $log_action->mtable = 'course'; | |
179 | $log_action->field = 'fullname'; | |
910dd4dd | 180 | if (!$DB->record_exists('log_display', array('action'=>'unenrol', 'module'=>'course'))) { |
61676608 | 181 | $DB->insert_record('log_display', $log_action); |
7ade55ad | 182 | } |
183 | upgrade_main_savepoint($result, 2008051202); | |
184 | } | |
185 | ||
fa162144 | 186 | if ($result && $oldversion < 2008051203) { |
187 | $table = new xmldb_table('mnet_enrol_course'); | |
2a88f626 | 188 | $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0); |
eee5d9bb | 189 | $dbman->change_field_precision($table, $field); |
fa162144 | 190 | upgrade_main_savepoint($result, 2008051203); |
191 | } | |
192 | ||
38fb8190 | 193 | if ($result && $oldversion < 2008063001) { |
775f811a | 194 | upgrade_set_timeout(60*20); // this may take a while |
195 | ||
38fb8190 | 196 | // table to be modified |
197 | $table = new xmldb_table('tag_instance'); | |
198 | // add field | |
199 | $field = new xmldb_field('tiuserid'); | |
200 | if (!$dbman->field_exists($table, $field)) { | |
2a88f626 | 201 | $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'itemid'); |
38fb8190 | 202 | $dbman->add_field($table, $field); |
203 | } | |
204 | // modify index | |
205 | $index = new xmldb_index('itemtype-itemid-tagid'); | |
206 | $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid')); | |
b91de8a5 | 207 | if ($dbman->index_exists($table, $index)) { |
208 | $dbman->drop_index($table, $index); | |
209 | } | |
38fb8190 | 210 | $index = new xmldb_index('itemtype-itemid-tagid-tiuserid'); |
211 | $index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid')); | |
b91de8a5 | 212 | if (!$dbman->index_exists($table, $index)) { |
213 | $dbman->add_index($table, $index); | |
214 | } | |
38fb8190 | 215 | |
216 | /// Main savepoint reached | |
217 | upgrade_main_savepoint($result, 2008063001); | |
218 | } | |
38fb8190 | 219 | |
a036d7f3 | 220 | if ($result && $oldversion < 2008070300) { |
61676608 | 221 | $DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false)); |
a036d7f3 | 222 | upgrade_main_savepoint($result, 2008070300); |
223 | } | |
4e781c7b | 224 | |
ac5efef6 | 225 | if ($result && $oldversion < 2008070701) { |
226 | ||
227 | /// Define table portfolio_instance to be created | |
228 | $table = new xmldb_table('portfolio_instance'); | |
229 | ||
230 | /// Adding fields to table portfolio_instance | |
2a88f626 | 231 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
232 | $table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null); | |
233 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
234 | $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); | |
ac5efef6 | 235 | |
236 | /// Adding keys to table portfolio_instance | |
237 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
238 | ||
239 | /// Conditionally launch create table for portfolio_instance | |
240 | if (!$dbman->table_exists($table)) { | |
241 | $dbman->create_table($table); | |
242 | } | |
243 | /// Define table portfolio_instance_config to be created | |
244 | $table = new xmldb_table('portfolio_instance_config'); | |
245 | ||
246 | /// Adding fields to table portfolio_instance_config | |
2a88f626 | 247 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
248 | $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
249 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
250 | $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null); | |
ac5efef6 | 251 | |
252 | /// Adding keys to table portfolio_instance_config | |
253 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
254 | $table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id')); | |
255 | ||
256 | /// Adding indexes to table portfolio_instance_config | |
257 | $table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name')); | |
258 | ||
259 | /// Conditionally launch create table for portfolio_instance_config | |
260 | if (!$dbman->table_exists($table)) { | |
261 | $dbman->create_table($table); | |
262 | } | |
263 | ||
264 | /// Define table portfolio_instance_user to be created | |
265 | $table = new xmldb_table('portfolio_instance_user'); | |
266 | ||
267 | /// Adding fields to table portfolio_instance_user | |
2a88f626 | 268 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null); |
269 | $table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
270 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
271 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
272 | $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null); | |
ac5efef6 | 273 | |
274 | /// Adding keys to table portfolio_instance_user | |
275 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
276 | $table->add_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id')); | |
277 | $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
278 | ||
279 | /// Conditionally launch create table for portfolio_instance_user | |
280 | if (!$dbman->table_exists($table)) { | |
281 | $dbman->create_table($table); | |
282 | } | |
283 | ||
284 | /// Main savepoint reached | |
285 | upgrade_main_savepoint($result, 2008070701); | |
286 | } | |
172dd12c | 287 | |
775f811a | 288 | if ($result && $oldversion < 2008072400) { |
289 | /// Create the database tables for message_processors | |
f65b2dae | 290 | $table = new xmldb_table('message_processors'); |
2a88f626 | 291 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
292 | $table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null); | |
f65b2dae | 293 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
3b120e46 | 294 | $dbman->create_table($table); |
295 | ||
3b120e46 | 296 | /// delete old and create new fields |
f65b2dae | 297 | $table = new xmldb_table('message'); |
298 | $field = new xmldb_field('messagetype'); | |
3b120e46 | 299 | $dbman->drop_field($table, $field); |
300 | ||
301 | /// fields to rename | |
f65b2dae | 302 | $field = new xmldb_field('message'); |
2a88f626 | 303 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); |
3b120e46 | 304 | $dbman->rename_field($table, $field, 'fullmessage'); |
f65b2dae | 305 | $field = new xmldb_field('format'); |
2a88f626 | 306 | $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null); |
3b120e46 | 307 | $dbman->rename_field($table, $field, 'fullmessageformat'); |
308 | ||
309 | /// new message fields | |
f65b2dae | 310 | $field = new xmldb_field('subject'); |
2a88f626 | 311 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); |
3b120e46 | 312 | $dbman->add_field($table, $field); |
f65b2dae | 313 | $field = new xmldb_field('fullmessagehtml'); |
2a88f626 | 314 | $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null); |
3b120e46 | 315 | $dbman->add_field($table, $field); |
f65b2dae | 316 | $field = new xmldb_field('smallmessage'); |
2a88f626 | 317 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); |
3b120e46 | 318 | $dbman->add_field($table, $field); |
319 | ||
320 | ||
f65b2dae | 321 | $table = new xmldb_table('message_read'); |
322 | $field = new xmldb_field('messagetype'); | |
3b120e46 | 323 | $dbman->drop_field($table, $field); |
f65b2dae | 324 | $field = new xmldb_field('mailed'); |
3b120e46 | 325 | $dbman->drop_field($table, $field); |
326 | ||
327 | /// fields to rename | |
f65b2dae | 328 | $field = new xmldb_field('message'); |
2a88f626 | 329 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); |
3b120e46 | 330 | $dbman->rename_field($table, $field, 'fullmessage'); |
f65b2dae | 331 | $field = new xmldb_field('format'); |
2a88f626 | 332 | $field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null); |
3b120e46 | 333 | $dbman->rename_field($table, $field, 'fullmessageformat'); |
334 | ||
335 | ||
336 | /// new message fields | |
f65b2dae | 337 | $field = new xmldb_field('subject'); |
2a88f626 | 338 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); |
3b120e46 | 339 | $dbman->add_field($table, $field); |
f65b2dae | 340 | $field = new xmldb_field('fullmessagehtml'); |
2a88f626 | 341 | $field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null); |
3b120e46 | 342 | $dbman->add_field($table, $field); |
f65b2dae | 343 | $field = new xmldb_field('smallmessage'); |
2a88f626 | 344 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null); |
3b120e46 | 345 | $dbman->add_field($table, $field); |
346 | ||
347 | /// new table | |
f65b2dae | 348 | $table = new xmldb_table('message_working'); |
2a88f626 | 349 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
350 | $table->add_field('unreadmessageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
351 | $table->add_field('processorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
f65b2dae | 352 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
3b120e46 | 353 | $dbman->create_table($table); |
354 | ||
355 | ||
356 | upgrade_main_savepoint($result, 2008072400); | |
357 | } | |
358 | ||
4e781c7b | 359 | if ($result && $oldversion < 2008072800) { |
360 | ||
361 | /// Define field enablecompletion to be added to course | |
362 | $table = new xmldb_table('course'); | |
363 | $field = new xmldb_field('enablecompletion'); | |
2a88f626 | 364 | $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'defaultrole'); |
4e781c7b | 365 | |
366 | /// Launch add field enablecompletion | |
775f811a | 367 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b | 368 | $dbman->add_field($table, $field); |
369 | } | |
775f811a | 370 | |
4e781c7b | 371 | /// Define field completion to be added to course_modules |
372 | $table = new xmldb_table('course_modules'); | |
373 | $field = new xmldb_field('completion'); | |
2a88f626 | 374 | $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'groupmembersonly'); |
4e781c7b | 375 | |
376 | /// Launch add field completion | |
775f811a | 377 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b | 378 | $dbman->add_field($table, $field); |
379 | } | |
380 | ||
381 | /// Define field completiongradeitemnumber to be added to course_modules | |
382 | $field = new xmldb_field('completiongradeitemnumber'); | |
2a88f626 | 383 | $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'completion'); |
4e781c7b | 384 | |
385 | /// Launch add field completiongradeitemnumber | |
775f811a | 386 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b | 387 | $dbman->add_field($table, $field); |
388 | } | |
389 | ||
390 | /// Define field completionview to be added to course_modules | |
391 | $field = new xmldb_field('completionview'); | |
2a88f626 | 392 | $field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completiongradeitemnumber'); |
4e781c7b | 393 | |
394 | /// Launch add field completionview | |
775f811a | 395 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b | 396 | $dbman->add_field($table, $field); |
397 | } | |
398 | ||
399 | /// Define field completionexpected to be added to course_modules | |
400 | $field = new xmldb_field('completionexpected'); | |
2a88f626 | 401 | $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionview'); |
4e781c7b | 402 | |
403 | /// Launch add field completionexpected | |
775f811a | 404 | if (!$dbman->field_exists($table,$field)) { |
4e781c7b | 405 | $dbman->add_field($table, $field); |
406 | } | |
407 | ||
408 | /// Define table course_modules_completion to be created | |
409 | $table = new xmldb_table('course_modules_completion'); | |
775f811a | 410 | if (!$dbman->table_exists($table)) { |
4e781c7b | 411 | |
412 | /// Adding fields to table course_modules_completion | |
2a88f626 | 413 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
414 | $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
415 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
416 | $table->add_field('completionstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
417 | $table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null); | |
418 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
775f811a | 419 | |
4e781c7b | 420 | /// Adding keys to table course_modules_completion |
1e0c56ea | 421 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); |
775f811a | 422 | |
4e781c7b | 423 | /// Adding indexes to table course_modules_completion |
1e0c56ea | 424 | $table->add_index('coursemoduleid', XMLDB_INDEX_NOTUNIQUE, array('coursemoduleid')); |
425 | $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid')); | |
775f811a | 426 | |
4e781c7b | 427 | /// Launch create table for course_modules_completion |
428 | $dbman->create_table($table); | |
429 | } | |
430 | ||
431 | /// Main savepoint reached | |
432 | upgrade_main_savepoint($result, 2008072800); | |
433 | } | |
775f811a | 434 | |
4ab16a09 | 435 | if ($result && $oldversion < 2008073000) { |
ac5efef6 | 436 | |
4ab16a09 | 437 | /// Define table portfolio_log to be created |
438 | $table = new xmldb_table('portfolio_log'); | |
439 | ||
440 | /// Adding fields to table portfolio_log | |
2a88f626 | 441 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
442 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
443 | $table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
444 | $table->add_field('portfolio', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
445 | $table->add_field('caller_class', XMLDB_TYPE_CHAR, '150', null, XMLDB_NOTNULL, null, null); | |
446 | $table->add_field('caller_file', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
447 | $table->add_field('caller_sha1', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
4ab16a09 | 448 | |
449 | /// Adding keys to table portfolio_log | |
450 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
451 | $table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
452 | $table->add_key('portfoliofk', XMLDB_KEY_FOREIGN, array('portfolio'), 'portfolio_instance', array('id')); | |
453 | ||
454 | /// Conditionally launch create table for portfolio_log | |
455 | if (!$dbman->table_exists($table)) { | |
456 | $dbman->create_table($table); | |
457 | } | |
458 | ||
459 | /// Main savepoint reached | |
460 | upgrade_main_savepoint($result, 2008073000); | |
461 | } | |
120b3758 | 462 | |
463 | if ($result && $oldversion < 2008073104) { | |
464 | /// Drop old table that might exist for some people | |
465 | $table = new xmldb_table('message_providers'); | |
466 | if ($dbman->table_exists($table)) { | |
467 | $dbman->drop_table($table); | |
468 | } | |
469 | ||
470 | /// Define table message_providers to be created | |
471 | $table = new xmldb_table('message_providers'); | |
472 | ||
473 | /// Adding fields to table message_providers | |
2a88f626 | 474 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
475 | $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); | |
476 | $table->add_field('component', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null); | |
477 | $table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null); | |
120b3758 | 478 | |
479 | /// Adding keys to table message_providers | |
480 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
481 | ||
482 | /// Adding indexes to table message_providers | |
483 | $table->add_index('componentname', XMLDB_INDEX_UNIQUE, array('component', 'name')); | |
484 | ||
485 | /// Create table for message_providers | |
486 | $dbman->create_table($table); | |
487 | ||
488 | upgrade_main_savepoint($result, 2008073104); | |
489 | } | |
172dd12c | 490 | |
491 | if ($result && $oldversion < 2008073111) { | |
492 | /// Define table files to be created | |
493 | $table = new xmldb_table('files'); | |
494 | ||
495 | /// Adding fields to table files | |
2a88f626 | 496 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
497 | $table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); | |
498 | $table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); | |
499 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
500 | $table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null); | |
501 | $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
502 | $table->add_field('filepath', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
503 | $table->add_field('filename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
504 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); | |
505 | $table->add_field('filesize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
506 | $table->add_field('mimetype', XMLDB_TYPE_CHAR, '100', null, null, null, null); | |
507 | $table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); | |
f0b9ee18 PS |
508 | $table->add_field('source', XMLDB_TYPE_TEXT, 'small', null, null, null, null); |
509 | $table->add_field('author', XMLDB_TYPE_CHAR, '255', null, null, null, null); | |
510 | $table->add_field('license', XMLDB_TYPE_CHAR, '255', null, null, null, null); | |
2a88f626 | 511 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); |
512 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
172dd12c | 513 | |
514 | /// Adding keys to table files | |
515 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
516 | $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); | |
517 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
518 | ||
519 | /// Adding indexes to table files | |
520 | $table->add_index('filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('filearea', 'contextid', 'itemid')); | |
521 | $table->add_index('contenthash', XMLDB_INDEX_NOTUNIQUE, array('contenthash')); | |
522 | $table->add_index('pathnamehash', XMLDB_INDEX_UNIQUE, array('pathnamehash')); | |
523 | ||
524 | /// Conditionally launch create table for files | |
525 | $dbman->create_table($table); | |
526 | ||
527 | /// Main savepoint reached | |
528 | upgrade_main_savepoint($result, 2008073111); | |
529 | } | |
530 | ||
bf34822b PS |
531 | if ($result && $oldversion < 2008073112) { |
532 | // Define field legacyfiles to be added to course | |
533 | $table = new xmldb_table('course'); | |
534 | $field = new xmldb_field('legacyfiles', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'maxbytes'); | |
535 | ||
536 | // Launch add field legacyfiles | |
537 | $dbman->add_field($table, $field); | |
538 | // enable legacy files in all courses | |
539 | $DB->execute("UPDATE {course} SET legacyfiles = 2"); | |
540 | ||
541 | // Main savepoint reached | |
542 | upgrade_main_savepoint($result, 2008073112); | |
543 | } | |
544 | ||
172dd12c | 545 | if ($result && $oldversion < 2008073113) { |
546 | /// move all course, backup and other files to new filepool based storage | |
547 | upgrade_migrate_files_courses(); | |
548 | /// Main savepoint reached | |
549 | upgrade_main_savepoint($result, 2008073113); | |
550 | } | |
551 | ||
552 | if ($result && $oldversion < 2008073114) { | |
553 | /// move all course, backup and other files to new filepool based storage | |
554 | upgrade_migrate_files_blog(); | |
555 | /// Main savepoint reached | |
556 | upgrade_main_savepoint($result, 2008073114); | |
557 | } | |
f33e1ed4 | 558 | |
1ce2da58 | 559 | if ($result && $oldversion < 2008080400) { |
560 | // Add field ssl_jump_url to mnet application, and populate existing default applications | |
561 | $table = new xmldb_table('mnet_application'); | |
562 | $field = new xmldb_field('sso_jump_url'); | |
563 | if (!$dbman->field_exists($table, $field)) { | |
2a88f626 | 564 | $field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); |
c5a04d12 | 565 | $dbman->add_field($table, $field); |
61676608 PS |
566 | $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle')); |
567 | $DB->set_field('mnet_application', 'sso_jump_url', '/auth/xmlrpc/jump.php', array('name' => 'mahara')); | |
1ce2da58 | 568 | } |
569 | ||
570 | /// Main savepoint reached | |
571 | upgrade_main_savepoint($result, 2008080400); | |
572 | } | |
04f35360 | 573 | |
574 | if ($result && $oldversion < 2008080500) { | |
575 | ||
576 | /// Define table portfolio_tempdata to be created | |
577 | $table = new xmldb_table('portfolio_tempdata'); | |
578 | ||
579 | /// Adding fields to table portfolio_tempdata | |
2a88f626 | 580 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
581 | $table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, null, null, null); | |
04f35360 | 582 | |
583 | /// Adding keys to table portfolio_tempdata | |
584 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
585 | ||
586 | /// Conditionally launch create table for portfolio_tempdata | |
587 | if (!$dbman->table_exists($table)) { | |
588 | $dbman->create_table($table); | |
589 | } | |
590 | ||
591 | /// Main savepoint reached | |
592 | upgrade_main_savepoint($result, 2008080500); | |
593 | } | |
594 | ||
84a44985 | 595 | if ($result && $oldversion < 2008080600) { |
596 | ||
597 | $DB->delete_records('portfolio_tempdata'); // there shouldnt' be any, and it will cause problems with this upgrade. | |
598 | /// Define field expirytime to be added to portfolio_tempdata | |
599 | $table = new xmldb_table('portfolio_tempdata'); | |
2a88f626 | 600 | $field = new xmldb_field('expirytime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'data'); |
84a44985 | 601 | |
602 | /// Conditionally launch add field expirytime | |
603 | if (!$dbman->field_exists($table, $field)) { | |
604 | $dbman->add_field($table, $field); | |
605 | } | |
606 | ||
607 | /// Main savepoint reached | |
608 | upgrade_main_savepoint($result, 2008080600); | |
609 | } | |
775f811a | 610 | |
c1f58efe | 611 | if ($result && $oldversion < 2008081500) { |
612 | /// Changing the type of all the columns that the question bank uses to store grades to be NUMBER(12, 7). | |
613 | $table = new xmldb_table('question'); | |
614 | $field = new xmldb_field('defaultgrade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'generalfeedback'); | |
615 | $dbman->change_field_type($table, $field); | |
616 | upgrade_main_savepoint($result, 2008081500); | |
617 | } | |
618 | ||
f9a2cf86 | 619 | if ($result && $oldversion < 2008081501) { |
620 | $table = new xmldb_table('question'); | |
2a88f626 | 621 | $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'defaultgrade'); |
f9a2cf86 | 622 | $dbman->change_field_type($table, $field); |
623 | upgrade_main_savepoint($result, 2008081501); | |
624 | } | |
625 | ||
626 | if ($result && $oldversion < 2008081502) { | |
627 | $table = new xmldb_table('question_answers'); | |
2a88f626 | 628 | $field = new xmldb_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'answer'); |
f9a2cf86 | 629 | $dbman->change_field_type($table, $field); |
630 | upgrade_main_savepoint($result, 2008081502); | |
631 | } | |
632 | ||
633 | if ($result && $oldversion < 2008081503) { | |
634 | $table = new xmldb_table('question_sessions'); | |
2a88f626 | 635 | $field = new xmldb_field('sumpenalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'newgraded'); |
f9a2cf86 | 636 | $dbman->change_field_type($table, $field); |
637 | upgrade_main_savepoint($result, 2008081503); | |
638 | } | |
639 | ||
640 | if ($result && $oldversion < 2008081504) { | |
641 | $table = new xmldb_table('question_states'); | |
2a88f626 | 642 | $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'event'); |
f9a2cf86 | 643 | $dbman->change_field_type($table, $field); |
644 | upgrade_main_savepoint($result, 2008081504); | |
645 | } | |
646 | ||
647 | if ($result && $oldversion < 2008081505) { | |
648 | $table = new xmldb_table('question_states'); | |
2a88f626 | 649 | $field = new xmldb_field('raw_grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'grade'); |
f9a2cf86 | 650 | $dbman->change_field_type($table, $field); |
651 | upgrade_main_savepoint($result, 2008081505); | |
652 | } | |
653 | ||
654 | if ($result && $oldversion < 2008081506) { | |
655 | $table = new xmldb_table('question_states'); | |
2a88f626 | 656 | $field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'raw_grade'); |
f9a2cf86 | 657 | $dbman->change_field_type($table, $field); |
658 | upgrade_main_savepoint($result, 2008081506); | |
659 | } | |
660 | ||
775f811a | 661 | if ($result && $oldversion < 2008081600) { |
662 | ||
663 | /// all 1.9 sites and fresh installs must already be unicode, not needed anymore | |
664 | unset_config('unicodedb'); | |
665 | ||
666 | /// Main savepoint reached | |
667 | upgrade_main_savepoint($result, 2008081600); | |
668 | } | |
669 | ||
ff2f69bc | 670 | if ($result && $oldversion < 2008081900) { |
671 | /// Define field userid to be added to portfolio_tempdata | |
672 | $table = new xmldb_table('portfolio_tempdata'); | |
2a88f626 | 673 | $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'expirytime'); |
ff2f69bc | 674 | |
675 | /// Conditionally launch add field userid | |
676 | if (!$dbman->field_exists($table, $field)) { | |
677 | $dbman->add_field($table, $field); | |
678 | } | |
679 | $DB->set_field('portfolio_tempdata', 'userid', 0); | |
680 | /// now change it to be notnull | |
681 | ||
682 | /// Changing nullability of field userid on table portfolio_tempdata to not null | |
2a88f626 | 683 | $field = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'expirytime'); |
ff2f69bc | 684 | |
685 | /// Launch change of nullability for field userid | |
686 | $dbman->change_field_notnull($table, $field); | |
687 | ||
688 | /// Define key userfk (foreign) to be added to portfolio_tempdata | |
689 | $table = new xmldb_table('portfolio_tempdata'); | |
690 | $key = new xmldb_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
691 | ||
692 | /// Launch add key userfk | |
693 | $dbman->add_key($table, $key); | |
694 | ||
695 | upgrade_main_savepoint($result, 2008081900); | |
696 | } | |
8f3f6cc3 | 697 | if ($result && $oldversion < 2008082602) { |
27051e43 | 698 | |
699 | /// Define table repository to be dropped | |
700 | $table = new xmldb_table('repository'); | |
701 | ||
702 | /// Conditionally launch drop table for repository | |
703 | if ($dbman->table_exists($table)) { | |
704 | $dbman->drop_table($table); | |
705 | } | |
706 | ||
707 | /// Define table repository to be created | |
708 | $table = new xmldb_table('repository'); | |
709 | ||
710 | /// Adding fields to table repository | |
2a88f626 | 711 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
712 | $table->add_field('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
713 | $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '1'); | |
714 | $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); | |
27051e43 | 715 | |
716 | /// Adding keys to table repository | |
717 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
718 | ||
719 | /// Conditionally launch create table for repository | |
720 | if (!$dbman->table_exists($table)) { | |
721 | $dbman->create_table($table); | |
722 | } | |
723 | /// Define table repository_instances to be created | |
724 | $table = new xmldb_table('repository_instances'); | |
725 | ||
726 | /// Adding fields to table repository_instances | |
2a88f626 | 727 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
728 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
729 | $table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
730 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); | |
731 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
732 | $table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null); | |
733 | $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null); | |
734 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); | |
735 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); | |
27051e43 | 736 | |
737 | /// Adding keys to table repository_instances | |
738 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
739 | ||
740 | /// Conditionally launch create table for repository_instances | |
741 | if (!$dbman->table_exists($table)) { | |
742 | $dbman->create_table($table); | |
743 | } | |
744 | ||
745 | /// Define table repository_instance_config to be created | |
746 | $table = new xmldb_table('repository_instance_config'); | |
747 | ||
748 | /// Adding fields to table repository_instance_config | |
2a88f626 | 749 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
750 | $table->add_field('instanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
751 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
752 | $table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null); | |
27051e43 | 753 | |
754 | /// Adding keys to table repository_instance_config | |
755 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
756 | ||
757 | /// Conditionally launch create table for repository_instance_config | |
758 | if (!$dbman->table_exists($table)) { | |
759 | $dbman->create_table($table); | |
760 | } | |
761 | ||
762 | /// Main savepoint reached | |
8f3f6cc3 | 763 | upgrade_main_savepoint($result, 2008082602); |
27051e43 | 764 | } |
765 | ||
62e76c67 | 766 | if ($result && $oldversion < 2008082700) { |
767 | /// Add a new column to the question sessions table to record whether a | |
768 | /// question has been flagged. | |
769 | ||
770 | /// Define field flagged to be added to question_sessions | |
771 | $table = new xmldb_table('question_sessions'); | |
2a88f626 | 772 | $field = new xmldb_field('flagged', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'manualcomment'); |
62e76c67 | 773 | |
774 | /// Conditionally launch add field flagged | |
775 | if (!$dbman->field_exists($table, $field)) { | |
776 | $dbman->add_field($table, $field); | |
777 | } | |
778 | ||
779 | /// Main savepoint reached | |
780 | upgrade_main_savepoint($result, 2008082700); | |
781 | } | |
ff2f69bc | 782 | |
2c48aeab | 783 | if ($result && $oldversion < 2008082900) { |
784 | ||
785 | /// Changing precision of field parent_type on table mnet_rpc to (20) | |
786 | $table = new xmldb_table('mnet_rpc'); | |
2a88f626 | 787 | $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path'); |
2c48aeab | 788 | |
789 | /// Launch change of precision for field parent_type | |
790 | $dbman->change_field_precision($table, $field); | |
791 | ||
792 | /// Main savepoint reached | |
793 | upgrade_main_savepoint($result, 2008082900); | |
794 | } | |
795 | ||
ff7e7f92 | 796 | if ($result && $oldversion < 2008090108) { |
797 | $repo = new object(); | |
798 | $repo->type = 'upload'; | |
799 | $repo->visible = 1; | |
800 | $repo->sortorder = 1; | |
801 | if (!$DB->record_exists('repository', array('type'=>'upload'))) { | |
802 | $typeid = $DB->insert_record('repository', $repo); | |
803 | }else{ | |
804 | $record = $DB->get_record('repository', array('type'=>'upload')); | |
805 | $typeid = $record->id; | |
806 | } | |
807 | if (!$DB->record_exists('repository_instances', array('typeid'=>$typeid))) { | |
808 | $instance = new object(); | |
fb7cae3b | 809 | $instance->name = get_string('repositoryname', 'repository_upload'); |
ff7e7f92 | 810 | $instance->typeid = $typeid; |
811 | $instance->userid = 0; | |
812 | $instance->contextid = SITEID; | |
813 | $instance->timecreated = time(); | |
814 | $instance->timemodified = time(); | |
61676608 | 815 | $DB->insert_record('repository_instances', $instance); |
ff7e7f92 | 816 | } |
817 | $repo->type = 'local'; | |
818 | $repo->visible = 1; | |
819 | $repo->sortorder = 1; | |
820 | if (!$DB->record_exists('repository', array('type'=>'local'))) { | |
821 | $typeid = $DB->insert_record('repository', $repo); | |
822 | }else{ | |
823 | $record = $DB->get_record('repository', array('type'=>'local')); | |
824 | $typeid = $record->id; | |
825 | } | |
826 | if (!$DB->record_exists('repository_instances', array('typeid'=>$typeid))) { | |
827 | $instance = new object(); | |
fb7cae3b | 828 | $instance->name = get_string('repositoryname', 'repository_local'); |
ff7e7f92 | 829 | $instance->typeid = $typeid; |
830 | $instance->userid = 0; | |
831 | $instance->contextid = SITEID; | |
832 | $instance->timecreated = time(); | |
833 | $instance->timemodified = time(); | |
61676608 | 834 | $DB->insert_record('repository_instances', $instance); |
ff7e7f92 | 835 | } |
836 | ||
837 | upgrade_main_savepoint($result, 2008090108); | |
838 | } | |
839 | ||
d849880e | 840 | // MDL-16411 Move all plugintype_pluginname_version values from config to config_plugins. |
841 | if ($result && $oldversion < 2008091000) { | |
842 | foreach (get_object_vars($CFG) as $name => $value) { | |
843 | if (substr($name, strlen($name) - 8) !== '_version') { | |
844 | continue; | |
845 | } | |
846 | $pluginname = substr($name, 0, strlen($name) - 8); | |
847 | if (!strpos($pluginname, '_')) { | |
848 | // Skip things like backup_version that don't contain an extra _ | |
849 | continue; | |
850 | } | |
851 | if ($pluginname == 'enrol_ldap_version') { | |
852 | // Special case - this is something different from a plugin version number. | |
853 | continue; | |
854 | } | |
6f49dd0f | 855 | if (!preg_match('/^\d{10}$/', $value)) { |
d849880e | 856 | // Extra safety check, skip anything that does not look like a Moodle |
857 | // version number (10 digits). | |
858 | continue; | |
859 | } | |
61676608 PS |
860 | set_config('version', $value, $pluginname); |
861 | unset_config($name); | |
d849880e | 862 | } |
863 | upgrade_main_savepoint($result, 2008091000); | |
864 | } | |
865 | ||
948c2860 | 866 | //Add a readonly field to the repository_instances table |
867 | //in order to support instance created automatically by a repository plugin | |
868 | if ($result && $oldversion < 2008091611) { | |
869 | ||
870 | /// Define field readonly to be added to repository_instances | |
871 | $table = new xmldb_table('repository_instances'); | |
2a88f626 | 872 | $field = new xmldb_field('readonly', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timemodified'); |
948c2860 | 873 | |
874 | /// Conditionally launch add field readonly | |
875 | if (!$dbman->field_exists($table, $field)) { | |
876 | $dbman->add_field($table, $field); | |
877 | } | |
878 | ||
879 | /// Main savepoint reached | |
880 | upgrade_main_savepoint($result, 2008091611); | |
881 | } | |
882 | ||
53b20fe3 | 883 | if ($result && $oldversion < 2008092300) { |
884 | unset_config('editorspelling'); | |
885 | unset_config('editordictionary'); | |
886 | /// Main savepoint reached | |
887 | upgrade_main_savepoint($result, 2008092300); | |
888 | } | |
889 | ||
5e7206a8 | 890 | if ($result && $oldversion < 2008101300) { |
891 | ||
d9e673c1 | 892 | if (!get_config(NULL, 'statsruntimedays')) { |
5e7206a8 | 893 | set_config('statsruntimedays', '31'); |
894 | } | |
895 | ||
896 | /// Main savepoint reached | |
897 | upgrade_main_savepoint($result, 2008101300); | |
898 | } | |
53b20fe3 | 899 | |
01a80f51 | 900 | /// New table for storing which roles can be assigned in which contexts. |
901 | if ($result && $oldversion < 2008110601) { | |
902 | ||
903 | /// Define table role_context_levels to be created | |
904 | $table = new xmldb_table('role_context_levels'); | |
905 | ||
906 | /// Adding fields to table role_context_levels | |
2a88f626 | 907 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
908 | $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
909 | $table->add_field('contextlevel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
01a80f51 | 910 | |
911 | /// Adding keys to table role_context_levels | |
912 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
913 | $table->add_key('contextlevel-roleid', XMLDB_KEY_UNIQUE, array('contextlevel', 'roleid')); | |
914 | $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id')); | |
915 | ||
916 | /// Conditionally launch create table for role_context_levels | |
917 | if (!$dbman->table_exists($table)) { | |
918 | $dbman->create_table($table); | |
919 | } | |
920 | ||
921 | /// Main savepoint reached | |
922 | upgrade_main_savepoint($result, 2008110601); | |
923 | } | |
924 | ||
925 | /// Now populate the role_context_levels table with the defaults that match | |
926 | /// moodle_install_roles, and any other combinations that exist in this system. | |
927 | if ($result && $oldversion < 2008110602) { | |
928 | $roleids = $DB->get_records_menu('role', array(), '', 'shortname,id'); | |
929 | ||
930 | /// Defaults, should match moodle_install_roles. | |
931 | $rolecontextlevels = array(); | |
01a80f51 | 932 | if (isset($roleids['coursecreator'])) { |
933 | $rolecontextlevels[$roleids['coursecreator']] = get_default_contextlevels('coursecreator'); | |
934 | } | |
935 | if (isset($roleids['editingteacher'])) { | |
936 | $rolecontextlevels[$roleids['editingteacher']] = get_default_contextlevels('editingteacher'); | |
937 | } | |
938 | if (isset($roleids['teacher'])) { | |
939 | $rolecontextlevels[$roleids['teacher']] = get_default_contextlevels('teacher'); | |
940 | } | |
941 | if (isset($roleids['student'])) { | |
942 | $rolecontextlevels[$roleids['student']] = get_default_contextlevels('student'); | |
943 | } | |
944 | if (isset($roleids['guest'])) { | |
945 | $rolecontextlevels[$roleids['guest']] = get_default_contextlevels('guest'); | |
946 | } | |
947 | if (isset($roleids['user'])) { | |
948 | $rolecontextlevels[$roleids['user']] = get_default_contextlevels('user'); | |
949 | } | |
656be893 | 950 | |
01a80f51 | 951 | /// See what other role assignments are in this database, extend the allowed |
952 | /// lists to allow them too. | |
953 | $existingrolecontextlevels = $DB->get_recordset_sql('SELECT DISTINCT ra.roleid, con.contextlevel FROM | |
954 | {role_assignments} ra JOIN {context} con ON ra.contextid = con.id'); | |
955 | foreach ($existingrolecontextlevels as $rcl) { | |
956 | if (!isset($rolecontextlevels[$rcl->roleid])) { | |
957 | $rolecontextlevels[$rcl->roleid] = array($rcl->contextlevel); | |
958 | } else if (!in_array($rcl->contextlevel, $rolecontextlevels[$rcl->roleid])) { | |
959 | $rolecontextlevels[$rcl->roleid][] = $rcl->contextlevel; | |
960 | } | |
961 | } | |
962 | ||
963 | /// Put the data into the database. | |
964 | foreach ($rolecontextlevels as $roleid => $contextlevels) { | |
965 | set_role_contextlevels($roleid, $contextlevels); | |
966 | } | |
967 | ||
968 | /// Main savepoint reached | |
969 | upgrade_main_savepoint($result, 2008110602); | |
970 | } | |
971 | ||
9101efd3 | 972 | /// Drop the deprecated teacher, teachers, student and students columns from the course table. |
973 | if ($result && $oldversion < 2008111200) { | |
974 | $table = new xmldb_table('course'); | |
975 | ||
976 | /// Conditionally launch drop field teacher | |
977 | $field = new xmldb_field('teacher'); | |
978 | if ($dbman->field_exists($table, $field)) { | |
979 | $dbman->drop_field($table, $field); | |
980 | } | |
981 | ||
982 | /// Conditionally launch drop field teacher | |
983 | $field = new xmldb_field('teachers'); | |
984 | if ($dbman->field_exists($table, $field)) { | |
985 | $dbman->drop_field($table, $field); | |
986 | } | |
987 | ||
988 | /// Conditionally launch drop field teacher | |
989 | $field = new xmldb_field('student'); | |
990 | if ($dbman->field_exists($table, $field)) { | |
991 | $dbman->drop_field($table, $field); | |
992 | } | |
993 | ||
994 | /// Conditionally launch drop field teacher | |
995 | $field = new xmldb_field('students'); | |
996 | if ($dbman->field_exists($table, $field)) { | |
997 | $dbman->drop_field($table, $field); | |
998 | } | |
999 | ||
1000 | /// Main savepoint reached | |
1001 | upgrade_main_savepoint($result, 2008111200); | |
1002 | } | |
1003 | ||
40c792c3 | 1004 | /// Add a unique index to the role.name column. |
1005 | if ($result && $oldversion < 2008111800) { | |
1006 | ||
1007 | /// Define index name (unique) to be added to role | |
1008 | $table = new xmldb_table('role'); | |
1009 | $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name')); | |
1010 | ||
1011 | /// Conditionally launch add index name | |
1012 | if (!$dbman->index_exists($table, $index)) { | |
1013 | $dbman->add_index($table, $index); | |
1014 | } | |
1015 | ||
1016 | /// Main savepoint reached | |
1017 | upgrade_main_savepoint($result, 2008111800); | |
1018 | } | |
1019 | ||
1020 | /// Add a unique index to the role.shortname column. | |
1021 | if ($result && $oldversion < 2008111801) { | |
1022 | ||
1023 | /// Define index shortname (unique) to be added to role | |
1024 | $table = new xmldb_table('role'); | |
1025 | $index = new xmldb_index('shortname', XMLDB_INDEX_UNIQUE, array('shortname')); | |
1026 | ||
1027 | /// Conditionally launch add index shortname | |
1028 | if (!$dbman->index_exists($table, $index)) { | |
1029 | $dbman->add_index($table, $index); | |
1030 | } | |
1031 | ||
1032 | /// Main savepoint reached | |
1033 | upgrade_main_savepoint($result, 2008111801); | |
1034 | } | |
1035 | ||
82bd6a5e | 1036 | if ($result && $oldversion < 2008120700) { |
1037 | ||
1038 | /// Changing precision of field shortname on table course_request to (100) | |
1039 | $table = new xmldb_table('course_request'); | |
2a88f626 | 1040 | $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname'); |
82bd6a5e | 1041 | |
da750a51 | 1042 | /// Before changing the field, drop dependent indexes |
1043 | /// Define index shortname (not unique) to be dropped form course_request | |
1044 | $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname')); | |
1045 | /// Conditionally launch drop index shortname | |
1046 | if ($dbman->index_exists($table, $index)) { | |
1047 | $dbman->drop_index($table, $index); | |
1048 | } | |
1049 | ||
82bd6a5e | 1050 | /// Launch change of precision for field shortname |
1051 | $dbman->change_field_precision($table, $field); | |
1052 | ||
da750a51 | 1053 | /// After changing the field, recreate dependent indexes |
1054 | /// Define index shortname (not unique) to be added to course_request | |
1055 | $index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname')); | |
1056 | /// Conditionally launch add index shortname | |
1057 | if (!$dbman->index_exists($table, $index)) { | |
1058 | $dbman->add_index($table, $index); | |
1059 | } | |
1060 | ||
82bd6a5e | 1061 | /// Main savepoint reached |
1062 | upgrade_main_savepoint($result, 2008120700); | |
1063 | } | |
1064 | ||
82bd6a5e | 1065 | if ($result && $oldversion < 2008120801) { |
1066 | ||
1067 | /// Changing precision of field shortname on table mnet_enrol_course to (100) | |
1068 | $table = new xmldb_table('mnet_enrol_course'); | |
2a88f626 | 1069 | $field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname'); |
82bd6a5e | 1070 | |
1071 | /// Launch change of precision for field shortname | |
1072 | $dbman->change_field_precision($table, $field); | |
1073 | ||
1074 | /// Main savepoint reached | |
1075 | upgrade_main_savepoint($result, 2008120801); | |
1076 | } | |
1077 | ||
1078 | if ($result && $oldversion < 2008121701) { | |
0953a4e7 | 1079 | |
1080 | /// Define field availablefrom to be added to course_modules | |
1081 | $table = new xmldb_table('course_modules'); | |
2a88f626 | 1082 | $field = new xmldb_field('availablefrom', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionexpected'); |
0953a4e7 | 1083 | |
1084 | /// Conditionally launch add field availablefrom | |
1085 | if (!$dbman->field_exists($table, $field)) { | |
1086 | $dbman->add_field($table, $field); | |
1087 | } | |
1088 | ||
1089 | /// Define field availableuntil to be added to course_modules | |
2a88f626 | 1090 | $field = new xmldb_field('availableuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availablefrom'); |
0953a4e7 | 1091 | |
1092 | /// Conditionally launch add field availableuntil | |
1093 | if (!$dbman->field_exists($table, $field)) { | |
1094 | $dbman->add_field($table, $field); | |
1095 | } | |
82bd6a5e | 1096 | |
0953a4e7 | 1097 | /// Define field showavailability to be added to course_modules |
2a88f626 | 1098 | $field = new xmldb_field('showavailability', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availableuntil'); |
0953a4e7 | 1099 | |
1100 | /// Conditionally launch add field showavailability | |
1101 | if (!$dbman->field_exists($table, $field)) { | |
1102 | $dbman->add_field($table, $field); | |
1103 | } | |
82bd6a5e | 1104 | |
0953a4e7 | 1105 | /// Define table course_modules_availability to be created |
1106 | $table = new xmldb_table('course_modules_availability'); | |
1107 | ||
1108 | /// Adding fields to table course_modules_availability | |
2a88f626 | 1109 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1110 | $table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
1111 | $table->add_field('sourcecmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); | |
1112 | $table->add_field('requiredcompletion', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null); | |
1113 | $table->add_field('gradeitemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); | |
1114 | $table->add_field('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null); | |
1115 | $table->add_field('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null); | |
0953a4e7 | 1116 | |
1117 | /// Adding keys to table course_modules_availability | |
1118 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
cbb17d54 | 1119 | $table->add_key('coursemoduleid', XMLDB_KEY_FOREIGN, array('coursemoduleid'), 'course_modules', array('id')); |
1120 | $table->add_key('sourcecmid', XMLDB_KEY_FOREIGN, array('sourcecmid'), 'course_modules', array('id')); | |
1121 | $table->add_key('gradeitemid', XMLDB_KEY_FOREIGN, array('gradeitemid'), 'grade_items', array('id')); | |
0953a4e7 | 1122 | |
1123 | /// Conditionally launch create table for course_modules_availability | |
1124 | if (!$dbman->table_exists($table)) { | |
1125 | $dbman->create_table($table); | |
1126 | } | |
1127 | ||
82bd6a5e | 1128 | /// Changes to modinfo mean we need to rebuild course cache |
a9a0b93d | 1129 | require_once($CFG->dirroot . '/course/lib.php'); |
8b6a0968 | 1130 | rebuild_course_cache(0, true); |
9136a60c | 1131 | |
82bd6a5e | 1132 | /// For developer upgrades, turn on the conditional activities and completion |
1133 | /// features automatically (to gain more testing) | |
8b6a0968 | 1134 | //TODO: remove before 2.0 final! |
1135 | if (debugging('', DEBUG_DEVELOPER)) { | |
1136 | set_config('enableavailability', 1); | |
1137 | set_config('enablecompletion', 1); | |
9136a60c | 1138 | } |
1139 | ||
9d510a2e | 1140 | /// Main savepoint reached |
82bd6a5e | 1141 | upgrade_main_savepoint($result, 2008121701); |
9d510a2e | 1142 | } |
1143 | ||
656be893 | 1144 | if ($result && $oldversion < 2009010500) { |
1145 | /// clean up config table a bit | |
1146 | unset_config('session_error_counter'); | |
1147 | ||
1148 | /// Main savepoint reached | |
1149 | upgrade_main_savepoint($result, 2009010500); | |
1150 | } | |
1151 | ||
1152 | if ($result && $oldversion < 2009010600) { | |
1153 | ||
1154 | /// Define field originalquestion to be dropped from question_states | |
1155 | $table = new xmldb_table('question_states'); | |
1156 | $field = new xmldb_field('originalquestion'); | |
1157 | ||
1158 | /// Conditionally launch drop field originalquestion | |
1159 | if ($dbman->field_exists($table, $field)) { | |
1160 | $dbman->drop_field($table, $field); | |
1161 | } | |
1162 | ||
1163 | /// Main savepoint reached | |
1164 | upgrade_main_savepoint($result, 2009010600); | |
1165 | } | |
1166 | ||
1167 | if ($result && $oldversion < 2009010601) { | |
1168 | ||
1169 | /// Changing precision of field ip on table log to (45) | |
1170 | $table = new xmldb_table('log'); | |
2a88f626 | 1171 | $field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'userid'); |
656be893 | 1172 | |
1173 | /// Launch change of precision for field ip | |
1174 | $dbman->change_field_precision($table, $field); | |
1175 | ||
1176 | /// Main savepoint reached | |
1177 | upgrade_main_savepoint($result, 2009010601); | |
1178 | } | |
1179 | ||
1180 | if ($result && $oldversion < 2009010602) { | |
1181 | ||
1182 | /// Changing precision of field lastip on table user to (45) | |
1183 | $table = new xmldb_table('user'); | |
2a88f626 | 1184 | $field = new xmldb_field('lastip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'currentlogin'); |
656be893 | 1185 | |
1186 | /// Launch change of precision for field lastip | |
1187 | $dbman->change_field_precision($table, $field); | |
1188 | ||
1189 | /// Main savepoint reached | |
1190 | upgrade_main_savepoint($result, 2009010602); | |
1191 | } | |
1192 | ||
1193 | if ($result && $oldversion < 2009010603) { | |
1194 | ||
1195 | /// Changing precision of field ip_address on table mnet_host to (45) | |
1196 | $table = new xmldb_table('mnet_host'); | |
2a88f626 | 1197 | $field = new xmldb_field('ip_address', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'wwwroot'); |
656be893 | 1198 | |
1199 | /// Launch change of precision for field ip_address | |
1200 | $dbman->change_field_precision($table, $field); | |
1201 | ||
1202 | /// Main savepoint reached | |
1203 | upgrade_main_savepoint($result, 2009010603); | |
1204 | } | |
1205 | ||
1206 | if ($result && $oldversion < 2009010604) { | |
1207 | ||
1208 | /// Changing precision of field ip on table mnet_log to (45) | |
1209 | $table = new xmldb_table('mnet_log'); | |
2a88f626 | 1210 | $field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'userid'); |
656be893 | 1211 | |
1212 | /// Launch change of precision for field ip | |
1213 | $dbman->change_field_precision($table, $field); | |
1214 | ||
1215 | /// Main savepoint reached | |
1216 | upgrade_main_savepoint($result, 2009010604); | |
1217 | } | |
1218 | ||
ab2eb65c | 1219 | if ($result && $oldversion < 2009011000) { |
1220 | ||
1221 | /// Changing nullability of field configdata on table block_instance to null | |
1222 | $table = new xmldb_table('block_instance'); | |
1223 | $field = new xmldb_field('configdata'); | |
2a88f626 | 1224 | $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'visible'); |
ab2eb65c | 1225 | |
1226 | /// Launch change of nullability for field configdata | |
1227 | $dbman->change_field_notnull($table, $field); | |
1228 | ||
1229 | /// Main savepoint reached | |
1230 | upgrade_main_savepoint($result, 2009011000); | |
1231 | } | |
1232 | ||
1caea91e | 1233 | if ($result && $oldversion < 2009011100) { |
1234 | /// Remove unused settings | |
1235 | unset_config('zip'); | |
1236 | unset_config('unzip'); | |
1237 | unset_config('adminblocks_initialised'); | |
1238 | ||
1239 | /// Main savepoint reached | |
1240 | upgrade_main_savepoint($result, 2009011100); | |
1241 | } | |
1242 | ||
eb6a973c | 1243 | if ($result && $oldversion < 2009011101) { |
1244 | /// Migrate backup settings to core plugin config table | |
1245 | $configs = $DB->get_records('backup_config'); | |
1246 | foreach ($configs as $config) { | |
1247 | set_config($config->name, $config->value, 'backup'); | |
1248 | } | |
1249 | ||
1250 | /// Define table to be dropped | |
1251 | $table = new xmldb_table('backup_config'); | |
1252 | ||
1253 | /// Launch drop table for old backup config | |
1254 | $dbman->drop_table($table); | |
1255 | ||
1256 | /// Main savepoint reached | |
1257 | upgrade_main_savepoint($result, 2009011101); | |
1258 | } | |
1259 | ||
301bf0b2 | 1260 | if ($result && $oldversion < 2009011303) { |
1261 | ||
1262 | /// Define table config_log to be created | |
1263 | $table = new xmldb_table('config_log'); | |
1264 | ||
1265 | /// Adding fields to table config_log | |
2a88f626 | 1266 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1267 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
1268 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
1269 | $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null); | |
1270 | $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); | |
1271 | $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null); | |
1272 | $table->add_field('oldvalue', XMLDB_TYPE_TEXT, 'small', null, null, null, null); | |
301bf0b2 | 1273 | |
1274 | /// Adding keys to table config_log | |
1275 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1276 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
1277 | ||
1278 | /// Adding indexes to table config_log | |
1279 | $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified')); | |
1280 | ||
1281 | /// Launch create table for config_log | |
1282 | $dbman->create_table($table); | |
1283 | ||
1284 | /// Main savepoint reached | |
1285 | upgrade_main_savepoint($result, 2009011303); | |
1286 | } | |
1287 | ||
b9fb7103 | 1288 | if ($result && $oldversion < 2009011900) { |
3f57bd45 | 1289 | |
1290 | /// Define table sessions2 to be dropped | |
1291 | $table = new xmldb_table('sessions2'); | |
1292 | ||
1293 | /// Conditionally launch drop table for sessions | |
1294 | if ($dbman->table_exists($table)) { | |
1295 | $dbman->drop_table($table); | |
1296 | } | |
1297 | ||
1298 | /// Define table sessions to be dropped | |
1299 | $table = new xmldb_table('sessions'); | |
1300 | ||
1301 | /// Conditionally launch drop table for sessions | |
1302 | if ($dbman->table_exists($table)) { | |
1303 | $dbman->drop_table($table); | |
1304 | } | |
1305 | ||
1306 | /// Define table sessions to be created | |
1307 | $table = new xmldb_table('sessions'); | |
1308 | ||
1309 | /// Adding fields to table sessions | |
2a88f626 | 1310 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1311 | $table->add_field('state', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); | |
1312 | $table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null); | |
1313 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
1314 | $table->add_field('sessdata', XMLDB_TYPE_TEXT, 'big', null, null, null, null); | |
1315 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
1316 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
1317 | $table->add_field('firstip', XMLDB_TYPE_CHAR, '45', null, null, null, null); | |
1318 | $table->add_field('lastip', XMLDB_TYPE_CHAR, '45', null, null, null, null); | |
3f57bd45 | 1319 | |
1320 | /// Adding keys to table sessions | |
1321 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1322 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
1323 | ||
1324 | /// Adding indexes to table sessions | |
1325 | $table->add_index('state', XMLDB_INDEX_NOTUNIQUE, array('state')); | |
1326 | $table->add_index('sid', XMLDB_INDEX_UNIQUE, array('sid')); | |
1327 | $table->add_index('timecreated', XMLDB_INDEX_NOTUNIQUE, array('timecreated')); | |
1328 | $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified')); | |
1329 | ||
1330 | /// Launch create table for sessions | |
1331 | $dbman->create_table($table); | |
1332 | ||
1333 | /// Main savepoint reached | |
b9fb7103 | 1334 | upgrade_main_savepoint($result, 2009011900); |
3f57bd45 | 1335 | } |
1336 | ||
dc6f76b9 | 1337 | if ($result && $oldversion < 2009012901) { |
795a08ad | 1338 | // NOTE: this table may already exist, see beginning of this file ;-) |
1f20942c | 1339 | |
1340 | /// Define table upgrade_log to be created | |
1341 | $table = new xmldb_table('upgrade_log'); | |
1342 | ||
1343 | /// Adding fields to table upgrade_log | |
2a88f626 | 1344 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1345 | $table->add_field('type', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); | |
1346 | $table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null); | |
1347 | $table->add_field('version', XMLDB_TYPE_CHAR, '100', null, null, null, null); | |
1348 | $table->add_field('info', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
1349 | $table->add_field('details', XMLDB_TYPE_TEXT, 'small', null, null, null, null); | |
1350 | $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null); | |
1351 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
1352 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
1f20942c | 1353 | |
1354 | /// Adding keys to table upgrade_log | |
1355 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1356 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
1357 | ||
1358 | /// Adding indexes to table upgrade_log | |
1359 | $table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified')); | |
1360 | $table->add_index('type-timemodified', XMLDB_INDEX_NOTUNIQUE, array('type', 'timemodified')); | |
1361 | ||
1362 | /// Conditionally launch create table for upgrade_log | |
1363 | if (!$dbman->table_exists($table)) { | |
1364 | $dbman->create_table($table); | |
1365 | } | |
1366 | ||
1367 | /// Main savepoint reached | |
dc6f76b9 | 1368 | upgrade_main_savepoint($result, 2009012901); |
1f20942c | 1369 | } |
1caea91e | 1370 | |
75564228 | 1371 | if ($result && $oldversion < 2009021800) { |
eb2761f8 | 1372 | // Converting format of grade conditions, if any exist, to percentages. |
75564228 | 1373 | $DB->execute(" |
1374 | UPDATE {course_modules_availability} SET grademin=( | |
1375 | SELECT 100.0*({course_modules_availability}.grademin-gi.grademin) | |
eb2761f8 | 1376 | /(gi.grademax-gi.grademin) |
1377 | FROM {grade_items} gi | |
75564228 | 1378 | WHERE gi.id={course_modules_availability}.gradeitemid) |
1379 | WHERE gradeitemid IS NOT NULL AND grademin IS NOT NULL"); | |
1380 | $DB->execute(" | |
1381 | UPDATE {course_modules_availability} SET grademax=( | |
1382 | SELECT 100.0*({course_modules_availability}.grademax-gi.grademin) | |
eb2761f8 | 1383 | /(gi.grademax-gi.grademin) |
1384 | FROM {grade_items} gi | |
75564228 | 1385 | WHERE gi.id={course_modules_availability}.gradeitemid) |
1386 | WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); | |
1387 | ||
1388 | /// Main savepoint reached | |
1389 | upgrade_main_savepoint($result, 2009021800); | |
1390 | } | |
bc7ec91a | 1391 | if ($result && $oldversion < 2009021801) { |
1392 | /// Define field backuptype to be added to backup_log | |
382123a0 | 1393 | $table = new xmldb_table('backup_log'); |
2a88f626 | 1394 | $field = new xmldb_field('backuptype', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, 'info'); |
bc7ec91a | 1395 | /// Conditionally Launch add field backuptype and set all old records as 'scheduledbackup' records. |
1396 | if (!$dbman->field_exists($table, $field)) { | |
1397 | $dbman->add_field($table, $field); | |
1398 | $DB->execute("UPDATE {backup_log} SET backuptype='scheduledbackup'"); | |
1399 | } | |
75564228 | 1400 | |
bc7ec91a | 1401 | /// Main savepoint reached |
1402 | upgrade_main_savepoint($result, 2009021801); | |
1403 | } | |
af52ecee | 1404 | /// Add default sort order for question types. |
1405 | if ($result && $oldversion < 2009030300) { | |
1406 | set_config('multichoice_sortorder', 1, 'question'); | |
1407 | set_config('truefalse_sortorder', 2, 'question'); | |
1408 | set_config('shortanswer_sortorder', 3, 'question'); | |
1409 | set_config('numerical_sortorder', 4, 'question'); | |
1410 | set_config('calculated_sortorder', 5, 'question'); | |
1411 | set_config('essay_sortorder', 6, 'question'); | |
1412 | set_config('match_sortorder', 7, 'question'); | |
1413 | set_config('randomsamatch_sortorder', 8, 'question'); | |
1414 | set_config('multianswer_sortorder', 9, 'question'); | |
1415 | set_config('description_sortorder', 10, 'question'); | |
1416 | set_config('random_sortorder', 11, 'question'); | |
1417 | set_config('missingtype_sortorder', 12, 'question'); | |
1418 | ||
1419 | upgrade_main_savepoint($result, 2009030300); | |
1420 | } | |
a75c78d3 | 1421 | if ($result && $oldversion < 2009030501) { |
1422 | /// setup default repository plugins | |
1423 | require_once($CFG->dirroot . '/repository/lib.php'); | |
1424 | repository_setup_default_plugins(); | |
1425 | /// Main savepoint reached | |
1426 | upgrade_main_savepoint($result, 2009030501); | |
1427 | } | |
af52ecee | 1428 | |
82701e24 | 1429 | /// MDL-18132 replace the use a new Role allow switch settings page, instead of |
1430 | /// $CFG->allowuserswitchrolestheycantassign | |
1431 | if ($result && $oldversion < 2009032000) { | |
1432 | /// First create the new table. | |
1433 | $table = new xmldb_table('role_allow_switch'); | |
1434 | ||
1435 | /// Adding fields to table role_allow_switch | |
2a88f626 | 1436 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1437 | $table->add_field('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
1438 | $table->add_field('allowswitch', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
82701e24 | 1439 | |
1440 | /// Adding keys to table role_allow_switch | |
1441 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1442 | $table->add_key('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id')); | |
1443 | $table->add_key('allowswitch', XMLDB_KEY_FOREIGN, array('allowswitch'), 'role', array('id')); | |
1444 | ||
1445 | /// Adding indexes to table role_allow_switch | |
1446 | $table->add_index('roleid-allowoverride', XMLDB_INDEX_UNIQUE, array('roleid', 'allowswitch')); | |
1447 | ||
1448 | /// Conditionally launch create table for role_allow_switch | |
1449 | if (!$dbman->table_exists($table)) { | |
1450 | $dbman->create_table($table); | |
1451 | } | |
1452 | ||
1453 | /// Main savepoint reached | |
1454 | upgrade_main_savepoint($result, 2009032000); | |
1455 | } | |
0fc9c009 | 1456 | |
82701e24 | 1457 | if ($result && $oldversion < 2009032001) { |
1458 | /// Copy from role_allow_assign into the new table. | |
dc740f97 | 1459 | $DB->execute('INSERT INTO {role_allow_switch} (roleid, allowswitch) |
1460 | SELECT roleid, allowassign FROM {role_allow_assign}'); | |
82701e24 | 1461 | |
1462 | /// Unset the config variable used in 1.9. | |
1463 | unset_config('allowuserswitchrolestheycantassign'); | |
1464 | ||
1465 | /// Main savepoint reached | |
1466 | upgrade_main_savepoint($result, 2009032001); | |
1467 | } | |
c94985ef | 1468 | |
1469 | if ($result && $oldversion < 2009033100) { | |
1470 | require_once("$CFG->dirroot/filter/tex/lib.php"); | |
1471 | filter_tex_updatedcallback(null); | |
1472 | /// Main savepoint reached | |
1473 | upgrade_main_savepoint($result, 2009033100); | |
1474 | } | |
1475 | ||
0fc9c009 | 1476 | if ($result && $oldversion < 2009040300) { |
1477 | ||
1478 | /// Define table filter_active to be created | |
1479 | $table = new xmldb_table('filter_active'); | |
1480 | ||
1481 | /// Adding fields to table filter_active | |
2a88f626 | 1482 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1483 | $table->add_field('filter', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); | |
1484 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
1485 | $table->add_field('active', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null); | |
1486 | $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); | |
0fc9c009 | 1487 | |
1488 | /// Adding keys to table filter_active | |
1489 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1490 | $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); | |
1491 | ||
1492 | /// Adding indexes to table filter_active | |
1493 | $table->add_index('contextid-filter', XMLDB_INDEX_UNIQUE, array('contextid', 'filter')); | |
1494 | ||
1495 | /// Conditionally launch create table for filter_active | |
1496 | if (!$dbman->table_exists($table)) { | |
1497 | $dbman->create_table($table); | |
1498 | } | |
1499 | ||
1500 | /// Main savepoint reached | |
1501 | upgrade_main_savepoint($result, 2009040300); | |
1502 | } | |
1503 | ||
1504 | if ($result && $oldversion < 2009040301) { | |
1505 | ||
1506 | /// Define table filter_config to be created | |
1507 | $table = new xmldb_table('filter_config'); | |
1508 | ||
1509 | /// Adding fields to table filter_config | |
2a88f626 | 1510 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1511 | $table->add_field('filter', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); | |
1512 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
1513 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
1514 | $table->add_field('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null); | |
0fc9c009 | 1515 | |
1516 | /// Adding keys to table filter_config | |
1517 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1518 | $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); | |
1519 | ||
1520 | /// Adding indexes to table filter_config | |
1521 | $table->add_index('contextid-filter-name', XMLDB_INDEX_UNIQUE, array('contextid', 'filter', 'name')); | |
1522 | ||
1523 | /// Conditionally launch create table for filter_config | |
1524 | if (!$dbman->table_exists($table)) { | |
1525 | $dbman->create_table($table); | |
1526 | } | |
1527 | ||
1528 | /// Main savepoint reached | |
1529 | upgrade_main_savepoint($result, 2009040301); | |
1530 | } | |
1531 | ||
c07e6d8d | 1532 | if ($result && $oldversion < 2009040302) { |
1533 | /// Transfer current settings from $CFG->textfilters | |
1534 | $disabledfilters = filter_get_all_installed(); | |
1535 | if (empty($CFG->textfilters)) { | |
1536 | $activefilters = array(); | |
1537 | } else { | |
1538 | $activefilters = explode(',', $CFG->textfilters); | |
1539 | } | |
1540 | $syscontext = get_context_instance(CONTEXT_SYSTEM); | |
1541 | $sortorder = 1; | |
1542 | foreach ($activefilters as $filter) { | |
1543 | filter_set_global_state($filter, TEXTFILTER_ON, $sortorder); | |
1544 | $sortorder += 1; | |
1545 | unset($disabledfilters[$filter]); | |
1546 | } | |
1547 | foreach ($disabledfilters as $filter => $notused) { | |
1548 | filter_set_global_state($filter, TEXTFILTER_DISABLED, $sortorder); | |
1549 | $sortorder += 1; | |
1550 | } | |
1551 | ||
1552 | /// Main savepoint reached | |
1553 | upgrade_main_savepoint($result, 2009040302); | |
1554 | } | |
1555 | ||
bbb45905 | 1556 | if ($result && $oldversion < 2009040600) { |
1557 | /// Ensure that $CFG->stringfilters is set. | |
1558 | if (empty($CFG->stringfilters)) { | |
1559 | if (!empty($CFG->filterall)) { | |
1560 | set_config('stringfilters', $CFG->textfilters); | |
1561 | } else { | |
1562 | set_config('stringfilters', ''); | |
1563 | } | |
1564 | } | |
1565 | ||
1566 | set_config('filterall', !empty($CFG->stringfilters)); | |
1567 | unset_config('textfilters'); | |
1568 | ||
1569 | /// Main savepoint reached | |
1570 | upgrade_main_savepoint($result, 2009040600); | |
1571 | } | |
1572 | ||
e7c6bf0e | 1573 | if ($result && $oldversion < 2009041700) { |
1574 | /// To ensure the UI remains consistent with no behaviour change, any | |
1575 | /// 'until' date in an activity condition should have 1 second subtracted | |
1576 | /// (to go from 0:00 on the following day to 23:59 on the previous one). | |
1577 | $DB->execute('UPDATE {course_modules} SET availableuntil = availableuntil - 1 WHERE availableuntil <> 0'); | |
6861b6fe | 1578 | require_once($CFG->dirroot . '/course/lib.php'); |
0f9534c1 | 1579 | rebuild_course_cache(0, true); |
e7c6bf0e | 1580 | |
1581 | /// Main savepoint reached | |
1582 | upgrade_main_savepoint($result, 2009041700); | |
1583 | } | |
1584 | ||
6bdf4c99 | 1585 | if ($result && $oldversion < 2009042600) { |
1586 | /// Deleting orphaned messages from deleted users. | |
1587 | require_once($CFG->dirroot.'/message/lib.php'); | |
1588 | /// Detect deleted users with messages sent(useridfrom) and not read | |
1589 | if ($deletedusers = $DB->get_records_sql('SELECT DISTINCT u.id | |
1590 | FROM {user} u | |
1591 | JOIN {message} m ON m.useridfrom = u.id | |
1592 | WHERE u.deleted = ?', array(1))) { | |
1593 | foreach ($deletedusers as $deleteduser) { | |
1594 | message_move_userfrom_unread2read($deleteduser->id); // move messages | |
1595 | } | |
1596 | } | |
1597 | /// Main savepoint reached | |
1598 | upgrade_main_savepoint($result, 2009042600); | |
1599 | } | |
1600 | ||
e37cd84a | 1601 | /// Dropping all enums/check contraints from core. MDL-18577 |
1602 | if ($result && $oldversion < 2009042700) { | |
1603 | ||
1604 | /// Changing list of values (enum) of field stattype on table stats_daily to none | |
1605 | $table = new xmldb_table('stats_daily'); | |
2a88f626 | 1606 | $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid'); |
e37cd84a | 1607 | |
1608 | /// Launch change of list of values for field stattype | |
2a88f626 | 1609 | $dbman->drop_enum_from_field($table, $field); |
e37cd84a | 1610 | |
1611 | /// Changing list of values (enum) of field stattype on table stats_weekly to none | |
1612 | $table = new xmldb_table('stats_weekly'); | |
2a88f626 | 1613 | $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid'); |
e37cd84a | 1614 | |
1615 | /// Launch change of list of values for field stattype | |
2a88f626 | 1616 | $dbman->drop_enum_from_field($table, $field); |
e37cd84a | 1617 | |
1618 | /// Changing list of values (enum) of field stattype on table stats_monthly to none | |
1619 | $table = new xmldb_table('stats_monthly'); | |
2a88f626 | 1620 | $field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid'); |
e37cd84a | 1621 | |
1622 | /// Launch change of list of values for field stattype | |
2a88f626 | 1623 | $dbman->drop_enum_from_field($table, $field); |
e37cd84a | 1624 | |
1625 | /// Changing list of values (enum) of field publishstate on table post to none | |
1626 | $table = new xmldb_table('post'); | |
2a88f626 | 1627 | $field = new xmldb_field('publishstate', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'draft', 'attachment'); |
e37cd84a | 1628 | |
1629 | /// Launch change of list of values for field publishstate | |
2a88f626 | 1630 | $dbman->drop_enum_from_field($table, $field); |
e37cd84a | 1631 | |
1632 | /// Main savepoint reached | |
1633 | upgrade_main_savepoint($result, 2009042700); | |
1634 | } | |
1635 | ||
c045e45a | 1636 | if ($result && $oldversion < 2009043000) { |
1637 | unset_config('grade_report_showgroups'); | |
1638 | upgrade_main_savepoint($result, 2009043000); | |
1639 | } | |
1640 | ||
1641 | if ($result && $oldversion < 2009050600) { | |
e88462a0 | 1642 | /// Site front page blocks need to be moved due to page name change. |
1643 | $DB->set_field('block_instance', 'pagetype', 'site-index', array('pagetype' => 'course-view', 'pageid' => SITEID)); | |
1644 | ||
1645 | /// Main savepoint reached | |
c045e45a | 1646 | upgrade_main_savepoint($result, 2009050600); |
e88462a0 | 1647 | } |
1648 | ||
c045e45a | 1649 | if ($result && $oldversion < 2009050601) { |
66b10689 | 1650 | |
3aceb097 | 1651 | /// Define table block_instance to be renamed to block_instances |
66b10689 | 1652 | $table = new xmldb_table('block_instance'); |
1653 | ||
1654 | /// Launch rename table for block_instance | |
3aceb097 | 1655 | $dbman->rename_table($table, 'block_instances'); |
66b10689 | 1656 | |
1657 | /// Main savepoint reached | |
c045e45a | 1658 | upgrade_main_savepoint($result, 2009050601); |
66b10689 | 1659 | } |
1660 | ||
c045e45a | 1661 | if ($result && $oldversion < 2009050602) { |
66b10689 | 1662 | |
1663 | /// Define table block_instance to be renamed to block_instance_old | |
1664 | $table = new xmldb_table('block_pinned'); | |
1665 | ||
1666 | /// Launch rename table for block_instance | |
1667 | $dbman->rename_table($table, 'block_pinned_old'); | |
1668 | ||
1669 | /// Main savepoint reached | |
c045e45a | 1670 | upgrade_main_savepoint($result, 2009050602); |
66b10689 | 1671 | } |
1672 | ||
c045e45a | 1673 | if ($result && $oldversion < 2009050603) { |
66b10689 | 1674 | |
1675 | /// Define table block_instance_old to be created | |
1676 | $table = new xmldb_table('block_instance_old'); | |
1677 | ||
1678 | /// Adding fields to table block_instance_old | |
2b212777 | 1679 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1680 | $table->add_field('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
1681 | $table->add_field('blockid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); | |
1682 | $table->add_field('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); | |
1683 | $table->add_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null); | |
1684 | $table->add_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null); | |
1685 | $table->add_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0'); | |
1686 | $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0'); | |
1687 | $table->add_field('configdata', XMLDB_TYPE_TEXT, 'small', null, null, null, null); | |
66b10689 | 1688 | |
1689 | /// Adding keys to table block_instance_old | |
1690 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
1691 | $table->add_key('blockid', XMLDB_KEY_FOREIGN, array('blockid'), 'block', array('id')); | |
1692 | ||
1693 | /// Adding indexes to table block_instance_old | |
1694 | $table->add_index('pageid', XMLDB_INDEX_NOTUNIQUE, array('pageid')); | |
1695 | $table->add_index('pagetype', XMLDB_INDEX_NOTUNIQUE, array('pagetype')); | |
1696 | ||
1697 | /// Conditionally launch create table for block_instance_old | |
1698 | if (!$dbman->table_exists($table)) { | |
1699 | $dbman->create_table($table); | |
1700 | } | |
1701 | ||
1702 | /// Main savepoint reached | |
c045e45a | 1703 | upgrade_main_savepoint($result, 2009050603); |
66b10689 | 1704 | } |
1705 | ||
c045e45a | 1706 | if ($result && $oldversion < 2009050604) { |
66b10689 | 1707 | /// Copy current blocks data from block_instances to block_instance_old |
35550fd6 | 1708 | $DB->execute('INSERT INTO {block_instance_old} (oldid, blockid, pageid, pagetype, position, weight, visible, configdata) |
1709 | SELECT id, blockid, pageid, pagetype, position, weight, visible, configdata FROM {block_instances} ORDER BY id'); | |
66b10689 | 1710 | |
c045e45a | 1711 | upgrade_main_savepoint($result, 2009050604); |
66b10689 | 1712 | } |
1713 | ||
c045e45a | 1714 | if ($result && $oldversion < 2009050605) { |
66b10689 | 1715 | |
1716 | /// Define field multiple to be dropped from block | |
1717 | $table = new xmldb_table('block'); | |
1718 | $field = new xmldb_field('multiple'); | |
1719 | ||
1720 | /// Conditionally launch drop field multiple | |
1721 | if ($dbman->field_exists($table, $field)) { | |
1722 | $dbman->drop_field($table, $field); | |
1723 | } | |
1724 | ||
1725 | /// Main savepoint reached | |
c045e45a | 1726 | upgrade_main_savepoint($result, 2009050605); |
66b10689 | 1727 | } |
1728 | ||
c045e45a | 1729 | if ($result && $oldversion < 2009050606) { |
66b10689 | 1730 | $table = new xmldb_table('block_instances'); |
1731 | ||
1732 | /// Rename field weight on table block_instances to defaultweight | |
2b212777 | 1733 | $field = new xmldb_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0', 'position'); |
66b10689 | 1734 | $dbman->rename_field($table, $field, 'defaultweight'); |
1735 | ||
1736 | /// Rename field position on table block_instances to defaultregion | |
2b212777 | 1737 | $field = new xmldb_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, 'pagetype'); |
66b10689 | 1738 | $dbman->rename_field($table, $field, 'defaultregion'); |
1739 | ||
1740 | /// Main savepoint reached | |
c045e45a | 1741 | upgrade_main_savepoint($result, 2009050606); |
66b10689 | 1742 | } |
1743 | ||
c045e45a | 1744 | if ($result && $oldversion < 2009050607) { |
66b10689 | 1745 | /// Changing precision of field defaultregion on table block_instances to (16) |
a26146d5 | 1746 | $table = new xmldb_table('block_instances'); |
1747 | $field = new xmldb_field('defaultregion', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, 'pagetype'); | |
66b10689 | 1748 | |
1749 | /// Launch change of precision for field defaultregion | |
1750 | $dbman->change_field_precision($table, $field); | |
1751 | ||
1752 | /// Main savepoint reached | |
a26146d5 | 1753 | upgrade_main_savepoint($result, 2009050607); |
66b10689 | 1754 | } |
1755 | ||
c045e45a | 1756 | if ($result && $oldversion < 2009050608) { |
66b10689 | 1757 | /// Change regions to the new notation |
1758 | $DB->set_field('block_instances', 'defaultregion', 'side-pre', array('defaultregion' => 'l')); | |
1759 | $DB->set_field('block_instances', 'defaultregion', 'side-post', array('defaultregion' => 'r')); | |
1760 | $DB->set_field('block_instances', 'defaultregion', 'course-view-top', array('defaultregion' => 'c')); | |
1761 | // This third one is a custom value from contrib/patches/center_blocks_position_patch and the | |
1762 | // flex page course format. Hopefully this new value is an adequate alternative. | |
1763 | ||
1764 | /// Main savepoint reached | |
c045e45a | 1765 | upgrade_main_savepoint($result, 2009050608); |
66b10689 | 1766 | } |
1767 | ||
c045e45a | 1768 | if ($result && $oldversion < 2009050609) { |
66b10689 | 1769 | |
1770 | /// Define key blockname (unique) to be added to block | |
1771 | $table = new xmldb_table('block'); | |
1772 | $key = new xmldb_key('blockname', XMLDB_KEY_UNIQUE, array('name')); | |
1773 | ||
1774 | /// Launch add key blockname | |
1775 | $dbman->add_key($table, $key); | |
1776 | ||
1777 | /// Main savepoint reached | |
c045e45a | 1778 | upgrade_main_savepoint($result, 2009050609); |
66b10689 | 1779 | } |
1780 | ||
c045e45a | 1781 | if ($result && $oldversion < 2009050610) { |
66b10689 | 1782 | $table = new xmldb_table('block_instances'); |
1783 | ||
1784 | /// Define field blockname to be added to block_instances | |
2b212777 | 1785 | $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, null, null, null, 'blockid'); |
66b10689 | 1786 | if (!$dbman->field_exists($table, $field)) { |
1787 | $dbman->add_field($table, $field); | |
1788 | } | |
1789 | ||
1790 | /// Define field contextid to be added to block_instances | |
2b212777 | 1791 | $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'blockname'); |
66b10689 | 1792 | if (!$dbman->field_exists($table, $field)) { |
1793 | $dbman->add_field($table, $field); | |
1794 | } | |
1795 | ||
1796 | /// Define field showinsubcontexts to be added to block_instances | |
2b212777 | 1797 | $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, null, null, null, 'contextid'); |
66b10689 | 1798 | if (!$dbman->field_exists($table, $field)) { |
1799 | $dbman->add_field($table, $field); | |
1800 | } | |
1801 | ||
1802 | /// Define field subpagepattern to be added to block_instances | |
2b212777 | 1803 | $field = new xmldb_field('subpagepattern', XMLDB_TYPE_CHAR, '16', null, null, null, null, 'pagetype'); |
66b10689 | 1804 | if (!$dbman->field_exists($table, $field)) { |
1805 | $dbman->add_field($table, $field); | |
1806 | } | |
1807 | ||
1808 | /// Main savepoint reached | |
c045e45a | 1809 | upgrade_main_savepoint($result, 2009050610); |
66b10689 | 1810 | } |
1811 | ||
c045e45a | 1812 | if ($result && $oldversion < 2009050611) { |
66b10689 | 1813 | $table = new xmldb_table('block_instances'); |
1814 | ||
1815 | /// Fill in blockname from blockid | |
1816 | $DB->execute("UPDATE {block_instances} SET blockname = (SELECT name FROM {block} WHERE id = blockid)"); | |
1817 | ||
1818 | /// Set showinsubcontexts = 0 for all rows. | |
1819 | $DB->execute("UPDATE {block_instances} SET showinsubcontexts = 0"); | |
1820 | ||
1821 | /// Main savepoint reached | |
c045e45a | 1822 | upgrade_main_savepoint($result, 2009050611); |
66b10689 | 1823 | } |
1824 | ||
c045e45a | 1825 | if ($result && $oldversion < 2009050612) { |
66b10689 | 1826 | |
1827 | /// Rename field pagetype on table block_instances to pagetypepattern | |
1828 | $table = new xmldb_table('block_instances'); | |
2b212777 | 1829 | $field = new xmldb_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'pageid'); |
66b10689 | 1830 | |
1831 | /// Launch rename field pagetype | |
1832 | $dbman->rename_field($table, $field, 'pagetypepattern'); | |
1833 | ||
1834 | /// Main savepoint reached | |
c045e45a | 1835 | upgrade_main_savepoint($result, 2009050612); |
66b10689 | 1836 | } |
1837 | ||
c045e45a | 1838 | if ($result && $oldversion < 2009050613) { |
66b10689 | 1839 | /// fill in contextid and subpage, and update pagetypepattern from pagetype and pageid |
1840 | ||
1841 | /// site-index | |
1842 | $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID); | |
eb2761f8 | 1843 | $DB->execute("UPDATE {block_instances} SET contextid = " . $frontpagecontext->id . ", |
1844 | pagetypepattern = 'site-index', | |
1845 | subpagepattern = NULL | |
1846 | WHERE pagetypepattern = 'site-index'"); | |
66b10689 | 1847 | |
1848 | /// course-view | |
eb2761f8 | 1849 | $DB->execute("UPDATE {block_instances} SET |
1850 | contextid = ( | |
1851 | SELECT {context}.id | |
1852 | FROM {context} | |
1853 | JOIN {course} ON instanceid = {course}.id AND contextlevel = " . CONTEXT_COURSE . " | |
1854 | WHERE {course}.id = pageid | |
1855 | ), | |
1856 | pagetypepattern = 'course-view-*', | |
1857 | subpagepattern = NULL | |
1858 | WHERE pagetypepattern = 'course-view'"); | |
66b10689 | 1859 | |
1860 | /// admin | |
1861 | $syscontext = get_context_instance(CONTEXT_SYSTEM); | |
eb2761f8 | 1862 | $DB->execute("UPDATE {block_instances} SET |
1863 | contextid = " . $syscontext->id . ", | |
1864 | pagetypepattern = 'admin-*', | |
1865 | subpagepattern = NULL | |
1866 | WHERE pagetypepattern = 'admin'"); | |
66b10689 | 1867 | |
1868 | /// my-index | |
eb2761f8 | 1869 | $DB->execute("UPDATE {block_instances} SET |
1870 | contextid = ( | |
1871 | SELECT {context}.id | |
1872 | FROM {context} | |
1873 | JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . " | |
1874 | WHERE {user}.id = pageid | |
1875 | ), | |
1876 | pagetypepattern = 'my-index', | |
1877 | subpagepattern = NULL | |
1878 | WHERE pagetypepattern = 'my-index'"); | |
66b10689 | 1879 | |
1880 | /// tag-index | |
eb2761f8 | 1881 | $DB->execute("UPDATE {block_instances} SET |
1882 | contextid = " . $syscontext->id . ", | |
1883 | pagetypepattern = 'tag-index', | |
1884 | subpagepattern = pageid | |
1885 | WHERE pagetypepattern = 'tag-index'"); | |
66b10689 | 1886 | |
1887 | /// blog-view | |
eb2761f8 | 1888 | $DB->execute("UPDATE {block_instances} SET |
1889 | contextid = ( | |
1890 | SELECT {context}.id | |
1891 | FROM {context} | |
1892 | JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . " | |
1893 | WHERE {user}.id = pageid | |
1894 | ), | |
1895 | pagetypepattern = 'blog-index', | |
1896 | subpagepattern = NULL | |
1897 | WHERE pagetypepattern = 'blog-view'"); | |
66b10689 | 1898 | |
1899 | /// mod-xxx-view | |
1900 | $moduleswithblocks = array('chat', 'data', 'lesson', 'quiz', 'dimdim', 'game', 'wiki', 'oublog'); | |
1901 | foreach ($moduleswithblocks as $modname) { | |
1902 | if (!$dbman->table_exists($modname)) { | |
1903 | continue; | |
1904 | } | |
eb2761f8 | 1905 | $DB->execute("UPDATE {block_instances} SET |
1906 | contextid = ( | |
1907 | SELECT {context}.id | |
1908 | FROM {context} | |
1909 | JOIN {course_modules} ON instanceid = {course_modules}.id AND contextlevel = " . CONTEXT_MODULE . " | |
1910 | JOIN {modules} ON {modules}.id = {course_modules}.module AND {modules}.name = '$modname' | |
1911 | JOIN {{$modname}} ON {course_modules}.instance = {{$modname}}.id | |
1912 | WHERE {{$modname}}.id = pageid | |
1913 | ), | |
1914 | pagetypepattern = 'blog-index', | |
1915 | subpagepattern = NULL | |
1916 | WHERE pagetypepattern = 'blog-view'"); | |
66b10689 | 1917 | } |
1918 | ||
1919 | /// Main savepoint reached | |
c045e45a | 1920 | upgrade_main_savepoint($result, 2009050613); |
66b10689 | 1921 | } |
1922 | ||
c045e45a | 1923 | if ($result && $oldversion < 2009050614) { |
66b10689 | 1924 | /// fill in any missing contextids with a dummy value, so we can add the not-null constraint. |
bf659cf0 | 1925 | $DB->execute("UPDATE {block_instances} SET contextid = 0 WHERE contextid IS NULL"); |
66b10689 | 1926 | |
1927 | /// Main savepoint reached | |
c045e45a | 1928 | upgrade_main_savepoint($result, 2009050614); |
66b10689 | 1929 | } |
1930 | ||
c045e45a | 1931 | if ($result && $oldversion < 2009050615) { |
66b10689 | 1932 | $table = new xmldb_table('block_instances'); |
1933 | ||
57c3a358 EL |
1934 | /// Arrived here, any block_instances record without blockname is one |
1935 | /// orphan block coming from 1.9. Just delete them. MDL-22503 | |
1936 | $DB->delete_records_select('block_instances', 'blockname IS NULL'); | |
1937 | ||
66b10689 | 1938 | /// Changing nullability of field blockname on table block_instances to not null |
2b212777 | 1939 | $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'id'); |
66b10689 | 1940 | $dbman->change_field_notnull($table, $field); |
1941 | ||
1942 | /// Changing nullability of field contextid on table block_instances to not null | |
2b212777 | 1943 | $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'blockname'); |
66b10689 | 1944 | $dbman->change_field_notnull($table, $field); |
1945 | ||
1946 | /// Changing nullability of field showinsubcontexts on table block_instances to not null | |
2b212777 | 1947 | $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, 'contextid'); |
66b10689 | 1948 | $dbman->change_field_notnull($table, $field); |
1949 | ||
1950 | /// Main savepoint reached | |
c045e45a | 1951 | upgrade_main_savepoint($result, 2009050615); |
66b10689 | 1952 | } |
1953 | ||
c045e45a | 1954 | if ($result && $oldversion < 2009050616) { |
66b10689 | 1955 | /// Add exiting sticky blocks. |
1956 | $blocks = $DB->get_records('block'); | |
1957 | $syscontext = get_context_instance(CONTEXT_SYSTEM); | |
1958 | $newregions = array( | |
1959 | 'l' => 'side-pre', | |
1960 | 'r' => 'side-post', | |
1961 | 'c' => 'course-view-top', | |
1962 | ); | |
1963 | $stickyblocks = $DB->get_recordset('block_pinned_old'); | |
1964 | foreach ($stickyblocks as $stickyblock) { | |
93d3a250 | 1965 | $newblock = new object(); |
35fb85a7 | 1966 | $newblock->blockname = $blocks[$stickyblock->blockid]->name; |
66b10689 | 1967 | $newblock->contextid = $syscontext->id; |
1968 | $newblock->showinsubcontexts = 1; | |
1969 | switch ($stickyblock->pagetype) { | |
1970 | case 'course-view': | |
1971 | $newblock->pagetypepattern = 'course-view-*'; | |
1972 | break; | |
1973 | default: | |
1974 | $newblock->pagetypepattern = $stickyblock->pagetype; | |
1975 | } | |
1976 | $newblock->defaultregion = $newregions[$stickyblock->position]; | |
1977 | $newblock->defaultweight = $stickyblock->weight; | |
1978 | $newblock->configdata = $stickyblock->configdata; | |
01de485d | 1979 | $newblock->visible = 1; |
66b10689 | 1980 | $DB->insert_record('block_instances', $newblock); |
1981 | } | |
1982 | ||
1983 | /// Main savepoint reached | |
c045e45a | 1984 | upgrade_main_savepoint($result, 2009050616); |
66b10689 | 1985 | } |
1986 | ||
c045e45a | 1987 | if ($result && $oldversion < 2009050617) { |
66b10689 | 1988 | |
1989 | /// Define table block_positions to be created | |
1990 | $table = new xmldb_table('block_positions'); | |
1991 | ||
1992 | /// Adding fields to table block_positions | |
2b212777 | 1993 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); |
1994 | $table->add_field('blockinstanceid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); | |
1995 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
1996 | $table->add_field('pagetype', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null); | |
1997 | $table->add_field('subpage', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null); | |
1998 | $table->add_field('visible', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '1'); | |
1999 | $table->add_field('region', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null); | |
2000 | $table->add_field('weight', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); | |
66b10689 | 2001 | |
2002 | /// Adding keys to table block_positions | |
2003 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2004 | $table->add_key('blockinstanceid', XMLDB_KEY_FOREIGN, array('blockinstanceid'), 'block_instances', array('id')); | |
2005 | $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); | |
2006 | ||
2007 | /// Adding indexes to table block_positions | |
2008 | $table->add_index('blockinstanceid-contextid-pagetype-subpage', XMLDB_INDEX_UNIQUE, array('blockinstanceid', 'contextid', 'pagetype', 'subpage')); | |
2009 | ||
2010 | /// Conditionally launch create table for block_positions | |
2011 | if (!$dbman->table_exists($table)) { | |
2012 | $dbman->create_table($table); | |
2013 | } | |
2014 | ||
2015 | /// Main savepoint reached | |
c045e45a | 2016 | upgrade_main_savepoint($result, 2009050617); |
66b10689 | 2017 | } |
2018 | ||
c045e45a | 2019 | if ($result && $oldversion < 2009050618) { |
66b10689 | 2020 | /// And block instances with visible = 0, copy that information to block_positions |
2021 | $DB->execute("INSERT INTO {block_positions} (blockinstanceid, contextid, pagetype, subpage, visible, region, weight) | |
2022 | SELECT id, contextid, | |
2023 | CASE WHEN pagetypepattern = 'course-view-*' THEN | |
2024 | (SELECT " . $DB->sql_concat("'course-view-'", 'format') . " | |
2025 | FROM {course} | |
2026 | JOIN {context} ON {course}.id = {context}.instanceid | |
2027 | WHERE {context}.id = contextid) | |
2028 | ELSE pagetypepattern END, | |
2029 | CASE WHEN subpagepattern IS NULL THEN '' | |
2030 | ELSE subpagepattern END, | |
2031 | 0, defaultregion, defaultweight | |
2032 | FROM {block_instances} WHERE visible = 0 AND pagetypepattern <> 'admin-*'"); | |
2033 | ||
2034 | /// Main savepoint reached | |
c045e45a | 2035 | upgrade_main_savepoint($result, 2009050618); |
66b10689 | 2036 | } |
2037 | ||
c045e45a | 2038 | if ($result && $oldversion < 2009050619) { |
66b10689 | 2039 | $table = new xmldb_table('block_instances'); |
2040 | ||
2041 | /// Define field blockid to be dropped from block_instances | |
2042 | $field = new xmldb_field('blockid'); | |
2043 | if ($dbman->field_exists($table, $field)) { | |
4276a19a | 2044 | /// Before dropping the field, drop dependent indexes |
2045 | $index = new xmldb_index('blockid', XMLDB_INDEX_NOTUNIQUE, array('blockid')); | |
2046 | if ($dbman->index_exists($table, $index)) { | |
2047 | /// Launch drop index blockid | |
2048 | $dbman->drop_index($table, $index); | |
2049 | } | |
66b10689 | 2050 | $dbman->drop_field($table, $field); |
2051 | } | |
2052 | ||
2053 | /// Define field pageid to be dropped from block_instances | |
2054 | $field = new xmldb_field('pageid'); | |
2055 | if ($dbman->field_exists($table, $field)) { | |
4276a19a | 2056 | /// Before dropping the field, drop dependent indexes |
2057 | $index = new xmldb_index('pageid', XMLDB_INDEX_NOTUNIQUE, array('pageid')); | |
2058 | if ($dbman->index_exists($table, $index)) { | |
2059 | /// Launch drop index pageid | |
2060 | $dbman->drop_index($table, $index); | |
2061 | } | |
66b10689 | 2062 | $dbman->drop_field($table, $field); |
2063 | } | |
2064 | ||
2065 | /// Define field visible to be dropped from block_instances | |
2066 | $field = new xmldb_field('visible'); | |
2067 | if ($dbman->field_exists($table, $field)) { | |
2068 | $dbman->drop_field($table, $field); | |
2069 | } | |
2070 | ||
2071 | /// Main savepoint reached | |
c045e45a | 2072 | upgrade_main_savepoint($result, 2009050619); |
35079f53 | 2073 | } |
2074 | ||
ecdf5d17 | 2075 | if ($result && $oldversion < 2009051200) { |
2076 | /// Let's check the status of mandatory mnet_host records, fixing them | |
2077 | /// and moving "orphan" users to default localhost record. MDL-16879 | |
aa9a6867 | 2078 | echo $OUTPUT->notification('Fixing mnet records, this may take a while...', 'notifysuccess'); |
ecdf5d17 | 2079 | upgrade_fix_incorrect_mnethostids(); |
2080 | ||
2081 | /// Main savepoint reached | |
2082 | upgrade_main_savepoint($result, 2009051200); | |
2083 | } | |
2084 | ||
a5747cf8 | 2085 | |
2086 | if ($result && $oldversion < 2009051700) { | |
2087 | /// migrate editor settings | |
2088 | if (empty($CFG->htmleditor)) { | |
2089 | set_config('texteditors', 'textarea'); | |
2090 | } else { | |
2091 | set_config('texteditors', 'tinymce,textarea'); | |
2092 | } | |
2093 | ||
2094 | unset_config('htmleditor'); | |
2095 | unset_config('defaulthtmleditor'); | |
2096 | ||
2097 | /// Main savepoint reached | |
2098 | upgrade_main_savepoint($result, 2009051700); | |
2099 | } | |
2100 | ||
1aa01caf | 2101 | if ($result && $oldversion < 2009060200) { |
2102 | /// Define table files_cleanup to be dropped - not needed | |
2103 | $table = new xmldb_table('files_cleanup'); | |
2104 | ||
2105 | /// Conditionally launch drop table for files_cleanup | |
2106 | if ($dbman->table_exists($table)) { | |
2107 | $dbman->drop_table($table); | |
2108 | } | |
2109 | ||
2110 | /// Main savepoint reached | |
2111 | upgrade_main_savepoint($result, 2009060200); | |
2112 | } | |
2113 | ||
b4154c2d | 2114 | if ($result && $oldversion < 2009061300) { |
2115 | //TODO: copy this to the very beginning of this upgrade script so that we may log upgrade queries | |
2116 | ||
2117 | /// Define table log_queries to be created | |
2118 | $table = new xmldb_table('log_queries'); | |
2119 | ||
2120 | /// Adding fields to table log_queries | |
2121 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
2122 | $table->add_field('qtype', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2123 | $table->add_field('sqltext', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null); | |
2124 | $table->add_field('sqlparams', XMLDB_TYPE_TEXT, 'big', null, null, null, null); | |
2125 | $table->add_field('error', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); | |
2126 | $table->add_field('info', XMLDB_TYPE_TEXT, 'small', null, null, null, null); | |
2127 | $table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null); | |
2128 | $table->add_field('exectime', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null); | |
2129 | $table->add_field('timelogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2130 | ||
2131 | /// Adding keys to table log_queries | |
2132 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2133 | ||
2134 | /// Conditionally launch create table for log_queries | |
2135 | if (!$dbman->table_exists($table)) { | |
2136 | $dbman->create_table($table); | |
2137 | } | |
2138 | ||
2139 | /// Main savepoint reached | |
2140 | upgrade_main_savepoint($result, 2009061300); | |
2141 | } | |
2142 | ||
52902cea | 2143 | /// Repeat 2009050607 upgrade step, which Petr commented out becuase of XMLDB |
2144 | /// stupidity, so lots of peopel will have missed. | |
2145 | if ($result && $oldversion < 2009061600) { | |
2146 | /// Changing precision of field defaultregion on table block_instances to (16) | |
2147 | $table = new xmldb_table('block_instances'); | |
2148 | $field = new xmldb_field('defaultregion', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, 'configdata'); | |
2149 | ||
2150 | /// Launch change of precision for field defaultregion | |
2151 | $dbman->change_field_precision($table, $field); | |
2152 | ||
2153 | /// Main savepoint reached | |
2154 | upgrade_main_savepoint($result, 2009061600); | |
2155 | } | |
2156 | ||
17da2e6f | 2157 | if ($result && $oldversion < 2009061702) { |
2158 | // standardizing plugin names | |
2159 | if ($configs = $DB->get_records_select('config_plugins', "plugin LIKE 'quizreport_%'")) { | |
2160 | foreach ($configs as $config) { | |
61676608 | 2161 | unset_config($config->name, $config->plugin); /// unset old config |
17da2e6f | 2162 | $config->plugin = str_replace('quizreport_', 'quiz_', $config->plugin); |
61676608 | 2163 | set_config($config->name, $config->value, $config->plugin); /// set new config |
17da2e6f | 2164 | } |
2165 | } | |
2166 | unset($configs); | |
2167 | upgrade_main_savepoint($result, 2009061702); | |
2168 | } | |
2169 | ||
2170 | if ($result && $oldversion < 2009061703) { | |
2171 | // standardizing plugin names | |
2172 | if ($configs = $DB->get_records_select('config_plugins', "plugin LIKE 'assignment_type_%'")) { | |
2173 | foreach ($configs as $config) { | |
61676608 | 2174 | unset_config($config->name, $config->plugin); /// unset old config |
17da2e6f | 2175 | $config->plugin = str_replace('assignment_type_', 'assignment_', $config->plugin); |
61676608 | 2176 | set_config($config->name, $config->value, $config->plugin); /// set new config |
17da2e6f | 2177 | } |
2178 | } | |
2179 | unset($configs); | |
2180 | upgrade_main_savepoint($result, 2009061703); | |
2181 | } | |
2182 | ||
2183 | if ($result && $oldversion < 2009061704) { | |
13a0d3d3 | 2184 | // change component string in capability records to new "_" format |
17da2e6f | 2185 | if ($caps = $DB->get_records('capabilities')) { |
2186 | foreach ($caps as $cap) { | |
2187 | $cap->component = str_replace('/', '_', $cap->component); | |
2188 | $DB->update_record('capabilities', $cap); | |
2189 | } | |
2190 | } | |
2191 | unset($caps); | |
2192 | upgrade_main_savepoint($result, 2009061704); | |
2193 | } | |
2194 | ||
2195 | if ($result && $oldversion < 2009061705) { | |
13a0d3d3 | 2196 | // change component string in events_handlers records to new "_" format |
17da2e6f | 2197 | if ($handlers = $DB->get_records('events_handlers')) { |
2198 | foreach ($handlers as $handler) { | |
2199 | $handler->handlermodule = str_replace('/', '_', $handler->handlermodule); | |
2200 | $DB->update_record('events_handlers', $handler); | |
2201 | } | |
2202 | } | |
2203 | unset($handlers); | |
2204 | upgrade_main_savepoint($result, 2009061705); | |
2205 | } | |
2206 | ||
2207 | if ($result && $oldversion < 2009061706) { | |
13a0d3d3 | 2208 | // change component string in message_providers records to new "_" format |
17da2e6f | 2209 | if ($mps = $DB->get_records('message_providers')) { |
2210 | foreach ($mps as $mp) { | |
2211 | $mp->component = str_replace('/', '_', $mp->component); | |
2212 | $DB->update_record('message_providers', $cap); | |
2213 | } | |
2214 | } | |
2215 | unset($caps); | |
2216 | upgrade_main_savepoint($result, 2009061706); | |
2217 | } | |
13a0d3d3 | 2218 | |
adf8f3f9 | 2219 | if ($result && $oldversion < 2009063000) { |
2220 | // upgrade format of _with_advanced settings - quiz only | |
2221 | // note: this can be removed later, not needed for upgrades from 1.9.x | |
c1f58efe | 2222 | if ($quiz = get_config('quiz')) { |
2223 | foreach ($quiz as $name=>$value) { | |
2224 | if (strpos($name, 'fix_') !== 0) { | |
2225 | continue; | |
2226 | } | |
2227 | $newname = substr($name,4).'_adv'; | |
2228 | set_config($newname, $value, 'quiz'); | |
2229 | unset_config($name, 'quiz'); | |
adf8f3f9 | 2230 | } |
13a0d3d3 | 2231 | } |
adf8f3f9 | 2232 | upgrade_main_savepoint($result, 2009063000); |
2233 | } | |
13a0d3d3 | 2234 | |
13a0d3d3 | 2235 | if ($result && $oldversion < 2009071000) { |
2236 | ||
2237 | /// Rename field contextid on table block_instances to parentcontextid | |
2238 | $table = new xmldb_table('block_instances'); | |
2239 | $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, 'blockname'); | |
2240 | ||
2241 | /// Launch rename field parentcontextid | |
2242 | $dbman->rename_field($table, $field, 'parentcontextid'); | |
2243 | ||
2244 | /// Main savepoint reached | |
2245 | upgrade_main_savepoint($result, 2009071000); | |
2246 | } | |
2247 | ||
e92c286c | 2248 | if ($result && $oldversion < 2009071300) { |
2249 | ||
2250 | /// Create contexts for every block. In the past, only non-sticky course block had contexts. | |
2251 | /// This is a copy of the code in create_contexts. | |
2252 | $sql = "INSERT INTO {context} (contextlevel, instanceid) | |
2253 | SELECT " . CONTEXT_BLOCK . ", bi.id | |
2254 | FROM {block_instances} bi | |
2255 | WHERE NOT EXISTS (SELECT 'x' | |
2256 | FROM {context} ctx | |
2257 | WHERE bi.id = ctx.instanceid AND ctx.contextlevel=" . CONTEXT_BLOCK . ")"; | |
2258 | $DB->execute($sql); | |
2259 | ||
2260 | /// TODO MDL-19776 We should not really use API funcitons in upgrade. | |
2261 | /// If MDL-19776 is done, we can remove this whole upgrade block. | |
2262 | build_context_path(); | |
2263 | ||
2264 | /// Main savepoint reached | |
2265 | upgrade_main_savepoint($result, 2009071300); | |
2266 | } | |
1918f7e0 | 2267 | |
cae83708 | 2268 | if ($result && $oldversion < 2009071600) { |
2269 | ||
2270 | /// Define field summaryformat to be added to post | |
2271 | $table = new xmldb_table('post'); | |
2272 | $field = new xmldb_field('summaryformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'format'); | |
2273 | ||
2274 | /// Conditionally launch add field summaryformat | |
2275 | if (!$dbman->field_exists($table, $field)) { | |
2276 | $dbman->add_field($table, $field); | |
2277 | } | |
2278 | ||
2279 | /// Main savepoint reached | |
2280 | upgrade_main_savepoint($result, 2009071600); | |
2281 | } | |
e92c286c | 2282 | |
1bcb7eb5 | 2283 | if ($result && $oldversion < 2009072400) { |
2284 | ||
2285 | /// Define table comments to be created | |
2286 | $table = new xmldb_table('comments'); | |
2287 | ||
2288 | /// Adding fields to table comments | |
2289 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
2290 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2291 | $table->add_field('commentarea', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
2292 | $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2293 | $table->add_field('content', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); | |
2294 | $table->add_field('format', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); | |
2295 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2296 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2297 | ||
2298 | /// Adding keys to table comments | |
2299 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2300 | ||
2301 | /// Conditionally launch create table for comments | |
2302 | if (!$dbman->table_exists($table)) { | |
2303 | $dbman->create_table($table); | |
2304 | } | |
0a127169 | 2305 | |
1bcb7eb5 | 2306 | /// Main savepoint reached |
2307 | upgrade_main_savepoint($result, 2009072400); | |
2308 | } | |
2309 | ||
7d2a0492 | 2310 | /** |
2311 | * This upgrade is to set up the new navigation blocks that have been developed | |
2312 | * as part of Moodle 2.0 | |
2313 | * Now I [Sam Hemelryk] hit a conundrum while exploring how to go about this | |
2314 | * as not only do we want to install the new blocks but we also want to set up | |
2315 | * default instances of them, and at the same time remove instances of the blocks | |
2316 | * that were/will-be outmoded by the two new navigation blocks. | |
2317 | * After talking it through with Tim Hunt {@link http://moodle.org/mod/cvsadmin/view.php?conversationid=3112} | |
2318 | * we decided that the best way to go about this was to put the bulk of the | |
2319 | * upgrade operation into core upgrade `here` but to let the plugins block | |
2320 | * still install the blocks. | |
2321 | * This leaves one hairy end in that we will create block_instances within the | |
2322 | * DB before the blocks themselves are created within the DB | |
2323 | */ | |
2324 | if ($result && $oldversion < 2009082800) { | |
2325 | ||
2326 | echo $OUTPUT->notification(get_string('navigationupgrade', 'admin')); | |
2327 | ||
2328 | // Get the system context so we can set the block instances to it | |
2329 | $syscontext = get_context_instance(CONTEXT_SYSTEM); | |
2330 | ||
2331 | // An array to contain the new block instances we will create | |
2332 | $newblockinstances = array('globalnavigation'=>new stdClass,'settingsnavigation'=>new stdClass); | |
2333 | // The new global navigation block instance as a stdClass | |
2334 | $newblockinstances['globalnavigation']->blockname = 'global_navigation_tree'; | |
2335 | $newblockinstances['globalnavigation']->parentcontextid = $syscontext->id; // System context | |
2336 | $newblockinstances['globalnavigation']->showinsubcontexts = true; // Show absolutly everywhere | |
2337 | $newblockinstances['globalnavigation']->pagetypepattern = '*'; // Thats right everywhere | |
2338 | $newblockinstances['globalnavigation']->subpagetypepattern = null; | |
2339 | $newblockinstances['globalnavigation']->defaultregion = BLOCK_POS_LEFT; | |
2340 | $newblockinstances['globalnavigation']->defaultweight = -10; // Try make this first | |
2341 | $newblockinstances['globalnavigation']->configdata = ''; | |
2342 | // The new settings navigation block instance as a stdClass | |
2343 | $newblockinstances['settingsnavigation']->blockname = 'settings_navigation_tree'; | |
2344 | $newblockinstances['settingsnavigation']->parentcontextid = $syscontext->id; | |
2345 | $newblockinstances['settingsnavigation']->showinsubcontexts = true; | |
2346 | $newblockinstances['settingsnavigation']->pagetypepattern = '*'; | |
2347 | $newblockinstances['settingsnavigation']->subpagetypepattern = null; | |
2348 | $newblockinstances['settingsnavigation']->defaultregion = BLOCK_POS_LEFT; | |
2349 | $newblockinstances['settingsnavigation']->defaultweight = -9; // Try make this second | |
2350 | $newblockinstances['settingsnavigation']->configdata = ''; | |
2351 | ||
2352 | // Blocks that are outmoded and for whom the bells will toll... by which I | |
2353 | // mean we will delete all instances of | |
2354 | $outmodedblocks = array('participants','admin_tree','activity_modules','admin','course_list'); | |
2355 | $outmodedblocksstring = '\''.join('\',\'',$outmodedblocks).'\''; | |
2356 | unset($outmodedblocks); | |
2357 | // Retrieve the block instance id's and parent contexts, so we can join them an GREATLY | |
2358 | // cut down the number of delete queries we will need to run | |
2359 | $allblockinstances = $DB->get_recordset_select('block_instances', 'blockname IN ('.$outmodedblocksstring.')', array(), '', 'id, parentcontextid'); | |
1918f7e0 | 2360 | |
7d2a0492 | 2361 | $contextids = array(); |
2362 | $instanceids = array(); | |
2363 | // Iterate through all block instances | |
2364 | foreach ($allblockinstances as $blockinstance) { | |
2365 | if (!in_array($blockinstance->parentcontextid, $contextids)) { | |
2366 | $contextids[] = $blockinstance->parentcontextid; | |
2367 | ||
2368 | // If we have over 1000 contexts clean them up and reset the array | |
2369 | // this ensures we don't hit any nasty memory limits or such | |
2370 | if (count($contextids) > 1000) { | |
61676608 | 2371 | upgrade_cleanup_unwanted_block_contexts($contextids); |
7d2a0492 | 2372 | $contextids = array(); |
2373 | } | |
2374 | } | |
2375 | if (!in_array($blockinstance->id, $instanceids)) { | |
2376 | $instanceids[] = $blockinstance->id; | |
2377 | // If we have more than 1000 block instances now remove all block positions | |
2378 | // and empty the array | |
2379 | if (count($contextids) > 1000) { | |
2380 | $instanceidstring = join(',',$instanceids); | |
61676608 | 2381 | $DB->delete_records_select('block_positions', 'blockinstanceid IN ('.$instanceidstring.')'); |
7d2a0492 | 2382 | $instanceids = array(); |
2383 | } | |
2384 | } | |
2385 | } | |
2386 | ||
61676608 | 2387 | upgrade_cleanup_unwanted_block_contexts($contextids); |
7d2a0492 | 2388 | |
2389 | $instanceidstring = join(',',$instanceids); | |
2390 | $outcome1 = $result && $DB->delete_records_select('block_positions', 'blockinstanceid IN ('.$instanceidstring.')'); | |
1918f7e0 | 2391 | |
7d2a0492 | 2392 | unset($allblockinstances); |
2393 | unset($contextids); | |
2394 | unset($instanceids); | |
2395 | unset($instanceidstring); | |
1918f7e0 | 2396 | |
7d2a0492 | 2397 | // Now remove the actual block instance |
7874b33d | 2398 | $DB->delete_records_select('block_instances', 'blockname IN ('.$outmodedblocksstring.')'); |
7d2a0492 | 2399 | unset($outmodedblocksstring); |
2400 | ||
2401 | // Insert the new block instances. Remember they have not been installed yet | |
2402 | // however this should not be a problem | |
2403 | foreach ($newblockinstances as $blockinstance) { | |
2404 | $blockinstance->id= $DB->insert_record('block_instances', $blockinstance); | |
2405 | // Ensure the block context is created. | |
2406 | get_context_instance(CONTEXT_BLOCK, $blockinstance->id); | |
2407 | } | |
2408 | unset($newblockinstances); | |
1918f7e0 | 2409 | |
7d2a0492 | 2410 | upgrade_main_savepoint($result, 2009082800); |
2411 | // The end of the navigation upgrade | |
2412 | } | |
2413 | ||
b89e4ad8 | 2414 | if ($result && $oldversion < 2009090800){ |
2415 | //insert new record for log_display table | |
2416 | //used to record tag update. | |
2417 | if (!$DB->record_exists('log_display', array('action'=>'update', 'module'=>'tag'))) { | |
2418 | $log_action = new object(); | |
2419 | $log_action->module = 'tag'; | |
2420 | $log_action->action = 'update'; | |
2421 | $log_action->mtable = 'tag'; | |
2422 | $log_action->field = 'name'; | |
2423 | ||
2424 | $result = $result && $DB->insert_record('log_display', $log_action); | |
2425 | } | |
2426 | upgrade_main_savepoint($result, 2009090800); | |
2427 | } | |
4313fa89 | 2428 | |
88af54fa | 2429 | if ($result && $oldversion < 2009100601) { |
5d820ca2 | 2430 | // drop all previous tables defined during the dev phase |
5b9a70a1 | 2431 | $dropold = array('external_services_users', 'external_services_functions', 'external_services', 'external_functions'); |
5d820ca2 | 2432 | foreach ($dropold as $tablename) { |
2433 | $table = new xmldb_table($tablename); | |
2434 | if ($dbman->table_exists($table)) { | |
2435 | $dbman->drop_table($table); | |
2436 | } | |
4313fa89 | 2437 | } |
88af54fa | 2438 | upgrade_main_savepoint($result, 2009100601); |
5d820ca2 | 2439 | } |
4313fa89 | 2440 | |
88af54fa | 2441 | if ($result && $oldversion < 2009100602) { |
4313fa89 | 2442 | /// Define table external_functions to be created |
2443 | $table = new xmldb_table('external_functions'); | |
2444 | ||
2445 | /// Adding fields to table external_functions | |
2446 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
5d820ca2 | 2447 | $table->add_field('name', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null); |
2448 | $table->add_field('classname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); | |
2449 | $table->add_field('methodname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); | |
2450 | $table->add_field('classpath', XMLDB_TYPE_CHAR, '255', null, null, null, null); | |
4313fa89 | 2451 | $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null); |
4313fa89 | 2452 | |
2453 | /// Adding keys to table external_functions | |
2454 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2455 | ||
5d820ca2 | 2456 | /// Adding indexes to table external_functions |
2457 | $table->add_index('name', XMLDB_INDEX_UNIQUE, array('name')); | |
2458 | ||
2459 | /// Launch create table for external_functions | |
2460 | $dbman->create_table($table); | |
4313fa89 | 2461 | |
5d820ca2 | 2462 | /// Main savepoint reached |
88af54fa | 2463 | upgrade_main_savepoint($result, 2009100602); |
5d820ca2 | 2464 | } |
4313fa89 | 2465 | |
88af54fa | 2466 | if ($result && $oldversion < 2009100603) { |
4313fa89 | 2467 | /// Define table external_services to be created |
2468 | $table = new xmldb_table('external_services'); | |
2469 | ||
2470 | /// Adding fields to table external_services | |
2471 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
5d820ca2 | 2472 | $table->add_field('name', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null); |
2473 | $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2474 | $table->add_field('requiredcapability', XMLDB_TYPE_CHAR, '150', null, null, null, null); | |
2475 | $table->add_field('restrictedusers', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2476 | $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, null, null, null); | |
4313fa89 | 2477 | |
2478 | /// Adding keys to table external_services | |
2479 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2480 | ||
5b9a70a1 | 2481 | /// Adding indexes to table external_services |
2482 | $table->add_index('name', XMLDB_INDEX_UNIQUE, array('name')); | |
2483 | ||
5d820ca2 | 2484 | /// Launch create table for external_services |
2485 | $dbman->create_table($table); | |
4313fa89 | 2486 | |
5d820ca2 | 2487 | /// Main savepoint reached |
88af54fa | 2488 | upgrade_main_savepoint($result, 2009100603); |
5d820ca2 | 2489 | } |
4313fa89 | 2490 | |
88af54fa | 2491 | if ($result && $oldversion < 2009100604) { |
4313fa89 | 2492 | /// Define table external_services_functions to be created |
2493 | $table = new xmldb_table('external_services_functions'); | |
2494 | ||
2495 | /// Adding fields to table external_services_functions | |
2496 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
2497 | $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
5d820ca2 | 2498 | $table->add_field('functionname', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null); |
4313fa89 | 2499 | |
2500 | /// Adding keys to table external_services_functions | |
2501 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
5d820ca2 | 2502 | $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id')); |
4313fa89 | 2503 | |
5d820ca2 | 2504 | /// Launch create table for external_services_functions |
2505 | $dbman->create_table($table); | |
2506 | ||
2507 | /// Main savepoint reached | |
88af54fa | 2508 | upgrade_main_savepoint($result, 2009100604); |
5d820ca2 | 2509 | } |
2510 | ||
88af54fa | 2511 | if ($result && $oldversion < 2009100605) { |
5d820ca2 | 2512 | /// Define table external_services_users to be created |
2513 | $table = new xmldb_table('external_services_users'); | |
2514 | ||
2515 | /// Adding fields to table external_services_users | |
2516 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
2517 | $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2518 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
88af54fa | 2519 | $table->add_field('iprestriction', XMLDB_TYPE_CHAR, '255', null, null, null, null); |
2520 | $table->add_field('validuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); | |
2521 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); | |
5d820ca2 | 2522 | |
2523 | /// Adding keys to table external_services_users | |
2524 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2525 | $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id')); | |
2526 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
2527 | ||
2528 | /// Launch create table for external_services_users | |
2529 | $dbman->create_table($table); | |
4313fa89 | 2530 | |
2531 | /// Main savepoint reached | |
88af54fa | 2532 | upgrade_main_savepoint($result, 2009100605); |
4313fa89 | 2533 | } |
2534 | ||
1942103f PS |
2535 | if ($result && $oldversion < 2009102600) { |
2536 | ||
2537 | /// Define table external_tokens to be created | |
2538 | $table = new xmldb_table('external_tokens'); | |
2539 | ||
2540 | /// Adding fields to table external_tokens | |
2541 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
2542 | $table->add_field('token', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null); | |
2543 | $table->add_field('tokentype', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2544 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2545 | $table->add_field('externalserviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2546 | $table->add_field('sid', XMLDB_TYPE_CHAR, '128', null, null, null, null); | |
2547 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2548 | $table->add_field('iprestriction', XMLDB_TYPE_CHAR, '255', null, null, null, null); | |
2549 | $table->add_field('validuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); | |
2550 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2551 | $table->add_field('lastaccess', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); | |
2552 | ||
2553 | /// Adding keys to table external_tokens | |
2554 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2555 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
2556 | $table->add_key('externalserviceid', XMLDB_KEY_FOREIGN, array('externalserviceid'), 'external_services', array('id')); | |
2557 | $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); | |
2558 | ||
2559 | /// Launch create table for external_tokens | |
2560 | $dbman->create_table($table); | |
2561 | ||
2562 | /// Main savepoint reached | |
2563 | upgrade_main_savepoint($result, 2009102600); | |
2564 | } | |
2565 | ||
cc82aef6 NC |
2566 | if ($result && $oldversion < 2009103000) { |
2567 | ||
2568 | /// Define table blog_association to be created | |
2569 | $table = new xmldb_table('blog_association'); | |
2570 | ||
2571 | /// Adding fields to table blog_association | |
2572 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
2573 | $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2574 | $table->add_field('blogid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2575 | ||
2576 | /// Adding keys to table blog_association | |
2577 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2578 | $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); | |
2579 | $table->add_key('blogid', XMLDB_KEY_FOREIGN, array('blogid'), 'post', array('id')); | |
2580 | ||
2581 | /// Conditionally launch create table for blog_association | |
2582 | if (!$dbman->table_exists($table)) { | |
2583 | $dbman->create_table($table); | |
2584 | } | |
2585 | ||
2586 | /// Define table blog_external to be created | |
2587 | $table = new xmldb_table('blog_external'); | |
2588 | ||
2589 | /// Adding fields to table blog_external | |
2590 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
2591 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
2592 | $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); | |
2593 | $table->add_field('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null); | |
2594 | $table->add_field('url', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null); | |
2595 | $table->add_field('filtertags', XMLDB_TYPE_CHAR, '255', null, null, null, null); | |
2596 | $table->add_field('failedlastsync', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); | |
2597 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null); | |
2598 | $table->add_field('timefetched', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); | |
2599 | ||
2600 | /// Adding keys to table blog_external | |
2601 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2602 | $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
2603 | ||
2604 | /// Conditionally launch create table for blog_external | |
2605 | if ($dbman->table_exists($table)) { | |
2606 | // Delete the existing one first (comes from early dev version) | |
2607 | $dbman->drop_table($table); | |
2608 | } | |
2609 | $dbman->create_table($table); | |
2610 | ||
adf176d7 | 2611 | // now inform admins that some settings require attention after upgrade |
cc82aef6 NC |
2612 | if (($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL) && empty($CFG->bloglevel_upgrade_complete)) { |
2613 | echo $OUTPUT->notification(get_string('bloglevelupgradenotice', 'admin')); | |
2614 | ||
cc82aef6 NC |
2615 | $site = get_site(); |
2616 | ||
2617 | $a = new StdClass; | |
2618 | $a->sitename = $site->fullname; | |
2619 | $a->fixurl = "$CFG->wwwroot/$CFG->admin/bloglevelupgrade.php"; | |
2620 | ||
c01678b1 PS |
2621 | $subject = get_string('bloglevelupgrade', 'admin'); |
2622 | $description = get_string('bloglevelupgradedescription', 'admin', $a); | |
2623 | ||
2624 | // can not use messaging here because it is not configured yet! | |
2625 | upgrade_log(UPGRADE_LOG_NOTICE, null, $subject, $description); | |
cc82aef6 NC |
2626 | } |
2627 | /// Main savepoint reached | |
2628 | upgrade_main_savepoint($result, 2009103000); | |
2629 | } | |
117bd748 | 2630 | |
8bdc9cac SH |
2631 | if ($result && $oldversion < 2009110400) { |
2632 | ||
2633 | // An array used to store the table name and keys of summary and trust fields | |
2634 | // to be added | |
2635 | $extendtables = array(); | |
2636 | $extendtables['course'] = array('summaryformat'); | |
2637 | $extendtables['course_categories'] = array('descriptionformat'); | |
2638 | $extendtables['course_request'] = array('summaryformat'); | |
2639 | $extendtables['grade_outcomes'] = array('descriptionformat'); | |
2640 | $extendtables['groups'] = array('descriptionformat'); | |
2641 | $extendtables['groupings'] = array('descriptionformat'); | |
2642 | $extendtables['scale'] = array('descriptionformat'); | |
2643 | $extendtables['user'] = array('descriptionformat'); | |
2644 | $extendtables['user_info_field'] = array('descriptionformat', 'defaultdataformat'); | |
2645 | $extendtables['user_info_data'] = array('dataformat'); | |
2646 | ||
2647 | foreach ($extendtables as $tablestr=>$newfields) { | |
2648 | $table = new xmldb_table($tablestr); | |
2649 | foreach ($newfields as $fieldstr) { | |
2650 | $field = new xmldb_field($fieldstr, XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); | |
2651 | // Check that the field doesn't already exists | |
2652 | if (!$dbman->field_exists($table, $field)) { | |
2653 | // Add the new field | |
2654 | $dbman->add_field($table, $field); | |
2655 | // Update the field if the text contains the default FORMAT_MOODLE to FORMAT_HTML | |
2656 | if (($pos = strpos($fieldstr, 'format'))>0) { | |
2657 | upgrade_set_timeout(60*20); // this may take a little while | |
2658 | $params = array(FORMAT_HTML, '<p%', '%<br />%', FORMAT_MOODLE); | |
2659 | $textfield = substr($fieldstr, 0, $pos); | |
cb8a83bb | 2660 | $DB->execute('UPDATE {'.$tablestr.'} SET '.$fieldstr.'=? WHERE ('.$textfield.' LIKE ? OR '.$textfield.' LIKE ?) AND '.$fieldstr.'=?', $params); |
8bdc9cac SH |
2661 | } |
2662 | } | |
2663 | } | |
2664 | } | |
2665 | ||
2666 | unset($extendtables); | |
2667 | ||
2668 | upgrade_main_savepoint($result, 2009110400); | |
2669 | } | |
2670 | ||
975341d1 | 2671 | if ($result && $oldversion < 2009110605) { |
2672 | ||
2673 | /// Define field timecreated to be added to external_services | |
2674 | $table = new xmldb_table('external_services'); | |
2675 | $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'component'); | |
2676 | ||
2677 | /// Conditionally launch add field timecreated | |
2678 | if (!$dbman->field_exists($table, $field)) { | |
2679 | $dbman->add_field($table, $field); | |
2680 | } | |
2681 | ||
2682 | /// Define field timemodified to be added to external_services | |
2683 | $table = new xmldb_table('external_services'); | |
2684 | $field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'timecreated'); | |
2685 | ||
2686 | /// Conditionally launch add field timemodified | |
2687 | if (!$dbman->field_exists($table, $field)) { | |
2688 | $dbman->add_field($table, $field); | |
2689 | } | |
2690 | ||
2691 | /// Main savepoint reached | |
2692 | upgrade_main_savepoint($result, 2009110605); | |
2693 | } | |
2694 | ||
e1b9ac3e PL |
2695 | if ($result && $oldversion < 2009111600) { |
2696 | ||
2697 | /// Define field instance to be added to portfolio_tempdata | |
2698 | $table = new xmldb_table('portfolio_tempdata'); | |
2699 | $field = new xmldb_field('instance', XMLDB_TYPE_INTEGER, '10', null, null, null, '0', 'userid'); | |
2700 | ||
2701 | /// Conditionally launch add field instance | |
2702 | if (!$dbman->field_exists($table, $field)) { | |
2703 | $dbman->add_field($table, $field); | |
2704 | } | |
2705 | ||
2706 | $key = new xmldb_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id')); | |
2707 | ||
2708 | /// Launch add key instancefk | |
2709 | $dbman->add_key($table, $key); | |
2710 | ||
2711 | /// Main savepoint reached | |
2712 | upgrade_main_savepoint($result, 2009111600); | |
2713 | } | |
2714 | ||
45645bce PL |
2715 | if ($result && $oldversion < 2009111700) { |
2716 | ||
2717 | /// Define field tempdataid to be added to portfolio_log | |
2718 | $table = new xmldb_table('portfolio_log'); | |
2719 | $field = new xmldb_field('tempdataid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'caller_sha1'); | |
2720 | ||
2721 | /// Conditionally launch add field tempdataid | |
2722 | if (!$dbman->field_exists($table, $field)) { | |
2723 | $dbman->add_field($table, $field); | |
2724 | } | |
2725 | ||
2726 | /// Main savepoint reached | |
2727 | upgrade_main_savepoint($result, 2009111700); | |
2728 | } | |
2729 | ||
eeb7ccf0 PL |
2730 | if ($result && $oldversion < 2009111701) { |
2731 | ||
2732 | /// Define field returnurl to be added to portfolio_log | |
2733 | $table = new xmldb_table('portfolio_log'); | |
2734 | $field = new xmldb_field('returnurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'tempdataid'); | |
2735 | ||
2736 | /// Conditionally launch add field returnurl | |
2737 | if (!$dbman->field_exists($table, $field)) { | |
2738 | $dbman->add_field($table, $field); | |
2739 | } | |
2740 | ||
2741 | /// Main savepoint reached | |
2742 | upgrade_main_savepoint($result, 2009111701); | |
2743 | } | |
2744 | ||
2745 | if ($result && $oldversion < 2009111702) { | |
2746 | ||
2747 | /// Define field continueurl to be added to portfolio_log | |
2748 | $table = new xmldb_table('portfolio_log'); | |
2749 | $field = new xmldb_field('continueurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'returnurl'); | |
2750 | ||
2751 | /// Conditionally launch add field continueurl | |
2752 | if (!$dbman->field_exists($table, $field)) { | |
2753 | $dbman->add_field($table, $field); | |
2754 | } | |
2755 | ||
2756 | /// Main savepoint reached | |
2757 | upgrade_main_savepoint($result, 2009111702); | |
2758 | } | |
2759 | ||
57e6ce5e PS |
2760 | if ($result && $oldversion < 2009112400) { |
2761 | if (empty($CFG->passwordsaltmain)) { | |
2762 | $subject = get_string('check_passwordsaltmain_name', 'report_security'); | |
2763 | $description = get_string('check_passwordsaltmain_warning', 'report_security');; | |
2764 | upgrade_log(UPGRADE_LOG_NOTICE, null, $subject, $description); | |
2765 | } | |
2766 | upgrade_main_savepoint($result, 2009112400); | |
2767 | } | |
e1b9ac3e | 2768 | |
5ae9f539 | 2769 | if ($result && $oldversion < 2010010601) { |
2770 | ||
2771 | /// Define field creatorid to be added to external_tokens | |
2772 | $table = new xmldb_table('external_tokens'); | |
2773 | $field = new xmldb_field('creatorid', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'contextid'); | |
2774 | ||
2775 | /// Conditionally launch add field creatorid | |
2776 | if (!$dbman->field_exists($table, $field)) { | |
2777 | $dbman->add_field($table, $field); | |
2778 | } | |
2779 | ||
2780 | /// Define key creatorid (foreign) to be added to external_tokens | |
2781 | $table = new xmldb_table('external_tokens'); | |
2782 | $key = new xmldb_key('creatorid', XMLDB_KEY_FOREIGN, array('creatorid'), 'user', array('id')); | |
2783 | ||
2784 | /// Launch add key creatorid | |
2785 | $dbman->add_key($table, $key); | |
2786 | ||
2787 | /// Main savepoint reached | |
2788 | upgrade_main_savepoint($result, 2010010601); | |
2789 | } | |
2790 | ||
c95002a2 | 2791 | if ($result && $oldversion < 2010011200) { |
a25bb902 AD |
2792 | $table = new xmldb_table('grade_categories'); |
2793 | $field = new xmldb_field('hidden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0); | |
2794 | ||
2795 | if (!$dbman->field_exists($table, $field)) { | |
2796 | $dbman->add_field($table, $field); | |
2797 | } | |
2798 | ||
c95002a2 | 2799 | upgrade_main_savepoint($result, 2010011200); |
a25bb902 AD |
2800 | } |
2801 | ||
de260e0f | 2802 | |
7062a798 PL |
2803 | if ($result && $oldversion < 2010012500) { |
2804 | upgrade_fix_incorrect_mnethostids(); | |
2805 | upgrade_main_savepoint($result, 2010012500); | |
2806 | } | |
de260e0f PL |
2807 | |
2808 | if ($result && $oldversion < 2010012600) { | |
2809 | // do stuff to the mnet table | |
2810 | $table = new xmldb_table('mnet_rpc'); | |
2811 | ||
2812 | $field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path'); | |
2813 | $dbman->rename_field($table, $field, 'plugintype'); | |
2814 | ||
2815 | $field = new xmldb_field('parent', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path'); | |
2816 | $dbman->rename_field($table, $field, 'pluginname'); | |
2817 | ||
2818 | $field = new xmldb_field('filename', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'profile'); | |
2819 | if (!$dbman->field_exists($table, $field)) { | |
2820 | $dbman->add_field($table, $field); | |
2821 | } | |
2822 | ||
2823 | $field = new xmldb_field('classname', XMLDB_TYPE_CHAR, '150', null, null, null, null, 'filename'); | |
2824 | if (!$dbman->field_exists($table, $field)) { | |
2825 | $dbman->add_field($table, $field); | |
2826 | } | |
2827 | ||
2828 | $field = new xmldb_field('static', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'classname'); | |
2829 | if (!$dbman->field_exists($table, $field)) { | |
2830 | $dbman->add_field($table, $field); | |
2831 | } | |
2832 | ||
2833 | /// Main savepoint reached | |
2834 | upgrade_main_savepoint($result, 2010012600); | |
2835 | } | |
2836 | ||
8586dbe2 PL |
2837 | if ($result && $oldversion < 2010012900) { |
2838 | ||
2839 | /// Define table mnet_remote_rpc to be created | |
2840 | $table = new xmldb_table('mnet_remote_rpc'); | |
2841 | ||
2842 | /// Adding fields to table mnet_remote_rpc | |
2843 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
2844 | $table->add_field('functionname', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null); | |
2845 | $table->add_field('xmlrpcpath', XMLDB_TYPE_CHAR, '80', null, XMLDB_NOTNULL, null, null); | |
2846 | ||
2847 | /// Adding keys to table mnet_remote_rpc | |
2848 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2849 | ||
2850 | /// Conditionally launch create table for mnet_remote_rpc | |
2851 | if (!$dbman->table_exists($table)) { | |
2852 | $dbman->create_table($table); | |
2853 | } | |
2854 | ||
2855 | ||
2856 | /// Define table mnet_remote_service2rpc to be created | |
2857 | $table = new xmldb_table('mnet_remote_service2rpc'); | |
2858 | ||
2859 | /// Adding fields to table mnet_remote_service2rpc | |
2860 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
2861 | $table->add_field('serviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); | |
2862 | $table->add_field('rpcid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); | |
2863 | ||
2864 | /// Adding keys to table mnet_remote_service2rpc | |
2865 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
2866 | ||
2867 | /// Adding indexes to table mnet_remote_service2rpc | |
2868 | $table->add_index('rpcid_serviceid', XMLDB_INDEX_UNIQUE, array('rpcid', 'serviceid')); | |
2869 | ||
2870 | /// Conditionally launch create table for mnet_remote_service2rpc | |
2871 | if (!$dbman->table_exists($table)) { | |
2872 | $dbman->create_table($table); | |
2873 | } | |
2874 | ||
2875 | ||
2876 | /// Rename field function_name on table mnet_rpc to functionname | |
2877 | $table = new xmldb_table('mnet_rpc'); | |
2878 | $field = new xmldb_field('function_name', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'id'); | |
2879 | ||
2880 | /// Launch rename field function_name | |
2881 | $dbman->rename_field($table, $field, 'functionname'); | |
2882 | ||
2883 | ||
2884 | /// Rename field xmlrpc_path on table mnet_rpc to xmlrpcpath | |
2885 | $table = new xmldb_table('mnet_rpc'); | |
2886 | $field = new xmldb_field('xmlrpc_path', XMLDB_TYPE_CHAR, '80', null, XMLDB_NOTNULL, null, null, 'function_name'); | |
2887 | ||
2888 | /// Launch rename field xmlrpc_path | |
2889 | $dbman->rename_field($table, $field, 'xmlrpcpath'); | |
2890 | ||
2891 | ||
2892 | /// Main savepoint reached | |
2893 | upgrade_main_savepoint($result, 2010012900); | |
2894 | } | |
a6e9dafe PL |
2895 | |
2896 | if ($result && $oldversion < 2010012901) { | |
2897 | ||
2898 | /// Define field plugintype to be added to mnet_remote_rpc | |
2899 | $table = new xmldb_table('mnet_remote_rpc'); | |
2900 | $field = new xmldb_field('plugintype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpcpath'); | |
2901 | ||
2902 | /// Conditionally launch add field plugintype | |
2903 | if (!$dbman->field_exists($table, $field)) { | |
2904 | $dbman->add_field($table, $field); | |
2905 | } | |
2906 | ||
a6e9dafe PL |
2907 | /// Define field pluginname to be added to mnet_remote_rpc |
2908 | $field = new xmldb_field('pluginname', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'plugintype'); | |
2909 | ||
2910 | /// Conditionally launch add field pluginname | |
2911 | if (!$dbman->field_exists($table, $field)) { | |
2912 | $dbman->add_field($table, $field); | |
2913 | } | |
5b7984a5 PL |
2914 | |
2915 | /// Main savepoint reached | |
2916 | upgrade_main_savepoint($result, 2010012901); | |
2917 | } | |
2918 | ||
2919 | if ($result && $oldversion < 2010012902) { | |
2920 | ||
2921 | /// Define field enabled to be added to mnet_remote_rpc | |
2922 | $table = new xmldb_table('mnet_remote_rpc'); | |
2923 | $field = new xmldb_field('enabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, 'pluginname'); | |
2924 | ||
2925 | /// Conditionally launch add field enabled | |
2926 | if (!$dbman->field_exists($table, $field)) { | |
2927 | $dbman->add_field($table, $field); | |
2928 | } | |
2929 | ||
2930 | /// Main savepoint reached | |
2931 | upgrade_main_savepoint($result, 2010012902); | |
a6e9dafe PL |
2932 | } |
2933 | ||
f6852f02 PL |
2934 | /// MDL-17863. Increase the portno column length on mnet_host to handle any port number |
2935 | if ($result && $oldversion < 2010020100) { | |
2936 | /// Changing precision of field portno on table mnet_host to (5) | |
2937 | $table = new xmldb_table('mnet_host'); | |
2938 | $field = new xmldb_field('portno', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'transport'); | |
2939 | ||
2940 | /// Launch change of precision for field portno | |
2941 | $dbman->change_field_precision($table, $field); | |
2942 | ||
2943 | upgrade_main_savepoint($result, 2010020100); | |
2944 | } | |
2945 | ||
d3d393ab RW |
2946 | if ($result && $oldversion < 2010020300) { |
2947 | ||
2948 | /// Define field timecreated to be added to user | |
2949 | $table = new xmldb_table('user'); | |
2950 | $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'trackforums'); | |
2951 | ||
2952 | if (!$dbman->field_exists($table, $field)) { | |
2953 | /// Launch add field timecreated | |
2954 | $dbman->add_field($table, $field); | |
2955 | ||
2956 | $DB->execute("UPDATE {user} SET timecreated = firstaccess"); | |
2957 | ||
2958 | $sql = "UPDATE {user} SET timecreated = " . time() ." where timecreated = 0"; | |
2959 | $DB->execute($sql); | |
2960 | } | |
2961 | upgrade_main_savepoint($result, 2010020300); | |
2962 | } | |
073d3804 EL |
2963 | |
2964 | // MDL-21407. Trim leading spaces from default tex latexpreamble causing problems under some confs | |
2965 | if ($result && $oldversion < 2010020301) { | |
2966 | if ($preamble = $CFG->filter_tex_latexpreamble) { | |
2967 | $preamble = preg_replace('/^ +/m', '', $preamble); | |
2968 | set_config('filter_tex_latexpreamble', $preamble); | |
2969 | } | |
2970 | upgrade_main_savepoint($result, 2010020301); | |
2971 | } | |
2972 | ||
9a9012dc PS |
2973 | if ($result && $oldversion < 2010021400) { |
2974 | /// Changes to modinfo mean we need to rebuild course cache | |
2975 | require_once($CFG->dirroot . '/course/lib.php'); | |
2976 | rebuild_course_cache(0, true); | |
2977 | upgrade_main_savepoint($result, 2010021400); | |
2978 | } | |
2979 | ||
c9606565 PL |
2980 | if ($result && $oldversion < 2010021800) { |
2981 | $DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle')); | |
2982 | upgrade_main_savepoint($result, 2010021800); | |
2983 | } | |
2984 | ||
cd1bca89 PS |
2985 | if ($result && $oldversion < 2010031900) { |
2986 | // regeneration of sessions is always enabled, no need for this setting any more | |
2987 | unset_config('regenloginsession'); | |
2988 | upgrade_main_savepoint($result, 2010031900); | |
2989 | } | |
90723839 | 2990 | |
c4c3b907 | 2991 | |
90723839 SH |
2992 | if ($result && $oldversion < 2010032400) { |
2993 | // Upgrade all of those using the standardold theme to the use the standard | |
2994 | // theme instead | |
2995 | if ($CFG->theme == 'standardold') { | |
2996 | // The config setting that affects the whole site | |
2997 | set_config('theme', 'standard'); | |
2998 | } | |
2999 | // Course Categories | |
3000 | $DB->execute('UPDATE {course_categories} SET theme=? WHERE theme=?', array('standard', 'standardold')); | |
3001 | // Course | |
3002 | $DB->execute('UPDATE {course} SET theme=? WHERE theme=?', array('standard', 'standardold')); | |
3003 | // User | |
3004 | $DB->execute('UPDATE {user} SET theme=? WHERE theme=?', array('standard', 'standardold')); | |
3005 | upgrade_main_savepoint($result, 2010032400); | |
3006 | } | |
1dce6261 | 3007 | |
f0b9ee18 | 3008 | if ($result && $oldversion < 2010033101.01) { |
1dce6261 DC |
3009 | |
3010 | /// Define field source to be added to files | |
3011 | $table = new xmldb_table('files'); | |
3012 | ||
f0b9ee18 | 3013 | $field = new xmldb_field('source', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'status'); |
1dce6261 DC |
3014 | |
3015 | /// Conditionally launch add field source | |
3016 | if (!$dbman->field_exists($table, $field)) { | |
3017 | $dbman->add_field($table, $field); | |
3018 | } | |
3019 | ||
3020 | $field = new xmldb_field('author', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'source'); | |
3021 | ||
3022 | /// Conditionally launch add field author | |
3023 | if (!$dbman->field_exists($table, $field)) { | |
3024 | $dbman->add_field($table, $field); | |
3025 | } | |
3026 | ||
3027 | $field = new xmldb_field('license', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'author'); | |
3028 | ||
3029 | /// Conditionally launch add field license | |
3030 | if (!$dbman->field_exists($table, $field)) { | |
3031 | $dbman->add_field($table, $field); | |
3032 | } | |
3033 | ||
f0b9ee18 PS |
3034 | upgrade_main_savepoint($result, 2010033101.01); |
3035 | } | |
3036 | ||
3037 | if ($result && $oldversion < 2010033101.02) { | |
98da6021 | 3038 | |
1dce6261 DC |
3039 | /// Define table license to be created |
3040 | $table = new xmldb_table('license'); | |
3041 | ||
3042 | /// Adding fields to table license | |
3043 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
3044 | $table->add_field('shortname', XMLDB_TYPE_CHAR, '255', null, null, null, null); | |
3045 | $table->add_field('fullname', XMLDB_TYPE_TEXT, 'small', null, null, null, null); | |
3046 | $table->add_field('source', XMLDB_TYPE_CHAR, '255', null, null, null, null); | |
3047 | $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); | |
3048 | $table->add_field('version', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); | |
3049 | ||
3050 | /// Adding keys to table license | |
3051 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
3052 | ||
3053 | /// Conditionally launch create table for license | |
3054 | if (!$dbman->table_exists($table)) { | |
3055 | $dbman->create_table($table); | |
3056 | } | |
d1d4813f DC |
3057 | $active_licenses = array(); |
3058 | ||
3059 | $license = new stdclass; | |
3060 | ||
3061 | // add unknown license | |
3062 | $license->shortname = 'unknown'; | |
3063 | $license->fullname = 'Unknown license'; | |
3064 | $license->source = ''; | |
3065 | $license->enabled = 1; | |
3066 | $license->version = '2010033100'; | |
3067 | $active_licenses[] = $license->shortname; | |
3068 | if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) { | |
3069 | if ($record->version < $license->version) { | |
3070 | // update license record | |
3071 | $license->enabled = $record->enabled; | |
3072 | $license->id = $record->id; | |
3073 | $DB->update_record('license', $license); | |
3074 | } | |
3075 | } else { | |
3076 | $DB->insert_record('license', $license); | |
3077 | } | |
3078 | ||
3079 | // add all rights reserved license | |
3080 | $license->shortname = 'allrightsreserved'; | |
3081 | $license->fullname = 'All rights reserved'; | |
3082 | $license->source = 'http://en.wikipedia.org/wiki/All_rights_reserved'; | |
3083 | $license->enabled = 1; | |
3084 | $license->version = '2010033100'; | |
3085 | $active_licenses[] = $license->shortname; | |
3086 | if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) { | |
3087 | if ($record->version < $license->version) { | |
3088 | // update license record | |
3089 | $license->id = $record->id; | |
3090 | $license->enabled = $record->enabled; | |
3091 | $DB->update_record('license', $license); | |
3092 | } | |
3093 | } else { | |
3094 | $DB->insert_record('license', $license); | |
3095 | } | |
3096 | ||
3097 | // add public domain license | |
3098 | $license->shortname = 'public'; | |
3099 | $license->fullname = 'Public Domain'; | |
3100 | $license->source = 'http://creativecommons.org/licenses/publicdomain/'; | |
3101 | $license->enabled = 1; | |
3102 | $license->version = '2010033100'; | |
3103 | $active_licenses[] = $license->shortname; | |
3104 | if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) { | |
3105 | if ($record->version < $license->version) { | |
3106 | // update license record | |
3107 | $license->enabled = $record->enabled; | |
3108 | $license->id = $record->id; | |
3109 | $DB->update_record('license', $license); | |
3110 | } | |
3111 | } else { | |
3112 | $DB->insert_record('license', $license); | |
3113 | } | |
3114 | ||
3115 | // add creative commons license | |
3116 | $license->shortname = 'cc'; | |
3117 | $license->fullname = 'Creative Commons'; | |
3118 | $license->source = 'http://creativecommons.org/licenses/by/3.0/'; | |
3119 | $license->enabled = 1; | |
3120 | $license->version = '2010033100'; | |
3121 | $active_licenses[] = $license->shortname; | |
3122 | if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) { | |
3123 | if ($record->version < $license->version) { | |
3124 | // update license record | |
3125 | $license->enabled = $record->enabled; | |
3126 | $license->id = $record->id; | |
3127 | $DB->update_record('license', $license); | |
3128 | } | |
3129 | } else { | |
3130 | $DB->insert_record('license', $license); | |
3131 | } | |
3132 | ||
3133 | // add creative commons no derivs license | |
3134 | $license->shortname = 'cc-nd'; | |
3135 | $license->fullname = 'Creative Commons - NoDerivs'; | |
3136 | $license->source = 'http://creativecommons.org/licenses/by-nd/3.0/'; | |
3137 | $license->enabled = 1; | |
3138 | $license->version = '2010033100'; | |
3139 | $active_licenses[] = $license->shortname; | |
3140 | if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) { | |
3141 | if ($record->version < $license->version) { | |
3142 | // update license record | |
3143 | $license->enabled = $record->enabled; | |
3144 | $license->id = $record->id; | |
3145 | $DB->update_record('license', $license); | |
3146 | } | |
3147 | } else { | |
3148 | $DB->insert_record('license', $license); | |
3149 | } | |
3150 | ||
3151 | // add creative commons no commercial no derivs license | |
3152 | $license->shortname = 'cc-nc-nd'; | |
3153 | $license->fullname = 'Creative Commons - No Commercial NoDerivs'; | |
3154 | $license->source = 'http://creativecommons.org/licenses/by-nc-nd/3.0/'; | |
3155 | $license->enabled = 1; | |
3156 | $license->version = '2010033100'; | |
3157 | $active_licenses[] = $license->shortname; | |
3158 | if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) { | |
3159 | if ($record->version < $license->version) { | |
3160 | // update license record | |
3161 | $license->enabled = $record->enabled; | |
3162 | $license->id = $record->id; | |
3163 | $DB->update_record('license', $license); | |
3164 | } | |
3165 | } else { | |
3166 | $DB->insert_record('license', $license); | |
3167 | } | |
3168 | ||
3169 | // add creative commons no commercial | |
3170 | $license->shortname = 'cc-nc-nd'; | |
3171 | $license->shortname = 'cc-nc'; | |
3172 | $license->fullname = 'Creative Commons - No Commercial'; | |
3173 | $license->source = 'http://creativecommons.org/licenses/by-nd/3.0/'; | |
3174 | $license->enabled = 1; | |
3175 | $license->version = '2010033100'; | |
3176 | $active_licenses[] = $license->shortname; | |
3177 | if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) { | |
3178 | if ($record->version < $license->version) { | |
3179 | // update license record | |
3180 | $license->enabled = $record->enabled; | |
3181 | $license->id = $record->id; | |
3182 | $DB->update_record('license', $license); | |
3183 | } | |
3184 | } else { | |
3185 | $DB->insert_record('license', $license); | |
3186 | } | |
3187 | ||
3188 | // add creative commons no commercial sharealike | |
3189 | $license->shortname = 'cc-nc-sa'; | |
3190 | $license->fullname = 'Creative Commons - No Commercial ShareAlike'; | |
3191 | $license->source = 'http://creativecommons.org/licenses/by-nc-sa/3.0/'; | |
3192 | $license->enabled = 1; | |
3193 | $license->version = '2010033100'; | |
3194 | $active_licenses[] = $license->shortname; | |
3195 | if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) { | |
3196 | if ($record->version < $license->version) { | |
3197 | // update license record | |
3198 | $license->enabled = $record->enabled; | |
3199 | $license->id = $record->id; | |
3200 | $DB->update_record('license', $license); | |
3201 | } | |
3202 | } else { | |
3203 | $DB->insert_record('license', $license); | |
3204 | } | |
3205 | ||
3206 | // add creative commons sharealike | |
3207 | $license->shortname = 'cc-sa'; | |
3208 | $license->fullname = 'Creative Commons - ShareAlike'; | |
3209 | $license->source = 'http://creativecommons.org/licenses/by-sa/3.0/'; | |
3210 | $license->enabled = 1; | |
3211 | $license->version = '2010033100'; | |
3212 | $active_licenses[] = $license->shortname; | |
3213 | if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) { | |
3214 | if ($record->version < $license->version) { | |
3215 | // update license record | |
3216 | $license->enabled = $record->enabled; | |
3217 | $license->id = $record->id; | |
3218 | $DB->update_record('license', $license); | |
3219 | } | |
3220 | } else { | |
3221 | $DB->insert_record('license', $license); | |
3222 | } | |
3223 | ||
3224 | set_config('licenses', implode(',', $active_licenses)); | |
1dce6261 DC |
3225 | /// set site default license |
3226 | set_config('sitedefaultlicense', 'allrightsreserved'); | |
3227 | ||
3228 | /// Main savepoint reached | |
f0b9ee18 | 3229 | upgrade_main_savepoint($result, 2010033101.02); |
1dce6261 | 3230 | } |
4f0c2d00 PS |
3231 | |
3232 | if ($result && $oldversion < 2010033102.00) { | |
3233 | // rename course view capability to participate | |
3234 | $params = array('view'=>'moodle/course:view', 'participate'=>'moodle/course:participate'); | |
3235 | $sql = "UPDATE {role_capabilities} SET capability = :participate WHERE capability = :view"; | |
3236 | $DB->execute($sql, $params); | |
3237 | $sql = "UPDATE {capabilities} SET name = :participate WHERE name = :view"; | |
3238 | $DB->execute($sql, $params); | |
3239 | // note: the view capability is readded again at the end of upgrade, but with different meaning | |
3240 | upgrade_main_savepoint($result, 2010033102.00); | |
3241 | } | |
3242 | ||
3243 | if ($result && $oldversion < 2010033102.01) { | |
3244 | // Define field archetype to be added to role table | |
3245 | $table = new xmldb_table('role'); | |
3246 | $field = new xmldb_field('archetype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, 'sortorder'); | |
3247 | $dbman->add_field($table, $field); | |
3248 | upgrade_main_savepoint($result, 2010033102.01); | |
3249 | } | |
3250 | ||
3251 | if ($result && $oldversion < 2010033102.02) { | |
3252 | // Set archetype for existing roles and change admin role to manager role | |
3253 | $sql = "SELECT r.*, rc.capability | |
3254 | FROM {role} r | |
3255 | JOIN {role_capabilities} rc ON rc.roleid = r.id | |
3256 | WHERE rc.contextid = :syscontextid AND rc.capability LIKE :legacycaps | |
3257 | ORDER BY r.id"; | |
3258 | $params = array('syscontextid'=>SYSCONTEXTID, 'legacycaps'=>'moodle/legacy:%'); | |
3259 | $substart = strlen('moodle/legacy:'); | |
3260 | $roles = $DB->get_recordset_sql($sql, $params); // in theory could be multiple legacy flags in one role | |
3261 | foreach ($roles as $role) { | |
3262 | $role->archetype = substr($role->capability, $substart); | |
3263 | unset($role->capability); | |
3264 | if ($role->archetype === 'admin') { | |
3265 | $role->archetype = 'manager'; | |
3266 | if ($role->shortname === 'admin') { | |
3267 | $role->shortname = 'manager'; | |
3268 | $role->name = get_string('manager', 'role'); | |
3269 | $role->description = get_string('managerdescription', 'role'); | |
3270 | } | |
3271 | } | |
3272 | $DB->update_record('role', $role); | |
3273 | } | |
3274 | $roles->close(); | |
3275 | ||
3276 | upgrade_main_savepoint($result, 2010033102.02); | |
3277 | } | |
3278 | ||
3279 | if ($result && $oldversion < 2010033102.03) { | |
3280 | // Now pick site admins (===have manager role assigned at the system context) | |
3281 | // and store them in the new $CFG->siteadmins setting as comma separated list | |
3282 | $sql = "SELECT ra.id, ra.userid | |
3283 | FROM {role_assignments} ra | |
3284 | JOIN {role} r ON r.id = ra.roleid | |
3285 | JOIN {user} u ON u.id = ra.userid | |
3286 | WHERE ra.contextid = :syscontext AND r.archetype = 'manager' AND u.deleted = 0 | |
3287 | ORDER BY ra.id"; | |
3288 | $ras = $DB->get_records_sql($sql, array('syscontext'=>SYSCONTEXTID)); | |
3289 | $admins = array(); | |
3290 | foreach ($ras as $ra) { | |
3291 | $admins[$ra->userid] = $ra->userid; | |
3292 | set_config('siteadmins', implode(',', $admins)); // better to save it repeatedly, we do need at least one admin | |
3293 | $DB->delete_records('role_assignments', array('id'=>$ra->id)); | |
3294 | } | |
3295 | ||
3296 | upgrade_main_savepoint($result, 2010033102.03); | |
3297 | } | |
3298 | ||
3299 | if ($result && $oldversion < 2010033102.04) { | |
3300 | // clean up the manager roles | |
3301 | $managers = $DB->get_records('role', array('archetype'=>'manager')); | |
3302 | foreach ($managers as $manager) { | |
3303 | // now sanitize the capabilities and overrides | |
3304 | $DB->delete_records('role_capabilities', array('capability'=>'moodle/site:config', 'roleid'=>$manager->id)); // only site admins may configure servers | |
3305 | // note: doanything and legacy caps are deleted automatically, they get moodle/course:view later at the end of the upgrade | |
3306 | ||
3307 | // set usable contexts | |
3308 | $DB->delete_records('role_context_levels', array('roleid'=>$manager->id)); | |
3309 | $assignlevels = array(CONTEXT_SYSTEM, CONTEXT_COURSECAT, CONTEXT_COURSE); | |
3310 | foreach ($assignlevels as $assignlevel) { | |
3311 | $record = (object)array('roleid'=>$manager->id, 'contextlevel'=>$assignlevel); | |
3312 | $DB->insert_record('role_context_levels', $record); | |
3313 | } | |
3314 | ||
3315 | // remove manager role assignments bellow the course context level - admin role was never intended for activities and blocks, | |
3316 | // the problem is that those assignments would not be visible after upgrade and old style admins in activities make no sense anyway | |
3317 | $DB->delete_records_select('role_assignments', "roleid = :manager AND contextid IN (SELECT id FROM {context} WHERE contextlevel > 50)", array('manager'=>$manager->id)); | |
3318 | ||
3319 | // allow them to assign all roles except default user, guest and frontpage - users get these roles automatically on the fly when needed | |
3320 | $DB->delete_records('role_allow_assign', array('roleid'=>$manager->id)); | |
3321 | $roles = $DB->get_records_sql("SELECT * FROM {role} WHERE archetype <> 'user' AND archetype <> 'guest' AND archetype <> 'frontpage'"); | |
3322 | foreach ($roles as $role) { | |
3323 | $record = (object)array('roleid'=>$manager->id, 'allowassign'=>$role->id); | |
3324 | $DB->insert_record('role_allow_assign', $record); | |
3325 | } | |
3326 | ||
3327 | // allow them to override all roles | |
3328 | $DB->delete_records('role_allow_override', array('roleid'=>$manager->id)); | |
3329 | $roles = $DB->get_records_sql("SELECT * FROM {role}"); | |
3330 | foreach ($roles as $role) { | |
3331 | $record = (object)array('roleid'=>$manager->id, 'allowoverride'=>$role->id); | |
3332 | $DB->insert_record('role_allow_override', $record); | |
3333 | } | |
3334 | ||
3335 | // allow them to switch to all following roles | |
3336 | $DB->delete_records('role_allow_switch', array('roleid'=>$manager->id)); | |
3337 | $roles = $DB->get_records_sql("SELECT * FROM {role} WHERE archetype IN ('student', 'teacher', 'editingteacher')"); | |
3338 | foreach ($roles as $role) { | |
3339 | $record = (object)array('roleid'=>$manager->id, 'allowswitch'=>$role->id); | |
3340 | $DB->insert_record('role_allow_switch', $record); | |
3341 | } | |
3342 | } | |
3343 | ||
3344 | upgrade_main_savepoint($result, 2010033102.04); | |
3345 | } | |
3346 | ||
3347 | if ($result && $oldversion < 2010033102.05) { | |
3348 | // remove course:view from all roles that are not used for enrolment, it does NOT belong there because it really means user is enrolled! | |
3349 | $noenrolroles = $DB->get_records_select('role', "archetype IN ('guest', 'user', 'manager', 'coursecreator', 'frontpage')"); | |
3350 | foreach ($noenrolroles as $role) { | |
3351 | $DB->delete_records('role_capabilities', array('roleid'=>$role->id, 'capability'=>'moodle/course:participate')); | |
3352 | } | |
3353 | upgrade_main_savepoint($result, 2010033102.05); | |
3354 | } | |
3355 | ||
3356 | if ($result && $oldversion < 2010033102.06) { | |
3357 | // make sure there is nothing weird in default user role | |
3358 | if (!empty($CFG->defaultuserroleid)) { | |
3359 | if ($role = $DB->get_record('role', array('id'=>$CFG->defaultuserroleid))) { | |
3360 | if ($role->archetype !== '' and $role->archetype !== 'user') { | |
3361 | upgrade_log(UPGRADE_LOG_NOTICE, null, 'Default authenticated user role (defaultuserroleid) value is invalid, setting cleared.'); | |
3362 | unset_config('defaultuserroleid'); | |
3363 | } | |
3364 | } else { | |
3365 | unset_config('defaultuserroleid'); | |
3366 | } | |
3367 | } | |
3368 | upgrade_main_savepoint($result, 2010033102.06); | |
3369 | } | |
3370 | ||
3371 | if ($result && $oldversion < 2010033102.07) { | |
3372 | if (!empty($CFG->displayloginfailures) and $CFG->displayloginfailures === 'teacher') { | |
3373 | upgrade_log(UPGRADE_LOG_NOTICE, null, 'Displaying of login failuters to teachers is not supported any more.'); | |
3374 | unset_config('displayloginfailures'); | |
3375 | } | |
3376 | upgrade_main_savepoint($result, 2010033102.07); | |
3377 | } | |
3378 | ||
3379 | if ($result && $oldversion < 2010033102.08) { | |
3380 | // make sure there are no problems in default guest role settings | |
3381 | if (!empty($CFG->guestroleid)) { | |
3382 | if ($role = $DB->get_record('role', array('id'=>$CFG->guestroleid))) { | |
3383 | if ($role->archetype !== '' and $role->archetype !== 'guest') { | |
3384 | upgrade_log(UPGRADE_LOG_NOTICE, null, 'Default guest role (guestroleid) value is invalid, setting cleared.'); | |
3385 | unset_config('guestroleid'); | |
3386 | } | |
3387 | } else { | |
3388 | upgrade_log(UPGRADE_LOG_NOTICE, null, 'Role specified in Default guest role (guestroleid) doeas not exist, setting cleared.'); | |
3389 | unset_config('guestroleid'); | |
3390 | } | |
3391 | } | |
3392 | // remove all roles of the guest account - the only way to change it is to override the guest role, sorry | |
3393 | // the guest account gets all the role assignemnts on the fly whcih works fine in has_capability(), | |
3394 | $DB->delete_records_select('role_assignments', "userid IN (SELECT id FROM {user} WHERE username = 'guest')"); | |
3395 | ||
3396 | upgrade_main_savepoint($result, 2010033102.08); | |
3397 | } | |
3398 | ||
3399 | if ($result && $oldversion < 2010033102.09) { | |
3400 | // For MDL-17501. Ensure that any role that has moodle/course:update also has moodle/course:visibility. | |
3401 | // Get the roles with 'moodle/course:update'. | |
3402 | $systemcontext = get_context_instance(CONTEXT_SYSTEM); | |
3403 | $roles = get_roles_with_capability('moodle/course:update', CAP_ALLOW, $systemcontext); | |
3404 | ||
3405 | // Give those roles 'moodle/course:visibility'. | |
3406 | foreach ($roles as $role) { | |
3407 | assign_capability('moodle/course:visibility', CAP_ALLOW, $role->id, $systemcontext->id); | |
3408 | } | |
3409 | ||
3410 | // Force all sessions to refresh access data. | |
3411 | mark_context_dirty($systemcontext->path); | |
3412 | ||
3413 | // Main savepoint reached | |
3414 | upgrade_main_savepoint($result, 2010033102.09); | |
3415 | } | |
3416 | ||
98da6021 PS |
3417 | if ($result && $oldversion < 2010040700) { |
3418 | // migrate old groupings --> groupmembersonly setting | |
3419 | if (isset($CFG->enablegroupings)) { | |
3420 | set_config('enablegroupmembersonly', $CFG->enablegroupings); | |
3421 | unset_config('enablegroupings'); | |
3422 | } | |
3423 | ||
3424 | // Main savepoint reached | |
3425 | upgrade_main_savepoint($result, 2010040700); | |
3426 | } | |
3427 | ||
3a915b06 PS |
3428 | if ($result && $oldversion < 2010040900) { |
3429 | ||
3430 | // Changing the default of field lang on table user to good old "en" | |
3431 | $table = new xmldb_table('user'); | |
3432 | $field = new xmldb_field('lang', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, 'en', 'country'); | |
3433 | ||
3434 | // Launch change of default for field lang | |
3435 | $dbman->change_field_default($table, $field); | |
3436 | ||
3437 | // update main site lang | |
3438 | if (strpos($CFG->lang, '_utf8') !== false) { | |
3439 | $lang = str_replace('_utf8', '', $CFG->lang); | |
3440 | set_config('lang', $lang); | |
3441 | } | |
3442 | ||
2357ab49 PS |
3443 | // tweak langlist |
3444 | if (!empty($CFG->langlist)) { | |
3445 | $langs = explode(',', $CFG->langlist); | |
3446 | foreach ($langs as $key=>$lang) { | |
3447 | $lang = str_replace('_utf8', '', $lang); | |
3448 | $langs[$key] = $lang; | |
3449 | } | |
3450 | set_config('langlist', implode(',', $langs)); | |
3451 | } | |
3452 | ||
3a915b06 PS |
3453 | // Main savepoint reached |
3454 | upgrade_main_savepoint($result, 2010040900); | |
3455 | } | |
3456 | ||
3457 | if ($result && $oldversion < 2010040901) { | |
3458 | ||
3459 | // Remove "_utf8" suffix from all langs in user table | |
3460 | $langs = $DB->get_records_sql("SELECT DISTINCT lang FROM {user} WHERE lang LIKE ?", array('%_utf8')); | |
3461 | ||
3462 | foreach ($langs as $lang=>$unused) { | |
3463 | $newlang = str_replace('_utf8', '', $lang); | |
3464 | $sql = "UPDATE {user} SET lang = :newlang WHERE lang = :lang"; | |
3465 | $DB->execute($sql, array('newlang'=>$newlang, 'lang'=>$lang)); | |
3466 | } | |
3467 | ||
3468 | // Main savepoint reached | |
3469 | upgrade_main_savepoint($result, 2010040901); | |
3470 | } | |
3471 | ||
3406acde SH |
3472 | if ($result && $oldversion < 2010041301) { |
3473 | $sql = "UPDATE {block} SET name=? WHERE name=?"; | |
3474 | $DB->execute($sql, array('navigation', 'global_navigation_tree')); | |
3475 | $DB->execute($sql, array('settings', 'settings_navigation_tree')); | |
3476 | ||
3477 | $sql = "UPDATE {block_instances} SET blockname=? WHERE blockname=?"; | |
3478 | $DB->execute($sql, array('navigation', 'global_navigation_tree')); | |
3479 | $DB->execute($sql, array('settings', 'settings_navigation_tree')); | |
3480 | upgrade_main_savepoint($result, 2010041301); | |
3481 | } | |
3482 | ||
ee4d3dee EL |
3483 | if ($result && $oldversion < 2010042100) { |
3484 | ||
3485 | /// Define table backup_controllers to be created | |
3486 | $table = new xmldb_table('backup_controllers'); | |
3487 | ||
3488 | /// Adding fields to table backup_controllers | |
3489 | $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); | |
3490 | $table->add_field('backupid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); | |
3491 | $table->add_field('type', XMLDB_TYPE_CHAR, '6', null, XMLDB_NOTNULL, null, null); | |
3492 | $table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
3493 | $table->add_field('format', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null); | |
3494 | $table->add_field('interactive', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
3495 | $table->add_field('purpose', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
3496 | $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
3497 | $table->add_field('status', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
3498 | $table->add_field('execution', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
3499 | $table->add_field('executiontime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
3500 | $table->add_field('checksum', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null); | |
3501 | $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
3502 | $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null); | |
3503 | $table->add_field('controller', XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null); | |
3504 | ||
3505 | /// Adding keys to table backup_controllers | |
3506 | $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); | |
3507 | $table->add_key('backupid_uk', XMLDB_KEY_UNIQUE, array('backupid')); | |
3508 | $table->add_key('userid_fk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); | |
3509 | ||
3510 | /// Adding indexes to table backup_controllers | |
3511 | $table->add_index('typeitem_ix', XMLDB_INDEX_NOTUNIQUE, array('type', 'itemid')); | |
3512 | ||
3513 | /// Conditionally launch create table for backup_controllers | |
3514 | if (!$dbman->table_exists($table)) { | |
3515 | $dbman->create_table($table); | |
3516 | } | |
3517 | ||