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