3 // This file keeps track of upgrades to Moodle.
5 // Sometimes, changes between versions involve
6 // alterations to database structures and other
7 // major things that may break installations.
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.
13 // If there's something it cannot do itself, it
14 // will tell you what you need to do.
16 // The commands in here will all be database-neutral,
17 // using the functions defined in lib/ddllib.php
20 function xmldb_main_upgrade($oldversion=0) {
22 global $CFG, $THEME, $USER, $db;
26 if ($result && $oldversion < 2006100401) {
27 /// Only for those tracking Moodle 1.7 dev, others will have these dropped in moodle_install_roles()
28 if (!empty($CFG->rolesactive
)) {
29 drop_table(new XMLDBTable('user_students'));
30 drop_table(new XMLDBTable('user_teachers'));
31 drop_table(new XMLDBTable('user_coursecreators'));
32 drop_table(new XMLDBTable('user_admins'));
35 upgrade_main_savepoint($result, 2006100401);
38 if ($result && $oldversion < 2006100601) { /// Disable the exercise module because it's unmaintained
39 if ($module = get_record('modules', 'name', 'exercise')) {
40 if ($module->visible
) {
41 // Hide/disable the module entry
42 set_field('modules', 'visible', '0', 'id', $module->id
);
43 // Save existing visible state for all activities
44 set_field('course_modules', 'visibleold', '1', 'visible' ,'1', 'module', $module->id
);
45 set_field('course_modules', 'visibleold', '0', 'visible' ,'0', 'module', $module->id
);
46 // Hide all activities
47 set_field('course_modules', 'visible', '0', 'module', $module->id
);
49 //require_once($CFG->dirroot.'/course/lib.php');
50 //rebuild_course_cache(); // Rebuld cache for all modules because they might have changed
54 upgrade_main_savepoint($result, 2006100601);
57 if ($result && $oldversion < 2006101001) { /// Disable the LAMS module by default (if it is installed)
58 if (count_records('modules', 'name', 'lams') && !count_records('lams')) {
59 set_field('modules', 'visible', 0, 'name', 'lams'); // Disable it by default
62 upgrade_main_savepoint($result, 2006101001);
65 if ($result && $oldversion < 2006102600) {
67 /// Define fields to be added to user_info_field
68 $table = new XMLDBTable('user_info_field');
69 $field = new XMLDBField('description');
70 $field->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, null, null, null, null, null, 'categoryid');
71 $field1 = new XMLDBField('param1');
72 $field1->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, null, null, null, null, null, 'defaultdata');
73 $field2 = new XMLDBField('param2');
74 $field2->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, null, null, null, null, null, 'param1');
75 $field3 = new XMLDBField('param3');
76 $field3->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, null, null, null, null, null, 'param2');
77 $field4 = new XMLDBField('param4');
78 $field4->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, null, null, null, null, null, 'param3');
79 $field5 = new XMLDBField('param5');
80 $field5->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, null, null, null, null, null, 'param4');
83 $result = $result && add_field($table, $field);
84 $result = $result && add_field($table, $field1);
85 $result = $result && add_field($table, $field2);
86 $result = $result && add_field($table, $field3);
87 $result = $result && add_field($table, $field4);
88 $result = $result && add_field($table, $field5);
90 upgrade_main_savepoint($result, 2006102600);
93 if ($result && $oldversion < 2006112000) {
95 /// Define field attachment to be added to post
96 $table = new XMLDBTable('post');
97 $field = new XMLDBField('attachment');
98 $field->setAttributes(XMLDB_TYPE_CHAR
, '100', null, null, null, null, null, null, 'format');
100 /// Launch add field attachment
101 $result = $result && add_field($table, $field);
103 upgrade_main_savepoint($result, 2006112000);
106 if ($result && $oldversion < 2006112200) {
108 /// Define field imagealt to be added to user
109 $table = new XMLDBTable('user');
110 $field = new XMLDBField('imagealt');
111 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null, 'trustbitmask');
113 /// Launch add field imagealt
114 $result = $result && add_field($table, $field);
116 $table = new XMLDBTable('user');
117 $field = new XMLDBField('screenreader');
118 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', null, XMLDB_NOTNULL
, null, null, null, '0', 'imagealt');
120 /// Launch add field screenreader
121 $result = $result && add_field($table, $field);
123 upgrade_main_savepoint($result, 2006112200);
126 if ($result && $oldversion < 2006120300) { /// Delete guest course section settings
127 // following code can be executed repeatedly, such as when upgrading from 1.7.x - it is ok
128 if ($guest = get_record('user', 'username', 'guest')) {
129 execute_sql("DELETE FROM {$CFG->prefix}course_display where userid=$guest->id", true);
132 upgrade_main_savepoint($result, 2006120300);
135 if ($result && $oldversion < 2006120400) { /// Remove secureforms config setting
136 execute_sql("DELETE FROM {$CFG->prefix}config where name='secureforms'", true);
138 upgrade_main_savepoint($result, 2006120400);
141 if (!empty($CFG->rolesactive
) && $oldversion < 2006120700) { // add moodle/user:viewdetails to all roles!
142 // note: use of assign_capability() is discouraged in upgrade script!
143 if ($roles = get_records('role')) {
144 $context = get_context_instance(CONTEXT_SYSTEM
);
145 foreach ($roles as $roleid=>$role) {
146 assign_capability('moodle/user:viewdetails', CAP_ALLOW
, $roleid, $context->id
);
150 upgrade_main_savepoint($result, 2006120700);
153 // Move the auth plugin settings into the config_plugin table
154 if ($result && $oldversion < 2007010300) {
155 if ($CFG->auth
== 'email') {
156 set_config('registerauth', 'email');
158 set_config('registerauth', '');
160 $authplugins = get_list_of_plugins('auth');
161 foreach ($CFG as $k => $v) {
162 if (strpos($k, 'ldap_') === 0) {
163 //upgrade nonstandard ldap settings
164 $setting = substr($k, 5);
165 if (set_config($setting, $v, "auth/ldap")) {
166 delete_records('config', 'name', $k);
171 if (strpos($k, 'auth_') !== 0) {
174 $authsetting = substr($k, 5);
175 foreach ($authplugins as $auth) {
176 if (strpos($authsetting, $auth) !== 0) {
179 $setting = substr($authsetting, strlen($auth));
180 if (set_config($setting, $v, "auth/$auth")) {
181 delete_records('config', 'name', $k);
184 break; // don't check the rest of the auth plugin names
188 upgrade_main_savepoint($result, 2007010300);
191 if ($result && $oldversion < 2007010301) {
195 $table = new XMLDBTable('mnet_host');
196 $table->comment
= 'Information about the local and remote hosts for RPC';
198 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
199 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
200 $f->comment
= 'Unique Host ID';
201 $f = $table->addFieldInfo('deleted', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
202 XMLDB_NOTNULL
, null, null, null, 0);
203 $f = $table->addFieldInfo('wwwroot', XMLDB_TYPE_CHAR
, '255', null,
204 XMLDB_NOTNULL
, null, null, null, null);
205 $f = $table->addFieldInfo('ip_address', XMLDB_TYPE_CHAR
, '39', null,
206 XMLDB_NOTNULL
, null, null, null, null);
207 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '80', null,
208 XMLDB_NOTNULL
, null, null, null, null);
209 $f = $table->addFieldInfo('public_key', XMLDB_TYPE_TEXT
, 'medium', null,
210 XMLDB_NOTNULL
, null, null, null, null);
211 $f = $table->addFieldInfo('public_key_expires', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
212 XMLDB_NOTNULL
, null, null, null, 0);
213 $f = $table->addFieldInfo('transport', XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
,
214 XMLDB_NOTNULL
, null, null, null, 0);
215 $f = $table->addFieldInfo('portno', XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
,
216 XMLDB_NOTNULL
, null, null, null, 0);
217 $f = $table->addFieldInfo('last_connect_time', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
218 XMLDB_NOTNULL
, null, null, null, 0);
219 $f = $table->addFieldInfo('last_log_id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
220 XMLDB_NOTNULL
, null, null, null, 0);
222 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
224 $result = $result && create_table($table);
226 $table = new XMLDBTable('mnet_host2service');
227 $table->comment
= 'Information about the services for a given host';
229 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
230 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
231 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
232 XMLDB_NOTNULL
, NULL, null, null, 0);
233 $f = $table->addFieldInfo('serviceid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
234 XMLDB_NOTNULL
, NULL, null, null, 0);
235 $f = $table->addFieldInfo('publish', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
236 XMLDB_NOTNULL
, NULL, null, null, 0);
237 $f = $table->addFieldInfo('subscribe', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
238 XMLDB_NOTNULL
, NULL, null, null, 0);
240 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
241 $table->addIndexInfo('hostid_serviceid', XMLDB_INDEX_UNIQUE
, array('hostid', 'serviceid'));
243 $result = $result && create_table($table);
245 $table = new XMLDBTable('mnet_log');
246 $table->comment
= 'Store session data from users migrating to other sites';
248 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
249 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
250 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
251 XMLDB_NOTNULL
, NULL, null, null, 0);
252 $f = $table->addFieldInfo('remoteid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
253 XMLDB_NOTNULL
, NULL, null, null, 0);
254 $f = $table->addFieldInfo('time', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
255 XMLDB_NOTNULL
, NULL, null, null, 0);
256 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
257 XMLDB_NOTNULL
, NULL, null, null, 0);
258 $f = $table->addFieldInfo('ip', XMLDB_TYPE_CHAR
, '15', null,
259 XMLDB_NOTNULL
, NULL, null, null, null);
260 $f = $table->addFieldInfo('course', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
261 XMLDB_NOTNULL
, NULL, null, null, 0);
262 $f = $table->addFieldInfo('coursename', XMLDB_TYPE_CHAR
, '40', null,
263 XMLDB_NOTNULL
, NULL, null, null, null);
264 $f = $table->addFieldInfo('module', XMLDB_TYPE_CHAR
, '20', null,
265 XMLDB_NOTNULL
, NULL, null, null, null);
266 $f = $table->addFieldInfo('cmid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
267 XMLDB_NOTNULL
, NULL, null, null, 0);
268 $f = $table->addFieldInfo('action', XMLDB_TYPE_CHAR
, '40', null,
269 XMLDB_NOTNULL
, NULL, null, null, null);
270 $f = $table->addFieldInfo('url', XMLDB_TYPE_CHAR
, '100', null,
271 XMLDB_NOTNULL
, NULL, null, null, null);
272 $f = $table->addFieldInfo('info', XMLDB_TYPE_CHAR
, '255', null,
273 XMLDB_NOTNULL
, NULL, null, null, null);
275 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
276 $table->addIndexInfo('host_user_course', XMLDB_INDEX_NOTUNIQUE
, array('hostid', 'userid', 'course'));
278 $result = $result && create_table($table);
281 $table = new XMLDBTable('mnet_rpc');
282 $table->comment
= 'Functions or methods that we may publish or subscribe to';
284 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
285 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
286 $f = $table->addFieldInfo('function_name', XMLDB_TYPE_CHAR
, '40', null,
287 XMLDB_NOTNULL
, NULL, null, null, null);
288 $f = $table->addFieldInfo('xmlrpc_path', XMLDB_TYPE_CHAR
, '80', null,
289 XMLDB_NOTNULL
, NULL, null, null, null);
290 $f = $table->addFieldInfo('parent_type', XMLDB_TYPE_CHAR
, '6', null,
291 XMLDB_NOTNULL
, NULL, null, null, null);
292 $f = $table->addFieldInfo('parent', XMLDB_TYPE_CHAR
, '20', null,
293 XMLDB_NOTNULL
, NULL, null, null, null);
294 $f = $table->addFieldInfo('enabled', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
295 XMLDB_NOTNULL
, NULL, null, null, 0);
296 $f = $table->addFieldInfo('help', XMLDB_TYPE_TEXT
, 'medium', null,
297 XMLDB_NOTNULL
, NULL, null, null, null);
298 $f = $table->addFieldInfo('profile', XMLDB_TYPE_TEXT
, 'medium', null,
299 XMLDB_NOTNULL
, NULL, null, null, null);
301 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
302 $table->addIndexInfo('enabled_xpath', XMLDB_INDEX_NOTUNIQUE
, array('enabled', 'xmlrpc_path'));
304 $result = $result && create_table($table);
306 $table = new XMLDBTable('mnet_service');
307 $table->comment
= 'A service is a group of functions';
309 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
310 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
311 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '40', null,
312 XMLDB_NOTNULL
, NULL, null, null, null);
313 $f = $table->addFieldInfo('description', XMLDB_TYPE_CHAR
, '40', null,
314 XMLDB_NOTNULL
, NULL, null, null, null);
315 $f = $table->addFieldInfo('apiversion', XMLDB_TYPE_CHAR
, '10', null,
316 XMLDB_NOTNULL
, NULL, null, null, null);
317 $f = $table->addFieldInfo('offer', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
318 XMLDB_NOTNULL
, NULL, null, null, 0);
320 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
322 $result = $result && create_table($table);
324 $table = new XMLDBTable('mnet_service2rpc');
325 $table->comment
= 'Group functions or methods under a service';
327 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
328 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
329 $f = $table->addFieldInfo('serviceid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
330 XMLDB_NOTNULL
, NULL, null, null, 0);
331 $f = $table->addFieldInfo('rpcid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
332 XMLDB_NOTNULL
, NULL, null, null, 0);
334 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
335 $table->addIndexInfo('unique', XMLDB_INDEX_UNIQUE
, array('rpcid', 'serviceid'));
337 $result = $result && create_table($table);
340 // Prime MNET configuration entries -- will be needed later by auth/mnet
342 include_once $CFG->dirroot
. '/mnet/lib.php';
343 $env = new mnet_environment();
347 // add mnethostid to user-
348 $table = new XMLDBTable('user');
349 $field = new XMLDBField('mnethostid');
350 $field->setType(XMLDB_TYPE_INTEGER
);
351 $field->setLength(10);
352 $field->setNotNull(true);
353 $field->setSequence(null);
354 $field->setEnum(null);
355 $field->setDefault('0');
356 $field->setPrevious("deleted");
357 $field->setNext("username");
358 $result = $result && add_field($table, $field);
360 // The default mnethostid is zero... we need to update this for all
361 // users of the local IdP service.
363 'mnethostid', $CFG->mnet_localhost_id
,
367 $index = new XMLDBIndex('username');
368 $index->setUnique(true);
369 $index->setFields(array('username'));
370 drop_index($table, $index);
371 $index->setFields(array('mnethostid', 'username'));
372 if (!add_index($table, $index)) {
373 notify(get_string('duplicate_usernames', 'mnet', 'http://docs.moodle.org/en/DuplicateUsernames'));
376 unset($table, $field, $index);
381 $table = new XMLDBTable('mnet_session');
382 $table->comment
='Store session data from users migrating to other sites';
384 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
385 XMLDB_NOTNULL
,XMLDB_SEQUENCE
, null, null, null);
386 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
387 XMLDB_NOTNULL
, NULL, null, null, 0);
388 $f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR
, '100', null,
389 XMLDB_NOTNULL
, NULL, null, null, null);
390 $f = $table->addFieldInfo('token', XMLDB_TYPE_CHAR
, '40', null,
391 XMLDB_NOTNULL
, NULL, null, null, null);
392 $f = $table->addFieldInfo('mnethostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
393 XMLDB_NOTNULL
, NULL, null, null, 0);
394 $f = $table->addFieldInfo('useragent', XMLDB_TYPE_CHAR
, '40', null,
395 XMLDB_NOTNULL
, NULL, null, null, null);
396 $f = $table->addFieldInfo('confirm_timeout', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
397 XMLDB_NOTNULL
, NULL, null, null, 0);
398 $f = $table->addFieldInfo('session_id', XMLDB_TYPE_CHAR
, '40', null,
399 XMLDB_NOTNULL
, NULL, null, null, null);
400 $f = $table->addFieldInfo('expires', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
401 XMLDB_NOTNULL
, NULL, null, null, 0);
403 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
404 $table->addIndexInfo('token', XMLDB_INDEX_UNIQUE
, array('token'));
406 $result = $result && create_table($table);
409 $table = new XMLDBTable('mnet_sso_access_control');
410 $table->comment
= 'Users by host permitted (or not) to login from a remote provider';
411 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
412 XMLDB_NOTNULL
,XMLDB_SEQUENCE
, null, null, null);
413 $f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR
, '100', null,
414 XMLDB_NOTNULL
, NULL, null, null, null);
415 $f = $table->addFieldInfo('mnet_host_id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
416 XMLDB_NOTNULL
, NULL, null, null, 0);
417 $f = $table->addFieldInfo('access', XMLDB_TYPE_CHAR
, '20', null,
418 XMLDB_NOTNULL
, NULL, null, null, 'allow');
420 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
421 $table->addIndexInfo('mnethostid_username', XMLDB_INDEX_UNIQUE
, array('mnet_host_id', 'username'));
423 $result = $result && create_table($table);
425 if (empty($USER->mnet_host_id
)) {
426 $USER->mnet_host_id
= $CFG->mnet_localhost_id
; // Something for the current user to prevent warnings
432 $table = new XMLDBTable('mnet_enrol_course');
433 $table->comment
= 'Information about courses on remote hosts';
434 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
435 XMLDB_NOTNULL
,XMLDB_SEQUENCE
, null, null, null);
436 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
437 XMLDB_NOTNULL
, NULL, null, null, 0);
438 $f = $table->addFieldInfo('remoteid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
439 XMLDB_NOTNULL
, NULL, null, null, 0);
440 $f = $table->addFieldInfo('cat_id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
441 XMLDB_NOTNULL
, NULL, null, null, 0);
442 $f = $table->addFieldInfo('cat_name', XMLDB_TYPE_CHAR
, '255', null,
443 XMLDB_NOTNULL
, NULL, null, null, null);
444 $f = $table->addFieldInfo('cat_description', XMLDB_TYPE_TEXT
, 'medium', null,
445 XMLDB_NOTNULL
, NULL, null, null, null);
446 $f = $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER
, '4', XMLDB_UNSIGNED
,
447 XMLDB_NOTNULL
, NULL, null, null, 0);
448 $f = $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR
, '254', null,
449 XMLDB_NOTNULL
, NULL, null, null, null);
450 $f = $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR
, '15', null,
451 XMLDB_NOTNULL
, NULL, null, null, null);
452 $f = $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR
, '100', null,
453 XMLDB_NOTNULL
, NULL, null, null, null);
454 $f = $table->addFieldInfo('summary', XMLDB_TYPE_TEXT
, 'medium', null,
455 XMLDB_NOTNULL
, NULL, null, null, null);
456 $f = $table->addFieldInfo('startdate', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
457 XMLDB_NOTNULL
, NULL, null, null, 0);
458 $f = $table->addFieldInfo('cost', XMLDB_TYPE_CHAR
, '10', null,
459 XMLDB_NOTNULL
, NULL, null, null, null);
460 $f = $table->addFieldInfo('currency', XMLDB_TYPE_CHAR
, '3', null,
461 XMLDB_NOTNULL
, NULL, null, null, null);
462 $f = $table->addFieldInfo('defaultroleid', XMLDB_TYPE_INTEGER
, '4', XMLDB_UNSIGNED
,
463 XMLDB_NOTNULL
, NULL, null, null, 0);
464 $f = $table->addFieldInfo('defaultrolename', XMLDB_TYPE_CHAR
, '255', null,
465 XMLDB_NOTNULL
, NULL, null, null, null);
467 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
468 $table->addIndexInfo('hostid_remoteid', XMLDB_INDEX_UNIQUE
, array('hostid', 'remoteid'));
470 $result = $result && create_table($table);
473 $table = new XMLDBTable('mnet_enrol_assignments');
475 $table->comment
= 'Information about enrolments on courses on remote hosts';
476 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
477 XMLDB_NOTNULL
,XMLDB_SEQUENCE
, null, null, null);
478 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
479 XMLDB_NOTNULL
, NULL, null, null, 0);
480 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
481 XMLDB_NOTNULL
, NULL, null, null, 0);
482 $f = $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
483 XMLDB_NOTNULL
, NULL, null, null, 0);
484 $f = $table->addFieldInfo('rolename', XMLDB_TYPE_CHAR
, '255', null,
485 XMLDB_NOTNULL
, NULL, null, null, null);
486 $f = $table->addFieldInfo('enroltime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
487 XMLDB_NOTNULL
, NULL, null, null, 0);
488 $f = $table->addFieldInfo('enroltype', XMLDB_TYPE_CHAR
, '20', null,
489 XMLDB_NOTNULL
, NULL, null, null, null);
492 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
493 $table->addIndexInfo('hostid_courseid', XMLDB_INDEX_NOTUNIQUE
, array('hostid', 'courseid'));
494 $table->addIndexInfo('userid', XMLDB_INDEX_NOTUNIQUE
, array('userid'));
496 $result = $result && create_table($table);
498 upgrade_main_savepoint($result, 2007010301);
501 if ($result && $oldversion < 2007010404) {
503 /// Define field shortname to be added to user_info_field
504 $table = new XMLDBTable('user_info_field');
505 $field = new XMLDBField('shortname');
506 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, 'shortname', 'id');
508 /// Launch add field shortname
509 $result = $result && add_field($table, $field);
511 /// Changing type of field name on table user_info_field to text
512 $table = new XMLDBTable('user_info_field');
513 $field = new XMLDBField('name');
514 $field->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, XMLDB_NOTNULL
, null, null, null, null, 'shortname');
516 /// Launch change of type for field name
517 $result = $result && change_field_type($table, $field);
519 /// For existing fields use 'name' as the 'shortname' entry
520 if ($fields = get_records_select('user_info_field', '', '', 'id, name')) {
521 foreach ($fields as $field) {
522 $field->shortname
= clean_param($field->name
, PARAM_ALPHANUM
);
523 $result && update_record('user_info_field', $field);
527 upgrade_main_savepoint($result, 2007010404);
530 if ($result && $oldversion < 2007011501) {
531 if (!empty($CFG->enablerecordcache
) && empty($CFG->rcache
) &&
532 // Note: won't force-load these settings into CFG
533 // we don't need or want cache during the upgrade itself
534 empty($CFG->cachetype
) && empty($CFG->intcachemax
)) {
535 set_config('cachetype', 'internal');
536 set_config('rcache', true);
537 set_config('intcachemax', $CFG->enablerecordcache
);
538 unset_config('enablerecordcache');
539 unset($CFG->enablerecordcache
);
542 upgrade_main_savepoint($result, 2007011501);
545 if ($result && $oldversion < 2007012100) {
546 /// Some old PG servers have user->firstname & user->lastname with 30cc. They must be 100cc.
547 /// Fixing that conditionally. MDL-7110
548 if ($CFG->dbfamily
== 'postgres') {
549 /// Get Metadata from user table
550 $cols = array_change_key_case($db->MetaColumns($CFG->prefix
. 'user'), CASE_LOWER
);
552 /// Process user->firstname if needed
553 if ($col = $cols['firstname']) {
554 if ($col->max_length
< 100) {
555 /// Changing precision of field firstname on table user to (100)
556 $table = new XMLDBTable('user');
557 $field = new XMLDBField('firstname');
558 $field->setAttributes(XMLDB_TYPE_CHAR
, '100', null, XMLDB_NOTNULL
, null, null, null, null, 'idnumber');
560 /// Launch change of precision for field firstname
561 $result = $result && change_field_precision($table, $field);
565 /// Process user->lastname if needed
566 if ($col = $cols['lastname']) {
567 if ($col->max_length
< 100) {
568 /// Changing precision of field lastname on table user to (100)
569 $table = new XMLDBTable('user');
570 $field = new XMLDBField('lastname');
571 $field->setAttributes(XMLDB_TYPE_CHAR
, '100', null, XMLDB_NOTNULL
, null, null, null, null, 'firstname');
573 /// Launch change of precision for field lastname
574 $result = $result && change_field_precision($table, $field);
579 upgrade_main_savepoint($result, 2007012100);
582 if ($result && $oldversion < 2007012101) {
584 /// Changing precision of field lang on table course to (30)
585 $table = new XMLDBTable('course');
586 $field = new XMLDBField('lang');
587 $field->setAttributes(XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, null, 'groupmodeforce');
589 /// Launch change of precision for field course->lang
590 $result = $result && change_field_precision($table, $field);
592 /// Changing precision of field lang on table user to (30)
593 $table = new XMLDBTable('user');
594 $field = new XMLDBField('lang');
595 $field->setAttributes(XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, 'en', 'country');
597 /// Launch change of precision for field user->lang
598 $result = $result && change_field_precision($table, $field);
600 upgrade_main_savepoint($result, 2007012101);
603 if ($result && $oldversion < 2007012400) {
605 /// Rename field access on table mnet_sso_access_control to accessctrl
606 $table = new XMLDBTable('mnet_sso_access_control');
607 $field = new XMLDBField('access');
608 $field->setAttributes(XMLDB_TYPE_CHAR
, '20', null, XMLDB_NOTNULL
, null, null, null, 'allow', 'mnet_host_id');
610 /// Launch rename field accessctrl
611 $result = $result && rename_field($table, $field, 'accessctrl');
613 upgrade_main_savepoint($result, 2007012400);
616 if ($result && $oldversion < 2007012500) {
617 execute_sql("DELETE FROM {$CFG->prefix}user WHERE username='changeme'", true);
619 upgrade_main_savepoint($result, 2007012500);
622 if ($result && $oldversion < 2007020400) {
623 /// Only for MySQL and PG, declare the user->ajax field as not null. MDL-8421.
624 if ($CFG->dbfamily
== 'mysql' ||
$CFG->dbfamily
== 'postgres') {
625 /// Changing nullability of field ajax on table user to not null
626 $table = new XMLDBTable('user');
627 $field = new XMLDBField('ajax');
628 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '1', 'htmleditor');
630 /// Launch change of nullability for field ajax
631 $result = $result && change_field_notnull($table, $field);
634 upgrade_main_savepoint($result, 2007020400);
637 if (!empty($CFG->rolesactive
) && $result && $oldversion < 2007021401) {
638 /// create default logged in user role if not present - upgrade rom 1.7.x
639 if (empty($CFG->defaultuserroleid
) or empty($CFG->guestroleid
) or $CFG->defaultuserroleid
== $CFG->guestroleid
) {
640 if (!get_records('role', 'shortname', 'user')) {
641 $userroleid = create_role(addslashes(get_string('authenticateduser')), 'user',
642 addslashes(get_string('authenticateduserdescription')), 'moodle/legacy:user');
644 reset_role_capabilities($userroleid);
645 set_config('defaultuserroleid', $userroleid);
650 upgrade_main_savepoint($result, 2007021401);
653 if ($result && $oldversion < 2007021501) {
654 /// delete removed setting from config
655 unset_config('tabselectedtofront');
657 upgrade_main_savepoint($result, 2007021501);
661 if ($result && $oldversion < 2007032200) {
663 /// Define table role_sortorder to be created
664 $table = new XMLDBTable('role_sortorder');
666 /// Adding fields to table role_sortorder
667 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
668 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
669 $table->addFieldInfo('roleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
670 $table->addFieldInfo('contextid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
671 $table->addFieldInfo('sortoder', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
673 /// Adding keys to table role_sortorder
674 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
675 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
676 $table->addKeyInfo('roleid', XMLDB_KEY_FOREIGN
, array('roleid'), 'role', array('id'));
677 $table->addKeyInfo('contextid', XMLDB_KEY_FOREIGN
, array('contextid'), 'context', array('id'));
679 /// Adding indexes to table role_sortorder
680 $table->addIndexInfo('userid-roleid-contextid', XMLDB_INDEX_UNIQUE
, array('userid', 'roleid', 'contextid'));
682 /// Launch create table for role_sortorder
683 $result = $result && create_table($table);
685 upgrade_main_savepoint($result, 2007032200);
689 /// code to change lenghen tag field to 255, MDL-9095
690 if ($result && $oldversion < 2007040400) {
692 /// Define index text (not unique) to be dropped form tags
693 $table = new XMLDBTable('tags');
694 $index = new XMLDBIndex('text');
695 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('text'));
697 /// Launch drop index text
698 $result = $result && drop_index($table, $index);
700 $field = new XMLDBField('text');
701 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null, 'userid');
703 /// Launch change of type for field text
704 $result = $result && change_field_type($table, $field);
706 $index = new XMLDBIndex('text');
707 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('text'));
709 /// Launch add index text
710 $result = $result && add_index($table, $index);
712 upgrade_main_savepoint($result, 2007040400);
715 if ($result && $oldversion < 2007041100) {
717 /// Define field idnumber to be added to course_modules
718 $table = new XMLDBTable('course_modules');
719 $field = new XMLDBField('idnumber');
720 $field->setAttributes(XMLDB_TYPE_CHAR
, '100', null, null, null, null, null, null, 'section');
722 /// Launch add field idnumber
723 $result = $result && add_field($table, $field);
725 upgrade_main_savepoint($result, 2007041100);
728 /* Changes to the custom profile menu type - store values rather than indices.
729 We could do all this with one tricky SQL statement but it's a one-off so no
730 harm in using PHP loops */
731 if ($result && $oldversion < 2007041600) {
733 /// Get the menu fields
734 if ($fields = get_records('user_info_field', 'datatype', 'menu')) {
735 foreach ($fields as $field) {
737 /// Get user data for the menu field
738 if ($data = get_records('user_info_data', 'fieldid', $field->id
)) {
740 /// Get the menu options
741 $options = explode("\n", $field->param1
);
742 foreach ($data as $d) {
743 $key = array_search($d->data
, $options);
745 /// If the data is an integer and is not one of the options,
746 /// set the respective option value
747 if (is_int($d->data
) and (($key === NULL) or ($key === false)) and isset($options[$d->data
])) {
748 $d->data
= $options[$d->data
];
749 $result = $result && update_record('user_info_data', $d);
756 upgrade_main_savepoint($result, 2007041600);
759 /// adding new gradebook tables
760 if ($result && $oldversion < 2007041800) {
762 /// Define table events_handlers to be created
763 $table = new XMLDBTable('events_handlers');
765 /// Adding fields to table events_handlers
766 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
767 $table->addFieldInfo('eventname', XMLDB_TYPE_CHAR
, '166', null, XMLDB_NOTNULL
, null, null, null, null);
768 $table->addFieldInfo('handlermodule', XMLDB_TYPE_CHAR
, '166', null, XMLDB_NOTNULL
, null, null, null, null);
769 $table->addFieldInfo('handlerfile', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
770 $table->addFieldInfo('handlerfunction', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
772 /// Adding keys to table events_handlers
773 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
775 /// Adding indexes to table events_handlers
776 $table->addIndexInfo('eventname-handlermodule', XMLDB_INDEX_UNIQUE
, array('eventname', 'handlermodule'));
778 /// Launch create table for events_handlers
779 $result = $result && create_table($table);
781 /// Define table events_queue to be created
782 $table = new XMLDBTable('events_queue');
784 /// Adding fields to table events_queue
785 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
786 $table->addFieldInfo('eventdata', XMLDB_TYPE_TEXT
, 'big', null, XMLDB_NOTNULL
, null, null, null, null);
787 $table->addFieldInfo('schedule', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
788 $table->addFieldInfo('stackdump', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
789 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
790 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
792 /// Adding keys to table events_queue
793 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
794 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
796 /// Launch create table for events_queue
797 $result = $result && create_table($table);
799 /// Define table events_queue_handlers to be created
800 $table = new XMLDBTable('events_queue_handlers');
802 /// Adding fields to table events_queue_handlers
803 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
804 $table->addFieldInfo('queuedeventid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
805 $table->addFieldInfo('handlerid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
806 $table->addFieldInfo('status', XMLDB_TYPE_INTEGER
, '10', null, null, null, null, null, null);
807 $table->addFieldInfo('errormessage', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
808 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
810 /// Adding keys to table events_queue_handlers
811 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
812 $table->addKeyInfo('queuedeventid', XMLDB_KEY_FOREIGN
, array('queuedeventid'), 'events_queue', array('id'));
813 $table->addKeyInfo('handlerid', XMLDB_KEY_FOREIGN
, array('handlerid'), 'events_handlers', array('id'));
815 /// Launch create table for events_queue_handlers
816 $result = $result && create_table($table);
818 upgrade_main_savepoint($result, 2007041800);
821 if ($result && $oldversion < 2007043001) {
823 /// Define field schedule to be added to events_handlers
824 $table = new XMLDBTable('events_handlers');
825 $field = new XMLDBField('schedule');
826 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null, 'handlerfunction');
828 /// Launch add field schedule
829 $result = $result && add_field($table, $field);
831 /// Define field status to be added to events_handlers
832 $table = new XMLDBTable('events_handlers');
833 $field = new XMLDBField('status');
834 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'schedule');
836 /// Launch add field status
837 $result = $result && add_field($table, $field);
839 upgrade_main_savepoint($result, 2007043001);
842 if ($result && $oldversion < 2007050201) {
844 /// Define field theme to be added to course_categories
845 $table = new XMLDBTable('course_categories');
846 $field = new XMLDBField('theme');
847 $field->setAttributes(XMLDB_TYPE_CHAR
, '50', null, null, null, null, null, null, 'path');
849 /// Launch add field theme
850 $result = $result && add_field($table, $field);
852 upgrade_main_savepoint($result, 2007050201);
855 if ($result && $oldversion < 2007051100) {
857 /// Define field forceunique to be added to user_info_field
858 $table = new XMLDBTable('user_info_field');
859 $field = new XMLDBField('forceunique');
860 $field->setAttributes(XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'visible');
862 /// Launch add field forceunique
863 $result = $result && add_field($table, $field);
865 /// Define field signup to be added to user_info_field
866 $table = new XMLDBTable('user_info_field');
867 $field = new XMLDBField('signup');
868 $field->setAttributes(XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'forceunique');
870 /// Launch add field signup
871 $result = $result && add_field($table, $field);
873 upgrade_main_savepoint($result, 2007051100);
876 if (!empty($CFG->rolesactive
) && $result && $oldversion < 2007051801) {
877 // Get the role id of the "Auth. User" role and check if the default role id is different
878 // note: use of assign_capability() is discouraged in upgrade script!
879 $userrole = get_record( 'role', 'shortname', 'user' );
880 $defaultroleid = $CFG->defaultuserroleid
;
882 if( $defaultroleid != $userrole->id
) {
883 // Add in the new moodle/my:manageblocks capibility to the default user role
884 $context = get_context_instance(CONTEXT_SYSTEM
);
885 assign_capability('moodle/my:manageblocks',CAP_ALLOW
,$defaultroleid,$context->id
);
888 upgrade_main_savepoint($result, 2007051801);
891 if ($result && $oldversion < 2007052200) {
893 /// Define field schedule to be dropped from events_queue
894 $table = new XMLDBTable('events_queue');
895 $field = new XMLDBField('schedule');
897 /// Launch drop field stackdump
898 $result = $result && drop_field($table, $field);
900 upgrade_main_savepoint($result, 2007052200);
903 if ($result && $oldversion < 2007052300) {
904 require_once($CFG->dirroot
. '/question/upgrade.php');
905 $result = $result && question_remove_rqp_qtype();
907 upgrade_main_savepoint($result, 2007052300);
910 if ($result && $oldversion < 2007060500) {
912 /// Define field usermodified to be added to post
913 $table = new XMLDBTable('post');
914 $field = new XMLDBField('usermodified');
915 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null, 'created');
917 /// Launch add field usermodified
918 $result = $result && add_field($table, $field);
920 /// Define key usermodified (foreign) to be added to post
921 $table = new XMLDBTable('post');
922 $key = new XMLDBKey('usermodified');
923 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
925 /// Launch add key usermodified
926 $result = $result && add_key($table, $key);
928 upgrade_main_savepoint($result, 2007060500);
931 if ($result && $oldversion < 2007070603) {
932 // Small update of guest user to be 100% sure it has the correct mnethostid (MDL-10375)
933 set_field('user', 'mnethostid', $CFG->mnet_localhost_id
, 'username', 'guest');
935 upgrade_main_savepoint($result, 2007070603);
938 if ($result && $oldversion < 2007071400) {
940 ** mnet application table
942 $table = new XMLDBTable('mnet_application');
943 $table->comment
= 'Information about applications on remote hosts';
944 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
945 XMLDB_NOTNULL
,XMLDB_SEQUENCE
, null, null, null);
946 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '50', null,
947 XMLDB_NOTNULL
, NULL, null, null, null);
948 $f = $table->addFieldInfo('display_name', XMLDB_TYPE_CHAR
, '50', null,
949 XMLDB_NOTNULL
, NULL, null, null, null);
950 $f = $table->addFieldInfo('xmlrpc_server_url', XMLDB_TYPE_CHAR
, '255', null,
951 XMLDB_NOTNULL
, NULL, null, null, null);
952 $f = $table->addFieldInfo('sso_land_url', XMLDB_TYPE_CHAR
, '255', null,
953 XMLDB_NOTNULL
, NULL, null, null, null);
956 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
958 $result = $result && create_table($table);
960 // Insert initial applications (moodle and mahara)
961 $application = new stdClass();
962 $application->name
= 'moodle';
963 $application->display_name
= 'Moodle';
964 $application->xmlrpc_server_url
= '/mnet/xmlrpc/server.php';
965 $application->sso_land_url
= '/auth/mnet/land.php';
967 $newid = insert_record('mnet_application', $application, false);
970 $application = new stdClass();
971 $application->name
= 'mahara';
972 $application->display_name
= 'Mahara';
973 $application->xmlrpc_server_url
= '/api/xmlrpc/server.php';
974 $application->sso_land_url
= '/auth/xmlrpc/land.php';
975 $result = $result && insert_record('mnet_application', $application, false);
977 // New mnet_host->applicationid field
978 $table = new XMLDBTable('mnet_host');
979 $field = new XMLDBField('applicationid');
980 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, $newid , 'last_log_id');
982 $result = $result && add_field($table, $field);
984 /// Define key applicationid (foreign) to be added to mnet_host
985 $table = new XMLDBTable('mnet_host');
986 $key = new XMLDBKey('applicationid');
987 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('applicationid'), 'mnet_application', array('id'));
989 /// Launch add key applicationid
990 $result = $result && add_key($table, $key);
992 upgrade_main_savepoint($result, 2007071400);
995 if ($result && $oldversion < 2007071607) {
996 require_once($CFG->dirroot
. '/question/upgrade.php');
997 $result = $result && question_remove_rqp_qtype_config_string();
999 upgrade_main_savepoint($result, 2007071607);
1002 if ($result && $oldversion < 2007072200) {
1004 /// Remove all grade tables used in development phases - we need new empty tables for final gradebook upgrade
1005 $tables = array('grade_categories',
1007 'grade_calculations',
1010 'grade_grades_final',
1011 'grade_grades_text',
1013 'grade_outcomes_courses',
1015 'grade_import_newitem',
1016 'grade_import_values');
1018 foreach ($tables as $table) {
1019 $table = new XMLDBTable($table);
1020 if (table_exists($table)) {
1025 $tables = array('grade_categories_history',
1026 'grade_items_history',
1027 'grade_grades_history',
1028 'grade_grades_text_history',
1029 'grade_scale_history',
1030 'grade_outcomes_history');
1032 foreach ($tables as $table) {
1033 $table = new XMLDBTable($table);
1034 if (table_exists($table)) {
1040 /// Define table grade_outcomes to be created
1041 $table = new XMLDBTable('grade_outcomes');
1043 /// Adding fields to table grade_outcomes
1044 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1045 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1046 $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1047 $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
1048 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1049 $table->addFieldInfo('description', XMLDB_TYPE_TEXT
, 'small', null, null, null, null, null, null);
1050 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1051 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1052 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1054 /// Adding keys to table grade_outcomes
1055 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1056 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1057 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
1058 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
1060 /// Launch create table for grade_outcomes
1061 $result = $result && create_table($table);
1064 /// Define table grade_categories to be created
1065 $table = new XMLDBTable('grade_categories');
1067 /// Adding fields to table grade_categories
1068 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1069 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1070 $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1071 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1072 $table->addFieldInfo('path', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1073 $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1074 $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1075 $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1076 $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1077 $table->addFieldInfo('aggregateonlygraded', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1078 $table->addFieldInfo('aggregateoutcomes', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1079 $table->addFieldInfo('aggregatesubcats', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1080 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1081 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1083 /// Adding keys to table grade_categories
1084 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1085 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1086 $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN
, array('parent'), 'grade_categories', array('id'));
1088 /// Launch create table for grade_categories
1089 $result = $result && create_table($table);
1092 /// Define table grade_items to be created
1093 $table = new XMLDBTable('grade_items');
1095 /// Adding fields to table grade_items
1096 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1097 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1098 $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1099 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1100 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, null);
1101 $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR
, '30', null, null, null, null, null, null);
1102 $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1103 $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1104 $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1105 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1106 $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1107 $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '1');
1108 $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
1109 $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1110 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1111 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1112 $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1113 $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '1.0');
1114 $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1115 $table->addFieldInfo('aggregationcoef', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1116 $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1117 $table->addFieldInfo('display', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1118 $table->addFieldInfo('decimals', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, null, null, null, null, null);
1119 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1120 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1121 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1122 $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1123 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1124 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1126 /// Adding keys to table grade_items
1127 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1128 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1129 $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN
, array('categoryid'), 'grade_categories', array('id'));
1130 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
1131 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN
, array('outcomeid'), 'grade_outcomes', array('id'));
1133 /// Adding indexes to table grade_grades
1134 $table->addIndexInfo('locked-locktime', XMLDB_INDEX_NOTUNIQUE
, array('locked', 'locktime'));
1135 $table->addIndexInfo('itemtype-needsupdate', XMLDB_INDEX_NOTUNIQUE
, array('itemtype', 'needsupdate'));
1136 $table->addIndexInfo('gradetype', XMLDB_INDEX_NOTUNIQUE
, array('gradetype'));
1138 /// Launch create table for grade_items
1139 $result = $result && create_table($table);
1142 /// Define table grade_grades to be created
1143 $table = new XMLDBTable('grade_grades');
1145 /// Adding fields to table grade_grades
1146 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1147 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1148 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1149 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
1150 $table->addFieldInfo('rawgrademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
1151 $table->addFieldInfo('rawgrademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1152 $table->addFieldInfo('rawscaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1153 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1154 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
1155 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1156 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1157 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1158 $table->addFieldInfo('exported', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1159 $table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1160 $table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1161 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1162 $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1163 $table->addFieldInfo('information', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1164 $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1165 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1166 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1168 /// Adding keys to table grade_grades
1169 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1170 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN
, array('itemid'), 'grade_items', array('id'));
1171 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
1172 $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN
, array('rawscaleid'), 'scale', array('id'));
1173 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
1175 /// Adding indexes to table grade_grades
1176 $table->addIndexInfo('locked-locktime', XMLDB_INDEX_NOTUNIQUE
, array('locked', 'locktime'));
1178 /// Launch create table for grade_grades
1179 $result = $result && create_table($table);
1182 /// Define table grade_outcomes_history to be created
1183 $table = new XMLDBTable('grade_outcomes_history');
1185 /// Adding fields to table grade_outcomes_history
1186 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1187 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1188 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1189 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1190 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1191 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1192 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1193 $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1194 $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
1195 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1196 $table->addFieldInfo('description', XMLDB_TYPE_TEXT
, 'small', null, null, null, null, null, null);
1198 /// Adding keys to table grade_outcomes_history
1199 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1200 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_outcomes', array('id'));
1201 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1202 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
1203 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN
, array('loggeduser'), 'user', array('id'));
1205 /// Adding indexes to table grade_outcomes_history
1206 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1208 /// Launch create table for grade_outcomes_history
1209 $result = $result && create_table($table);
1212 /// Define table grade_categories_history to be created
1213 $table = new XMLDBTable('grade_categories_history');
1215 /// Adding fields to table grade_categories_history
1216 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1217 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1218 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1219 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1220 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1221 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1222 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1223 $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1224 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1225 $table->addFieldInfo('path', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1226 $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1227 $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1228 $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1229 $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1230 $table->addFieldInfo('aggregateonlygraded', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1231 $table->addFieldInfo('aggregateoutcomes', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1232 $table->addFieldInfo('aggregatesubcats', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1234 /// Adding keys to table grade_categories_history
1235 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1236 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_categories', array('id'));
1237 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1238 $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN
, array('parent'), 'grade_categories', array('id'));
1239 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN
, array('loggeduser'), 'user', array('id'));
1241 /// Adding indexes to table grade_categories_history
1242 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1244 /// Launch create table for grade_categories_history
1245 $result = $result && create_table($table);
1248 /// Define table grade_items_history to be created
1249 $table = new XMLDBTable('grade_items_history');
1251 /// Adding fields to table grade_items_history
1252 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1253 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1254 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1255 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1256 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1257 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1258 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1259 $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1260 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1261 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, null);
1262 $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR
, '30', null, null, null, null, null, null);
1263 $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1264 $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1265 $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1266 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1267 $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1268 $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '1');
1269 $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
1270 $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1271 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1272 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1273 $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1274 $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '1.0');
1275 $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1276 $table->addFieldInfo('aggregationcoef', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1277 $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1278 $table->addFieldInfo('display', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1279 $table->addFieldInfo('decimals', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, null, null, null, null, null);
1280 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1281 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1282 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1283 $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1285 /// Adding keys to table grade_items_history
1286 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1287 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_items', array('id'));
1288 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1289 $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN
, array('categoryid'), 'grade_categories', array('id'));
1290 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
1291 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN
, array('outcomeid'), 'grade_outcomes', array('id'));
1292 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN
, array('loggeduser'), 'user', array('id'));
1294 /// Adding indexes to table grade_items_history
1295 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1297 /// Launch create table for grade_items_history
1298 $result = $result && create_table($table);
1301 /// Define table grade_grades_history to be created
1302 $table = new XMLDBTable('grade_grades_history');
1304 /// Adding fields to table grade_grades_history
1305 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1306 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1307 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1308 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1309 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1310 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1311 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1312 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1313 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
1314 $table->addFieldInfo('rawgrademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
1315 $table->addFieldInfo('rawgrademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1316 $table->addFieldInfo('rawscaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1317 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1318 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
1319 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1320 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1321 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1322 $table->addFieldInfo('exported', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1323 $table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1324 $table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1325 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1326 $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1327 $table->addFieldInfo('information', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1328 $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1330 /// Adding keys to table grade_grades_history
1331 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1332 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_grades', array('id'));
1333 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN
, array('itemid'), 'grade_items', array('id'));
1334 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
1335 $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN
, array('rawscaleid'), 'scale', array('id'));
1336 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
1337 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN
, array('loggeduser'), 'user', array('id'));
1339 /// Adding indexes to table grade_grades_history
1340 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1342 /// Launch create table for grade_grades_history
1343 $result = $result && create_table($table);
1346 /// Define table scale_history to be created
1347 $table = new XMLDBTable('scale_history');
1349 /// Adding fields to table scale_history
1350 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1351 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1352 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1353 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1354 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1355 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1356 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1357 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1358 $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1359 $table->addFieldInfo('scale', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
1360 $table->addFieldInfo('description', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
1362 /// Adding keys to table scale_history
1363 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1364 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'scale', array('id'));
1365 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1366 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN
, array('loggeduser'), 'user', array('id'));
1368 /// Adding indexes to table scale_history
1369 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1371 /// Launch create table for scale_history
1372 $result = $result && create_table($table);
1374 /// upgrade the old 1.8 gradebook - migrade data into new grade tables
1376 if ($rs = get_recordset('course')) {
1377 while ($course = rs_fetch_next_record($rs)) {
1378 // this function uses SQL only, it must not be changed after 1.9 goes stable!!
1379 if (!upgrade_18_gradebook($course->id
)) {
1388 upgrade_main_savepoint($result, 2007072200);
1391 if ($result && $oldversion < 2007072400) {
1392 /// Dropping one DEFAULT in a TEXT column. It's was only one remaining
1393 /// since Moodle 1.7, so new servers won't have those anymore.
1395 /// Changing the default of field sessdata on table sessions2 to drop it
1396 $table = new XMLDBTable('sessions2');
1397 $field = new XMLDBField('sessdata');
1398 $field->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, null, null, null, null, null, 'modified');
1400 /// Launch change of default for field sessdata
1401 $result = $result && change_field_default($table, $field);
1403 upgrade_main_savepoint($result, 2007072400);
1407 if ($result && $oldversion < 2007073100) {
1408 /// Define table grade_outcomes_courses to be created
1409 $table = new XMLDBTable('grade_outcomes_courses');
1411 /// Adding fields to table grade_outcomes_courses
1412 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1413 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1414 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1416 /// Adding keys to table grade_outcomes_courses
1417 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1418 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1419 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN
, array('outcomeid'), 'grade_outcomes', array('id'));
1420 $table->addKeyInfo('courseid-outcomeid', XMLDB_KEY_UNIQUE
, array('courseid', 'outcomeid'));
1421 /// Launch create table for grade_outcomes_courses
1422 $result = $result && create_table($table);
1424 upgrade_main_savepoint($result, 2007073100);
1428 if ($result && $oldversion < 2007073101) { // Add new tag tables
1430 /// Define table tag to be created
1431 $table = new XMLDBTable('tag');
1433 /// Adding fields to table tag
1434 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1435 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
1436 $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1437 $table->addFieldInfo('tagtype', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1438 $table->addFieldInfo('description', XMLDB_TYPE_TEXT
, 'small', null, null, null, null, null, null);
1439 $table->addFieldInfo('descriptionformat', XMLDB_TYPE_INTEGER
, '2', null, XMLDB_NOTNULL
, null, null, null, null);
1440 $table->addFieldInfo('flag', XMLDB_TYPE_INTEGER
, '4', XMLDB_UNSIGNED
, null, null, null, null, '0');
1441 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1443 /// Adding keys to table tag
1444 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1446 /// Adding indexes to table tag
1447 $table->addIndexInfo('name', XMLDB_INDEX_UNIQUE
, array('name'));
1449 /// Launch create table for tag
1450 $result = $result && create_table($table);
1454 /// Define table tag_correlation to be created
1455 $table = new XMLDBTable('tag_correlation');
1457 /// Adding fields to table tag_correlation
1458 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1459 $table->addFieldInfo('tagid', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
1460 $table->addFieldInfo('correlatedtags', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
1462 /// Adding keys to table tag_correlation
1463 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1465 /// Adding indexes to table tag_correlation
1466 $table->addIndexInfo('tagid', XMLDB_INDEX_UNIQUE
, array('tagid'));
1468 /// Launch create table for tag_correlation
1469 $result = $result && create_table($table);
1473 /// Define table tag_instance to be created
1474 $table = new XMLDBTable('tag_instance');
1476 /// Adding fields to table tag_instance
1477 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1478 $table->addFieldInfo('tagid', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
1479 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1480 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
1482 /// Adding keys to table tag_instance
1483 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1485 /// Adding indexes to table tag_instance
1486 $table->addIndexInfo('tagiditem', XMLDB_INDEX_NOTUNIQUE
, array('tagid', 'itemtype', 'itemid'));
1488 /// Launch create table for tag_instance
1489 $result = $result && create_table($table);
1491 upgrade_main_savepoint($result, 2007073101);
1495 if ($result && $oldversion < 2007073103) {
1497 /// Define field rawname to be added to tag
1498 $table = new XMLDBTable('tag');
1499 $field = new XMLDBField('rawname');
1500 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null, 'name');
1502 /// Launch add field rawname
1503 $result = $result && add_field($table, $field);
1505 upgrade_main_savepoint($result, 2007073103);
1508 if ($result && $oldversion < 2007073105) {
1510 /// Define field description to be added to grade_outcomes
1511 $table = new XMLDBTable('grade_outcomes');
1512 $field = new XMLDBField('description');
1513 if (!field_exists($table, $field)) {
1514 $field->setAttributes(XMLDB_TYPE_TEXT
, 'small', null, null, null, null, null, null, 'scaleid');
1515 /// Launch add field description
1516 $result = $result && add_field($table, $field);
1519 $table = new XMLDBTable('grade_outcomes_history');
1520 $field = new XMLDBField('description');
1521 if (!field_exists($table, $field)) {
1522 $field->setAttributes(XMLDB_TYPE_TEXT
, 'small', null, null, null, null, null, null, 'scaleid');
1523 /// Launch add field description
1524 $result = $result && add_field($table, $field);
1527 upgrade_main_savepoint($result, 2007073105);
1530 // adding unique contraint on (courseid,shortname) of an outcome
1531 if ($result && $oldversion < 2007080100) {
1533 /// Define key courseid-shortname (unique) to be added to grade_outcomes
1534 $table = new XMLDBTable('grade_outcomes');
1535 $key = new XMLDBKey('courseid-shortname');
1536 $key->setAttributes(XMLDB_KEY_UNIQUE
, array('courseid', 'shortname'));
1538 /// Launch add key courseid-shortname
1539 $result = $result && add_key($table, $key);
1541 upgrade_main_savepoint($result, 2007080100);
1544 /// originally there was supportname and supportemail upgrade code - this is handled in upgradesettings.php instead
1546 if ($result && $oldversion < 2007080202) {
1548 /// Define index tagiditem (not unique) to be dropped form tag_instance
1549 $table = new XMLDBTable('tag_instance');
1550 $index = new XMLDBIndex('tagiditem');
1551 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('tagid', 'itemtype', 'itemid'));
1553 /// Launch drop index tagiditem
1554 drop_index($table, $index);
1556 /// Define index tagiditem (unique) to be added to tag_instance
1557 $table = new XMLDBTable('tag_instance');
1558 $index = new XMLDBIndex('tagiditem');
1559 $index->setAttributes(XMLDB_INDEX_UNIQUE
, array('tagid', 'itemtype', 'itemid'));
1561 /// Launch add index tagiditem
1562 $result = $result && add_index($table, $index);
1564 upgrade_main_savepoint($result, 2007080202);
1567 if ($result && $oldversion < 2007080300) {
1569 /// Define field aggregateoutcomes to be added to grade_categories
1570 $table = new XMLDBTable('grade_categories');
1571 $field = new XMLDBField('aggregateoutcomes');
1572 if (!field_exists($table, $field)) {
1573 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'droplow');
1575 /// Launch add field aggregateoutcomes
1576 $result = $result && add_field($table, $field);
1579 /// Define field aggregateoutcomes to be added to grade_categories
1580 $table = new XMLDBTable('grade_categories_history');
1581 $field = new XMLDBField('aggregateoutcomes');
1582 if (!field_exists($table, $field)) {
1583 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'droplow');
1585 /// Launch add field aggregateoutcomes
1586 $result = $result && add_field($table, $field);
1589 upgrade_main_savepoint($result, 2007080300);
1592 if ($result && $oldversion < 2007080800) { /// Normalize course->shortname MDL-10026
1594 /// Changing precision of field shortname on table course to (100)
1595 $table = new XMLDBTable('course');
1596 $field = new XMLDBField('shortname');
1597 $field->setAttributes(XMLDB_TYPE_CHAR
, '100', null, XMLDB_NOTNULL
, null, null, null, null, 'fullname');
1599 /// Launch change of precision for field shortname
1600 $result = $result && change_field_precision($table, $field);
1602 upgrade_main_savepoint($result, 2007080800);
1605 if ($result && $oldversion < 2007080900) {
1606 /// Add context.path & index
1607 $table = new XMLDBTable('context');
1608 $field = new XMLDBField('path');
1609 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null, 'instanceid');
1610 $result = $result && add_field($table, $field);
1611 $table = new XMLDBTable('context');
1612 $index = new XMLDBIndex('path');
1613 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('path'));
1614 $result = $result && add_index($table, $index);
1616 /// Add context.depth
1617 $table = new XMLDBTable('context');
1618 $field = new XMLDBField('depth');
1619 $field->setAttributes(XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'path');
1620 $result = $result && add_field($table, $field);
1622 /// make sure the system context has proper data
1623 get_system_context(false);
1625 upgrade_main_savepoint($result, 2007080900);
1628 if ($result && $oldversion < 2007080903) {
1630 $table = new XMLDBTable('grade_grades');
1631 $index = new XMLDBIndex('locked-locktime');
1632 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('locked', 'locktime'));
1634 if (!index_exists($table, $index)) {
1635 /// Launch add index
1636 $result = $result && add_index($table, $index);
1640 $table = new XMLDBTable('grade_items');
1641 $index = new XMLDBIndex('locked-locktime');
1642 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('locked', 'locktime'));
1644 if (!index_exists($table, $index)) {
1645 /// Launch add index
1646 $result = $result && add_index($table, $index);
1649 /// Define index itemtype-needsupdate (not unique) to be added to grade_items
1650 $table = new XMLDBTable('grade_items');
1651 $index = new XMLDBIndex('itemtype-needsupdate');
1652 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('itemtype', 'needsupdate'));
1653 if (!index_exists($table, $index)) {
1654 /// Launch add index itemtype-needsupdate
1655 $result = $result && add_index($table, $index);
1659 $table = new XMLDBTable('grade_items');
1660 $index = new XMLDBIndex('gradetype');
1661 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('gradetype'));
1663 if (!index_exists($table, $index)) {
1664 /// Launch add index
1665 $result = $result && add_index($table, $index);
1668 upgrade_main_savepoint($result, 2007080903);
1671 if ($result && $oldversion < 2007081000) {
1672 require_once($CFG->dirroot
. '/question/upgrade.php');
1673 $result = $result && question_upgrade_context_etc();
1675 upgrade_main_savepoint($result, 2007081000);
1678 if ($result && $oldversion < 2007081302) {
1680 $table = new XMLDBTable('groups');
1681 $field = new XMLDBField('password');
1683 if (field_exists($table, $field)) {
1684 /// 1.7.*/1.6.*/1.5.* - create 'groupings' and 'groupings_groups' + rename password to enrolmentkey
1685 /// or second run after fixing structure broken from 1.8.x
1686 $result = $result && upgrade_17_groups();
1688 } else if (table_exists(new XMLDBTable('groups_groupings'))) {
1689 /// ELSE 'groups_groupings' table exists, this is 1.8.* properly upgraded
1690 $result = $result && upgrade_18_groups();
1693 /// broken groups, failed 1.8.x upgrade
1694 upgrade_18_broken_groups();
1695 notify('Warning: failed groups upgrade detected! Unfortunately this problem '.
1696 'can not be fixed automatically. Mapping of groups to courses was lost, '.
1697 'you can either revert to backup from 1.7.x and run ugprade again or '.
1698 'continue and fill in the missing course ids into groups table manually.');
1702 upgrade_main_savepoint($result, 2007081302);
1705 if ($result && $oldversion < 2007081303) {
1706 /// Common groups upgrade for 1.8.* and 1.7.*/1.6.*..
1708 // delete not used fields
1709 $table = new XMLDBTable('groups');
1710 $field = new XMLDBField('theme');
1711 if (field_exists($table, $field)) {
1712 drop_field($table, $field);
1714 $table = new XMLDBTable('groups');
1715 $field = new XMLDBField('lang');
1716 if (field_exists($table, $field)) {
1717 drop_field($table, $field);
1720 /// Add groupingid field/f.key to 'course' table.
1721 $table = new XMLDBTable('course');
1722 $field = new XMLDBField('defaultgroupingid');
1723 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', $prev='groupmodeforce');
1724 $result = $result && add_field($table, $field);
1727 /// Add grouping ID, grouponly field/f.key to 'course_modules' table.
1728 $table = new XMLDBTable('course_modules');
1729 $field = new XMLDBField('groupingid');
1730 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', $prev='groupmode');
1731 $result = $result && add_field($table, $field);
1733 $table = new XMLDBTable('course_modules');
1734 $field = new XMLDBField('groupmembersonly');
1735 $field->setAttributes(XMLDB_TYPE_INTEGER
, '4', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', $prev='groupingid');
1736 $result = $result && add_field($table, $field);
1738 $table = new XMLDBTable('course_modules');
1739 $key = new XMLDBKey('groupingid');
1740 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('groupingid'), 'groupings', array('id'));
1741 $result = $result && add_key($table, $key);
1743 upgrade_main_savepoint($result, 2007081303);
1746 if ($result && $oldversion < 2007082300) {
1748 /// Define field ordering to be added to tag_instance table
1749 $table = new XMLDBTable('tag_instance');
1750 $field = new XMLDBField('ordering');
1752 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'itemid');
1754 /// Launch add field rawname
1755 $result = $result && add_field($table, $field);
1757 upgrade_main_savepoint($result, 2007082300);
1760 if ($result && $oldversion < 2007082700) {
1762 /// Define field timemodified to be added to tag_instance
1763 $table = new XMLDBTable('tag_instance');
1764 $field = new XMLDBField('timemodified');
1765 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'ordering');
1767 /// Launch add field timemodified
1768 $result = $result && add_field($table, $field);
1770 upgrade_main_savepoint($result, 2007082700);
1773 /// migrate all tags table to tag - this code MUST use SQL only,
1774 /// because if the db structure changes the library functions will fail in future
1775 if ($result && $oldversion < 2007082701) {
1776 $tagrefs = array(); // $tagrefs[$oldtagid] = $newtagid
1777 if ($rs = get_recordset('tags')) {
1779 while ($oldtag = rs_fetch_next_record($rs)) {
1780 $raw_normalized = clean_param($oldtag->text
, PARAM_TAG
);
1781 $normalized = moodle_strtolower($raw_normalized);
1782 // if this tag does not exist in tag table yet
1783 if (!$newtag = get_record('tag', 'name', addslashes($normalized), '', '', '', '', 'id')) {
1784 $itag = new object();
1785 $itag->name
= $normalized;
1786 $itag->rawname
= $raw_normalized;
1787 $itag->userid
= $oldtag->userid
;
1788 $itag->timemodified
= time();
1789 $itag->descriptionformat
= 0; // default format
1790 if ($oldtag->type
== 'official') {
1791 $itag->tagtype
= 'official';
1793 $itag->tagtype
= 'default';
1796 if ($idx = insert_record('tag', addslashes_recursive($itag))) {
1797 $tagrefs[$oldtag->id
] = $idx;
1799 // if this tag is already used by tag table
1801 $tagrefs[$oldtag->id
] = $newtag->id
;
1808 // fetch all the tag instances and migrate them as well
1809 if ($rs = get_recordset('blog_tag_instance')) {
1811 while ($blogtag = rs_fetch_next_record($rs)) {
1812 if (array_key_exists($blogtag->tagid
, $tagrefs)) {
1813 $tag_instance = new object();
1814 $tag_instance->tagid
= $tagrefs[$blogtag->tagid
];
1815 $tag_instance->itemtype
= 'blog';
1816 $tag_instance->itemid
= $blogtag->entryid
;
1817 $tag_instance->ordering
= 1; // does not matter much, because originally there was no ordering in blogs
1818 $tag_instance->timemodified
= time();
1819 insert_record('tag_instance', $tag_instance);
1826 unset($tagrefs); // release memory
1828 $table = new XMLDBTable('tags');
1830 $table = new XMLDBTable('blog_tag_instance');
1833 upgrade_main_savepoint($result, 2007082701);
1836 /// MDL-11015, MDL-11016
1837 if ($result && $oldversion < 2007082800) {
1839 /// Changing type of field userid on table tag to int
1840 $table = new XMLDBTable('tag');
1841 $field = new XMLDBField('userid');
1842 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null, 'id');
1844 /// Launch change of type for field userid
1845 $result = $result && change_field_type($table, $field);
1847 /// Changing type of field descriptionformat on table tag to int
1848 $table = new XMLDBTable('tag');
1849 $field = new XMLDBField('descriptionformat');
1850 $field->setAttributes(XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'description');
1852 /// Launch change of type for field descriptionformat
1853 $result = $result && change_field_type($table, $field);
1855 /// Define key userid (foreign) to be added to tag
1856 $table = new XMLDBTable('tag');
1857 $key = new XMLDBKey('userid');
1858 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
1860 /// Launch add key userid
1861 $result = $result && add_key($table, $key);
1863 /// Define index tagiditem (unique) to be dropped form tag_instance
1864 $table = new XMLDBTable('tag_instance');
1865 $index = new XMLDBIndex('tagiditem');
1866 $index->setAttributes(XMLDB_INDEX_UNIQUE
, array('tagid', 'itemtype', 'itemid'));
1868 /// Launch drop index tagiditem
1869 $result = $result && drop_index($table, $index);
1871 /// Changing type of field tagid on table tag_instance to int
1872 $table = new XMLDBTable('tag_instance');
1873 $field = new XMLDBField('tagid');
1874 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null, 'id');
1876 /// Launch change of type for field tagid
1877 $result = $result && change_field_type($table, $field);
1879 /// Define key tagid (foreign) to be added to tag_instance
1880 $table = new XMLDBTable('tag_instance');
1881 $key = new XMLDBKey('tagid');
1882 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('tagid'), 'tag', array('id'));
1884 /// Launch add key tagid
1885 $result = $result && add_key($table, $key);
1887 /// Changing sign of field itemid on table tag_instance to unsigned
1888 $table = new XMLDBTable('tag_instance');
1889 $field = new XMLDBField('itemid');
1890 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null, 'itemtype');
1892 /// Launch change of sign for field itemid
1893 $result = $result && change_field_unsigned($table, $field);
1895 /// Changing sign of field ordering on table tag_instance to unsigned
1896 $table = new XMLDBTable('tag_instance');
1897 $field = new XMLDBField('ordering');
1898 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null, 'itemid');
1900 /// Launch change of sign for field ordering
1901 $result = $result && change_field_unsigned($table, $field);
1903 /// Define index itemtype-itemid-tagid (unique) to be added to tag_instance
1904 $table = new XMLDBTable('tag_instance');
1905 $index = new XMLDBIndex('itemtype-itemid-tagid');
1906 $index->setAttributes(XMLDB_INDEX_UNIQUE
, array('itemtype', 'itemid', 'tagid'));
1908 /// Launch add index itemtype-itemid-tagid
1909 $result = $result && add_index($table, $index);
1911 /// Define index tagid (unique) to be dropped form tag_correlation
1912 $table = new XMLDBTable('tag_correlation');
1913 $index = new XMLDBIndex('tagid');
1914 $index->setAttributes(XMLDB_INDEX_UNIQUE
, array('tagid'));
1916 /// Launch drop index tagid
1917 $result = $result && drop_index($table, $index);
1919 /// Changing type of field tagid on table tag_correlation to int
1920 $table = new XMLDBTable('tag_correlation');
1921 $field = new XMLDBField('tagid');
1922 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null, 'id');
1924 /// Launch change of type for field tagid
1925 $result = $result && change_field_type($table, $field);
1928 /// Define key tagid (foreign) to be added to tag_correlation
1929 $table = new XMLDBTable('tag_correlation');
1930 $key = new XMLDBKey('tagid');
1931 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('tagid'), 'tag', array('id'));
1933 /// Launch add key tagid
1934 $result = $result && add_key($table, $key);
1936 upgrade_main_savepoint($result, 2007082800);
1940 if ($result && $oldversion < 2007082801) {
1942 /// Define table user_private_key to be created
1943 $table = new XMLDBTable('user_private_key');
1945 /// Adding fields to table user_private_key
1946 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1947 $table->addFieldInfo('script', XMLDB_TYPE_CHAR
, '128', null, XMLDB_NOTNULL
, null, null, null, null);
1948 $table->addFieldInfo('value', XMLDB_TYPE_CHAR
, '128', null, XMLDB_NOTNULL
, null, null, null, null);
1949 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1950 $table->addFieldInfo('instance', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1951 $table->addFieldInfo('iprestriction', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1952 $table->addFieldInfo('validuntil', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1953 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1955 /// Adding keys to table user_private_key
1956 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1957 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
1959 /// Adding indexes to table user_private_key
1960 $table->addIndexInfo('script-value', XMLDB_INDEX_NOTUNIQUE
, array('script', 'value'));
1962 /// Launch create table for user_private_key
1963 $result = $result && create_table($table);
1965 upgrade_main_savepoint($result, 2007082801);
1968 /// Going to modify the applicationid from int(1) to int(10). Dropping and
1969 /// re-creating the associated keys/indexes is mandatory to be cross-db. MDL-11042
1970 if ($result && $oldversion < 2007082803) {
1972 /// Define key applicationid (foreign) to be dropped form mnet_host
1973 $table = new XMLDBTable('mnet_host');
1974 $key = new XMLDBKey('applicationid');
1975 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('applicationid'), 'mnet_application', array('id'));
1977 /// Launch drop key applicationid
1978 $result = $result && drop_key($table, $key);
1980 /// Changing type of field applicationid on table mnet_host to int
1981 $field = new XMLDBField('applicationid');
1982 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '1', 'last_log_id');
1984 /// Launch change of type for field applicationid
1985 $result = $result && change_field_type($table, $field);
1987 /// Define key applicationid (foreign) to be added to mnet_host
1988 $key = new XMLDBKey('applicationid');
1989 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('applicationid'), 'mnet_application', array('id'));
1991 /// Launch add key applicationid
1992 $result = $result && add_key($table, $key);
1994 upgrade_main_savepoint($result, 2007082803);
1997 if ($result && $oldversion < 2007090503) {
1998 /// Define field aggregatesubcats to be added to grade_categories
1999 $table = new XMLDBTable('grade_categories');
2000 $field = new XMLDBField('aggregatesubcats');
2001 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'aggregateoutcomes');
2003 if (!field_exists($table, $field)) {
2004 /// Launch add field aggregateonlygraded
2005 $result = $result && add_field($table, $field);
2008 /// Define field aggregateonlygraded to be added to grade_categories
2009 $table = new XMLDBTable('grade_categories');
2010 $field = new XMLDBField('aggregateonlygraded');
2011 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'droplow');
2013 if (!field_exists($table, $field)) {
2014 /// Launch add field aggregateonlygraded
2015 $result = $result && add_field($table, $field);
2018 /// Define field aggregatesubcats to be added to grade_categories_history
2019 $table = new XMLDBTable('grade_categories_history');
2020 $field = new XMLDBField('aggregatesubcats');
2021 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'aggregateoutcomes');
2023 if (!field_exists($table, $field)) {
2024 /// Launch add field aggregateonlygraded
2025 $result = $result && add_field($table, $field);
2028 /// Define field aggregateonlygraded to be added to grade_categories_history
2029 $table = new XMLDBTable('grade_categories_history');
2030 $field = new XMLDBField('aggregateonlygraded');
2031 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'droplow');
2033 if (!field_exists($table, $field)) {
2034 /// Launch add field aggregateonlygraded
2035 $result = $result && add_field($table, $field);
2038 /// upgrade path in grade_categrories table - now using slash on both ends
2039 $concat = sql_concat('path', "'/'");
2040 $sql = "UPDATE {$CFG->prefix}grade_categories SET path = $concat WHERE path NOT LIKE '/%/'";
2041 execute_sql($sql, true);
2043 /// convert old aggregation constants if needed
2044 /*for ($i=0; $i<=12; $i=$i+2) {
2046 $sql = "UPDATE {$CFG->prefix}grade_categories SET aggregation = $i, aggregateonlygraded = 1 WHERE aggregation = $j";
2047 execute_sql($sql, true);
2048 }*/ // not needed anymore - breaks upgrade now
2050 upgrade_main_savepoint($result, 2007090503);
2053 /// To have UNIQUE indexes over NULLable columns isn't cross-db at all
2054 /// so we create a non unique index and programatically enforce uniqueness
2055 if ($result && $oldversion < 2007090600) {
2057 /// Define index idnumber (unique) to be dropped form course_modules
2058 $table = new XMLDBTable('course_modules');
2059 $index = new XMLDBIndex('idnumber');
2060 $index->setAttributes(XMLDB_INDEX_UNIQUE
, array('idnumber'));
2062 /// Launch drop index idnumber
2063 $result = $result && drop_index($table, $index);
2065 /// Define index idnumber-course (not unique) to be added to course_modules
2066 $table = new XMLDBTable('course_modules');
2067 $index = new XMLDBIndex('idnumber-course');
2068 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('idnumber', 'course'));
2070 /// Launch add index idnumber-course
2071 $result = $result && add_index($table, $index);
2073 /// Define index idnumber-courseid (not unique) to be added to grade_items
2074 $table = new XMLDBTable('grade_items');
2075 $index = new XMLDBIndex('idnumber-courseid');
2076 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('idnumber', 'courseid'));
2078 /// Launch add index idnumber-courseid
2079 $result = $result && add_index($table, $index);
2081 upgrade_main_savepoint($result, 2007090600);
2084 /// Create the permanent context_temp table to be used by build_context_path()
2085 if ($result && $oldversion < 2007092001) {
2087 /// Define table context_temp to be created
2088 $table = new XMLDBTable('context_temp');
2090 /// Adding fields to table context_temp
2091 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
2092 $table->addFieldInfo('path', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
2093 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
2095 /// Adding keys to table context_temp
2096 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
2098 /// Launch create table for context_temp
2099 $result = $result && create_table($table);
2101 /// make sure category depths, parents and paths are ok, categories from 1.5 may not be properly initialized (MDL-12585)
2102 upgrade_fix_category_depths();
2104 /// Recalculate depths, paths and so on
2105 if (!empty($CFG->rolesactive
)) {
2107 // make sure all course, category and user contexts exist - we need it for grade letter upgrade, etc.
2108 create_contexts(CONTEXT_COURSE
, false, true);
2109 create_contexts(CONTEXT_USER
, false, true);
2110 // we need all contexts path/depths filled properly
2111 build_context_path(true, true);
2112 load_all_capabilities();
2115 // upgrade from 1.6 - build all contexts
2116 create_contexts(null, true, true);
2119 upgrade_main_savepoint($result, 2007092001);
2123 * Merging of grade_grades_text back into grade_grades
2125 if ($result && $oldversion < 2007092002) {
2127 /// Define field feedback to be added to grade_grades
2128 $table = new XMLDBTable('grade_grades');
2129 $field = new XMLDBField('feedback');
2130 $field->setAttributes(XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null, 'excluded');
2132 if (!field_exists($table, $field)) {
2133 /// Launch add field feedback
2134 $result = $result && add_field($table, $field);
2137 /// Define field feedbackformat to be added to grade_grades
2138 $table = new XMLDBTable('grade_grades');
2139 $field = new XMLDBField('feedbackformat');
2140 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'feedback');
2142 if (!field_exists($table, $field)) {
2143 /// Launch add field feedbackformat
2144 $result = $result && add_field($table, $field);
2147 /// Define field information to be added to grade_grades
2148 $table = new XMLDBTable('grade_grades');
2149 $field = new XMLDBField('information');
2150 $field->setAttributes(XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null, 'feedbackformat');
2152 if (!field_exists($table, $field)) {
2153 /// Launch add field information
2154 $result = $result && add_field($table, $field);
2157 /// Define field informationformat to be added to grade_grades
2158 $table = new XMLDBTable('grade_grades');
2159 $field = new XMLDBField('informationformat');
2160 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'information');
2162 if (!field_exists($table, $field)) {
2163 /// Launch add field informationformat
2164 $result = $result && add_field($table, $field);
2167 /// Define field feedback to be added to grade_grades_history
2168 $table = new XMLDBTable('grade_grades_history');
2169 $field = new XMLDBField('feedback');
2170 $field->setAttributes(XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null, 'excluded');
2172 if (!field_exists($table, $field)) {
2173 /// Launch add field feedback
2174 $result = $result && add_field($table, $field);
2177 /// Define field feedbackformat to be added to grade_grades_history
2178 $table = new XMLDBTable('grade_grades_history');
2179 $field = new XMLDBField('feedbackformat');
2180 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'feedback');
2182 if (!field_exists($table, $field)) {
2183 /// Launch add field feedbackformat
2184 $result = $result && add_field($table, $field);
2187 /// Define field information to be added to grade_grades_history
2188 $table = new XMLDBTable('grade_grades_history');
2189 $field = new XMLDBField('information');
2190 $field->setAttributes(XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null, 'feedbackformat');
2192 if (!field_exists($table, $field)) {
2193 /// Launch add field information
2194 $result = $result && add_field($table, $field);
2197 /// Define field informationformat to be added to grade_grades_history
2198 $table = new XMLDBTable('grade_grades_history');
2199 $field = new XMLDBField('informationformat');
2200 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'information');
2202 if (!field_exists($table, $field)) {
2203 /// Launch add field informationformat
2204 $result = $result && add_field($table, $field);
2207 $table = new XMLDBTable('grade_grades_text');
2208 if ($result and table_exists($table)) {
2209 //migrade existing data into grade_grades table - this is slow but works for all dbs,
2210 //it will be executed on development sites only
2211 $fields = array('feedback', 'information');
2212 foreach ($fields as $field) {
2213 $sql = "UPDATE {$CFG->prefix}grade_grades
2216 FROM {$CFG->prefix}grade_grades_text ggt
2217 WHERE ggt.gradeid = {$CFG->prefix}grade_grades.id)";
2218 $result = execute_sql($sql) && $result;
2220 $fields = array('feedbackformat', 'informationformat');
2221 foreach ($fields as $field) {
2222 $sql = "UPDATE {$CFG->prefix}grade_grades
2223 SET $field = COALESCE((
2225 FROM {$CFG->prefix}grade_grades_text ggt
2226 WHERE ggt.gradeid = {$CFG->prefix}grade_grades.id), 0)";
2227 $result = execute_sql($sql) && $result;
2231 $tables = array('grade_grades_text', 'grade_grades_text_history');
2233 foreach ($tables as $table) {
2234 $table = new XMLDBTable($table);
2235 if (table_exists($table)) {
2242 upgrade_main_savepoint($result, 2007092002);
2245 if ($result && $oldversion < 2007092803) {
2247 /// Remove obsoleted unit tests tables - they will be recreated automatically
2248 $tables = array('grade_categories',
2251 'grade_calculations',
2254 'grade_grades_final',
2255 'grade_grades_text',
2257 'grade_outcomes_courses');
2259 foreach ($tables as $tablename) {
2260 $table = new XMLDBTable('unittest_'.$tablename);
2261 if (table_exists($table)) {
2264 $table = new XMLDBTable('unittest_'.$tablename.'_history');
2265 if (table_exists($table)) {
2270 /// Define field display to be added to grade_items
2271 $table = new XMLDBTable('grade_items');
2272 $field = new XMLDBField('display');
2273 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0', 'sortorder');
2275 /// Launch add field display
2276 if (!field_exists($table, $field)) {
2277 $result = $result && add_field($table, $field);
2279 $result = $result && change_field_default($table, $field);
2282 /// Define field display to be added to grade_items_history
2283 $table = new XMLDBTable('grade_items_history');
2284 $field = new XMLDBField('display');
2285 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0', 'sortorder');
2287 /// Launch add field display
2288 if (!field_exists($table, $field)) {
2289 $result = $result && add_field($table, $field);
2293 /// Define field decimals to be added to grade_items
2294 $table = new XMLDBTable('grade_items');
2295 $field = new XMLDBField('decimals');
2296 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, null, null, null, null, null, 'display');
2298 /// Launch add field decimals
2299 if (!field_exists($table, $field)) {
2300 $result = $result && add_field($table, $field);
2302 $result = $result && change_field_default($table, $field);
2303 $result = $result && change_field_notnull($table, $field);
2306 /// Define field decimals to be added to grade_items_history
2307 $table = new XMLDBTable('grade_items_history');
2308 $field = new XMLDBField('decimals');
2309 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, null, null, null, null, null, 'display');
2311 /// Launch add field decimals
2312 if (!field_exists($table, $field)) {
2313 $result = $result && add_field($table, $field);
2317 /// fix incorrect -1 default for grade_item->display
2318 execute_sql("UPDATE {$CFG->prefix}grade_items SET display=0 WHERE display=-1");
2320 upgrade_main_savepoint($result, 2007092803);
2323 /// migrade grade letters - we can not do this in normal grades upgrade becuase we need all course contexts
2324 if ($result && $oldversion < 2007092806) {
2326 $result = upgrade_18_letters();
2328 /// Define index contextidlowerboundary (not unique) to be added to grade_letters
2329 $table = new XMLDBTable('grade_letters');
2330 $index = new XMLDBIndex('contextid-lowerboundary');
2331 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('contextid', 'lowerboundary'));
2333 /// Launch add index contextidlowerboundary
2334 if (!index_exists($table, $index)) {
2335 $result = $result && add_index($table, $index);
2338 upgrade_main_savepoint($result, 2007092806);
2341 if ($result && $oldversion < 2007100100) {
2343 /// Define table cache_flags to be created
2344 $table = new XMLDBTable('cache_flags');
2346 /// Adding fields to table cache_flags
2347 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
2348 $table->addFieldInfo('flagtype', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
2349 $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
2350 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
2351 $table->addFieldInfo('value', XMLDB_TYPE_TEXT
, 'medium', null, XMLDB_NOTNULL
, null, null, null, null);
2352 $table->addFieldInfo('expiry', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
2354 /// Adding keys to table cache_flags
2355 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
2358 * Note: mysql can not create indexes on text fields larger than 333 chars!
2361 /// Adding indexes to table cache_flags
2362 $table->addIndexInfo('flagtype', XMLDB_INDEX_NOTUNIQUE
, array('flagtype'));
2363 $table->addIndexInfo('name', XMLDB_INDEX_NOTUNIQUE
, array('name'));
2365 /// Launch create table for cache_flags
2366 if (!table_exists($table)) {
2367 $result = $result && create_table($table);
2370 upgrade_main_savepoint($result, 2007100100);
2374 if ($result && $oldversion < 2007100300) {
2375 /// MNET stuff for roaming theme
2376 /// Define field force_theme to be added to mnet_host
2377 $table = new XMLDBTable('mnet_host');
2378 $field = new XMLDBField('force_theme');
2379 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'last_log_id');
2381 /// Launch add field force_theme
2382 $result = $result && add_field($table, $field);
2384 /// Define field theme to be added to mnet_host
2385 $table = new XMLDBTable('mnet_host');
2386 $field = new XMLDBField('theme');
2387 $field->setAttributes(XMLDB_TYPE_CHAR
, '100', null, null, null, null, null, null, 'force_theme');
2389 /// Launch add field theme
2390 $result = $result && add_field($table, $field);
2392 upgrade_main_savepoint($result, 2007100300);
2395 if ($result && $oldversion < 2007100301) {
2397 /// Define table cache_flags to be created
2398 $table = new XMLDBTable('cache_flags');
2399 $index = new XMLDBIndex('typename');
2400 if (index_exists($table, $index)) {
2401 $result = $result && drop_index($table, $index);
2404 $table = new XMLDBTable('cache_flags');
2405 $index = new XMLDBIndex('flagtype');
2406 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('flagtype'));
2407 if (!index_exists($table, $index)) {
2408 $result = $result && add_index($table, $index);
2411 $table = new XMLDBTable('cache_flags');
2412 $index = new XMLDBIndex('name');
2413 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('name'));
2414 if (!index_exists($table, $index)) {
2415 $result = $result && add_index($table, $index);
2418 upgrade_main_savepoint($result, 2007100301);
2421 if ($result && $oldversion < 2007100303) {
2423 /// Changing nullability of field summary on table course to null
2424 $table = new XMLDBTable('course');
2425 $field = new XMLDBField('summary');
2426 $field->setAttributes(XMLDB_TYPE_TEXT
, 'small', null, null, null, null, null, null, 'idnumber');
2428 /// Launch change of nullability for field summary
2429 $result = $result && change_field_notnull($table, $field);
2431 upgrade_main_savepoint($result, 2007100303);
2434 if ($result && $oldversion < 2007100500) {
2435 /// for dev sites - it is ok to do this repeatedly
2437 /// Changing nullability of field path on table context to null
2438 $table = new XMLDBTable('context');
2439 $field = new XMLDBField('path');
2440 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null, 'instanceid');
2442 /// Launch change of nullability for field path
2443 $result = $result && change_field_notnull($table, $field);
2445 upgrade_main_savepoint($result, 2007100500);
2448 if ($result && $oldversion < 2007100700) {
2450 /// first drop existing tables - we do not need any data from there
2451 $table = new XMLDBTable('grade_import_values');
2452 if (table_exists($table)) {
2456 $table = new XMLDBTable('grade_import_newitem');
2457 if (table_exists($table)) {
2461 /// Define table grade_import_newitem to be created
2462 $table = new XMLDBTable('grade_import_newitem');
2464 /// Adding fields to table grade_import_newitem
2465 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
2466 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
2467 $table->addFieldInfo('importcode', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
2468 $table->addFieldInfo('importer', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
2470 /// Adding keys to table grade_import_newitem
2471 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
2472 $table->addKeyInfo('importer', XMLDB_KEY_FOREIGN
, array('importer'), 'user', array('id'));
2474 /// Launch create table for grade_import_newitem
2475 $result = $result && create_table($table);
2478 /// Define table grade_import_values to be created
2479 $table = new XMLDBTable('grade_import_values');
2481 /// Adding fields to table grade_import_values
2482 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
2483 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
2484 $table->addFieldInfo('newgradeitem', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
2485 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
2486 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
2487 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
2488 $table->addFieldInfo('importcode', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
2489 $table->addFieldInfo('importer', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
2491 /// Adding keys to table grade_import_values
2492 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
2493 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN
, array('itemid'), 'grade_items', array('id'));
2494 $table->addKeyInfo('newgradeitem', XMLDB_KEY_FOREIGN
, array('newgradeitem'), 'grade_import_newitem', array('id'));
2495 $table->addKeyInfo('importer', XMLDB_KEY_FOREIGN
, array('importer'), 'user', array('id'));
2497 /// Launch create table for grade_import_values
2498 $result = $result && create_table($table);
2500 upgrade_main_savepoint($result, 2007100700);
2503 /// dropping context_rel table - not used anymore
2504 if ($result && $oldversion < 2007100800) {
2506 /// Define table context_rel to be dropped
2507 $table = new XMLDBTable('context_rel');
2509 /// Launch drop table for context_rel
2510 if (table_exists($table)) {
2514 upgrade_main_savepoint($result, 2007100800);
2517 /// Truncate the text_cahe table and add new index
2518 if ($result && $oldversion < 2007100802) {
2520 /// Truncate the cache_text table
2521 execute_sql("TRUNCATE TABLE {$CFG->prefix}cache_text", true);
2523 /// Define index timemodified (not unique) to be added to cache_text
2524 $table = new XMLDBTable('cache_text');
2525 $index = new XMLDBIndex('timemodified');
2526 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('timemodified'));
2528 /// Launch add index timemodified
2529 $result = $result && add_index($table, $index);
2531 upgrade_main_savepoint($result, 2007100802);
2534 /// newtable for gradebook settings per course
2535 if ($result && $oldversion < 2007100803) {
2537 /// Define table grade_settings to be created
2538 $table = new XMLDBTable('grade_settings');
2540 /// Adding fields to table grade_settings
2541 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
2542 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
2543 $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
2544 $table->addFieldInfo('value', XMLDB_TYPE_TEXT
, 'small', null, null, null, null, null, null);
2546 /// Adding keys to table grade_settings
2547 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
2548 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
2550 /// Adding indexes to table grade_settings
2551 $table->addIndexInfo('courseid-name', XMLDB_INDEX_UNIQUE
, array('courseid', 'name'));
2553 /// Launch create table for grade_settings
2554 $result = $result && create_table($table);
2556 upgrade_main_savepoint($result, 2007100803);
2559 /// cleanup in user_lastaccess
2560 if ($result && $oldversion < 2007100902) {
2562 FROM {$CFG->prefix}user_lastaccess
2563 WHERE NOT EXISTS (SELECT 'x'
2564 FROM {$CFG->prefix}course c
2565 WHERE c.id = {$CFG->prefix}user_lastaccess.courseid)";
2568 upgrade_main_savepoint($result, 2007100902);
2571 /// drop old gradebook tables
2572 if ($result && $oldversion < 2007100903) {
2573 $tables = array('grade_category',
2576 'grade_preferences',
2577 'grade_exceptions');
2579 foreach ($tables as $table) {
2580 $table = new XMLDBTable($table);
2581 if (table_exists($table)) {
2586 upgrade_main_savepoint($result, 2007100903);
2589 if ($result && $oldversion < 2007101500 && !file_exists($CFG->dataroot
. '/user')) {
2590 // Get list of users by browsing moodledata/user
2591 $oldusersdir = $CFG->dataroot
. '/users';
2592 $folders = get_directory_list($oldusersdir, '', false, true, false);
2594 foreach ($folders as $userid) {
2595 $olddir = $oldusersdir . '/' . $userid;
2596 $files = get_directory_list($olddir);
2598 if (empty($files)) {
2602 // Create new user directory
2603 if (!$newdir = make_user_directory($userid)) {
2604 // some weird directory - do not stop the upgrade, just ignore it
2608 // Move contents of old directory to new one
2609 if (file_exists($olddir) && file_exists($newdir)) {
2610 foreach ($files as $file) {
2611 copy($olddir . '/' . $file, $newdir . '/' . $file);
2614 notify("Could not move the contents of $olddir into $newdir!");
2620 // Leave a README in old users directory
2621 $readmefilename = $oldusersdir . '/README.txt';
2622 if ($handle = fopen($readmefilename, 'w+b')) {
2623 if (!fwrite($handle, get_string('olduserdirectory'))) {
2624 // Could not write to the readme file. No cause for huge concern
2625 notify("Could not write to the README.txt file in $readmefilename.");
2629 // Could not create the readme file. No cause for huge concern
2630 notify("Could not create the README.txt file in $readmefilename.");
2634 if ($result && $oldversion < 2007101502) {
2636 /// try to remove duplicate entries
2638 $SQL = "SELECT userid, itemid, COUNT(*)
2639 FROM {$CFG->prefix}grade_grades
2640 GROUP BY userid, itemid
2641 HAVING COUNT( * ) >1";
2644 if ($rs = get_recordset_sql($SQL)) {
2645 if ($rs && $rs->RecordCount() > 0) {
2646 while ($dup = rs_fetch_next_record($rs)) {
2647 if ($thisdups = get_records_sql("SELECT id FROM {$CFG->prefix}grade_grades
2648 WHERE itemid = $dup->itemid AND userid = $dup->userid
2649 ORDER BY timemodified DESC")) {
2651 $processed = 0; // keep the first one
2652 foreach ($thisdups as $thisdup) {
2654 // remove the duplicates
2655 delete_records('grade_grades', 'id', $thisdup->id
);
2665 /// Define key userid-itemid (unique) to be added to grade_grades
2666 $table = new XMLDBTable('grade_grades');
2667 $key = new XMLDBKey('userid-itemid');
2668 $key->setAttributes(XMLDB_KEY_UNIQUE
, array('userid', 'itemid'));
2670 /// Launch add key userid-itemid
2671 $result = $result && add_key($table, $key);
2673 /// Main savepoint reached
2674 upgrade_main_savepoint($result, 2007101502);
2677 if ($result && $oldversion < 2007101505) {
2679 /// Changing precision of field dst_time on table timezone to (6)
2680 $table = new XMLDBTable('timezone');
2681 $field = new XMLDBField('dst_time');
2682 $field->setAttributes(XMLDB_TYPE_CHAR
, '6', null, XMLDB_NOTNULL
, null, null, null, '00:00', 'dst_skipweeks');
2684 /// Launch change of precision for field dst_time
2685 $result = $result && change_field_precision($table, $field);
2687 /// Changing precision of field std_time on table timezone to (6)
2688 $table = new XMLDBTable('timezone');
2689 $field = new XMLDBField('std_time');
2690 $field->setAttributes(XMLDB_TYPE_CHAR
, '6', null, XMLDB_NOTNULL
, null, null, null, '00:00', 'std_skipweeks');
2692 /// Launch change of precision for field std_time
2693 $result = $result && change_field_precision($table, $field);
2695 /// Main savepoint reached
2696 upgrade_main_savepoint($result, 2007101505);
2699 if ($result && $oldversion < 2007101506) {
2701 /// CONTEXT_PERSONAL was never implemented - removing
2703 FROM {$CFG->prefix}context
2704 WHERE contextlevel=20";
2708 /// Main savepoint reached
2709 upgrade_main_savepoint($result, 2007101506);
2712 if ($result && $oldversion < 2007101507) {
2714 require_once($CFG->dirroot
.'/course/lib.php');
2715 notify('Started rebuilding of course cache...', 'notifysuccess');
2716 rebuild_course_cache(); // Rebuild course cache - new group related fields there
2717 notify('...finished rebuilding of course cache.', 'notifysuccess');
2719 /// Main savepoint reached
2720 upgrade_main_savepoint($result, 2007101507);
2723 if ($result && $oldversion < 2007101508) {
2725 notify('Updating country list according to recent official ISO listing...', 'notifysuccess');
2726 // re-assign users to valid countries
2727 set_field('user', 'country', 'CD', 'country', 'ZR'); // Zaire is now Congo Democratique
2728 set_field('user', 'country', 'TL', 'country', 'TP'); // Timor has changed
2729 set_field('user', 'country', 'FR', 'country', 'FX'); // France metropolitaine doesn't exist
2730 set_field('user', 'country', 'RS', 'country', 'KO'); // Kosovo is part of Serbia, "under the auspices of the United Nations, pursuant to UN Security Council Resolution 1244 of 10 June 1999."
2731 set_field('user', 'country', 'GB', 'country', 'WA'); // Wales is part of UK (ie Great Britain)
2732 set_field('user', 'country', 'RS', 'country', 'CS'); // Re-assign Serbia-Montenegro to Serbia. This is arbitrary, but there is no way to make an automatic decision on this.
2733 notify('...update complete. Remember to update the language pack to get the most recent country names defitions and codes. This is specialy important for sites with users from Congo (now CD), Timor (now TL), Kosovo (now RS), Wales (now GB), Serbia (RS) and Montenegro (ME). Users based in Montenegro (ME) will need to manually update their profile.', 'notifysuccess');
2735 upgrade_main_savepoint($result, 2007101508);
2738 if ($result && $oldversion < 2007101508.01) {
2739 // add forgotten table
2740 /// Define table scale_history to be created
2741 $table = new XMLDBTable('scale_history');
2743 /// Adding fields to table scale_history
2744 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
2745 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
2746 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
2747 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
2748 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
2749 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
2750 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
2751 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
2752 $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
2753 $table->addFieldInfo('scale', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
2754 $table->addFieldInfo('description', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
2756 /// Adding keys to table scale_history
2757 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
2758 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'scale', array('id'));
2759 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
2760 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN
, array('loggeduser'), 'user', array('id'));
2762 /// Adding indexes to table scale_history
2763 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
2765 if ($result and !table_exists($table)) {
2766 /// Launch create table for scale_history
2767 $result = $result && create_table($table);
2770 /// Main savepoint reached
2771 upgrade_main_savepoint($result, 2007101508.01);
2775 if ($result && $oldversion < 2007101508.02) {
2776 // upgade totals, no big deal if it fails
2777 require_once($CFG->libdir
.'/statslib.php');
2778 stats_upgrade_totals();
2780 if (isset($CFG->loglifetime
) and $CFG->loglifetime
== 30) {
2781 set_config('loglifetime', 35); // we need more than 31 days for monthly stats!
2784 notify('Upgrading log table indexes, this may take a long time, please be patient.', 'notifysuccess');
2786 /// Define index time-course-module-action (not unique) to be dropped form log
2787 $table = new XMLDBTable('log');
2788 $index = new XMLDBIndex('time-course-module-action');
2789 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('time', 'course', 'module', 'action'));
2791 /// Launch drop index time-course-module-action
2792 if (index_exists($table, $index)) {
2793 $result = drop_index($table, $index) && $result;
2796 /// Define index userid (not unique) to be dropped form log
2797 $table = new XMLDBTable('log');
2798 $index = new XMLDBIndex('userid');
2799 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('userid'));
2801 /// Launch drop index userid
2802 if (index_exists($table, $index)) {
2803 $result = drop_index($table, $index) && $result;
2806 /// Define index info (not unique) to be dropped form log
2807 $table = new XMLDBTable('log');
2808 $index = new XMLDBIndex('info');
2809 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('info'));
2811 /// Launch drop index info
2812 if (index_exists($table, $index)) {
2813 $result = drop_index($table, $index) && $result;
2816 /// Define index time (not unique) to be added to log
2817 $table = new XMLDBTable('log');
2818 $index = new XMLDBIndex('time');
2819 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('time'));
2821 /// Launch add index time
2822 if (!index_exists($table, $index)) {
2823 $result = add_index($table, $index) && $result;
2826 /// Define index action (not unique) to be added to log
2827 $table = new XMLDBTable('log');
2828 $index = new XMLDBIndex('action');
2829 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('action'));
2831 /// Launch add index action
2832 if (!index_exists($table, $index)) {
2833 $result = add_index($table, $index) && $result;
2836 /// Main savepoint reached
2837 upgrade_main_savepoint($result, 2007101508.02);
2840 if ($result && $oldversion < 2007101508.03) {
2842 /// Define index course-userid (not unique) to be dropped form log
2843 $table = new XMLDBTable('log');
2844 $index = new XMLDBIndex('course-userid');
2845 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('course', 'userid'));
2847 /// Launch drop index course-userid
2848 if (index_exists($table, $index)) {
2849 $result = $result && drop_index($table, $index);
2852 /// Define index userid-course (not unique) to be added to log
2853 $table = new XMLDBTable('log');
2854 $index = new XMLDBIndex('userid-course');
2855 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('userid', 'course'));
2857 /// Launch add index userid-course
2858 if (!index_exists($table, $index)) {
2859 $result = $result && add_index($table, $index);
2862 /// Main savepoint reached
2863 upgrade_main_savepoint($result, 2007101508.03);
2866 if ($result && $oldversion < 2007101508.04) {
2867 set_field('tag_instance', 'itemtype', 'post', 'itemtype', 'blog');
2868 upgrade_main_savepoint($result, 2007101508.04);
2871 if ($result && $oldversion < 2007101508.05) {
2873 /// Define index cmid (not unique) to be added to log
2874 $table = new XMLDBTable('log');
2875 $index = new XMLDBIndex('cmid');
2876 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('cmid'));
2878 /// Launch add index cmid
2879 if (!index_exists($table, $index)) {
2880 $result = $result && add_index($table, $index);
2883 /// Main savepoint reached
2884 upgrade_main_savepoint($result, 2007101508.05);
2887 if ($result && $oldversion < 2007101508.06) {
2889 /// Define index groupid-courseid-visible-userid (not unique) to be added to event
2890 $table = new XMLDBTable('event');
2891 $index = new XMLDBIndex('groupid-courseid-visible-userid');
2892 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('groupid', 'courseid', 'visible', 'userid'));
2894 /// Launch add index groupid-courseid-visible-userid
2895 if (!index_exists($table, $index)) {
2896 $result = $result && add_index($table, $index);
2899 /// Main savepoint reached
2900 upgrade_main_savepoint($result, 2007101508.06);
2903 if ($result && $oldversion < 2007101508.07) {
2905 /// Define table webdav_locks to be created
2906 $table = new XMLDBTable('webdav_locks');
2908 /// Adding fields to table webdav_locks
2909 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
2910 $table->addFieldInfo('token', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
2911 $table->addFieldInfo('path', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
2912 $table->addFieldInfo('expiry', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
2913 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
2914 $table->addFieldInfo('recursive', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
2915 $table->addFieldInfo('exclusivelock', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
2916 $table->addFieldInfo('created', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
2917 $table->addFieldInfo('modified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
2918 $table->addFieldInfo('owner', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
2920 /// Adding keys to table webdav_locks
2921 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
2922 $table->addKeyInfo('token', XMLDB_KEY_UNIQUE
, array('token'));
2924 /// Adding indexes to table webdav_locks
2925 $table->addIndexInfo('path', XMLDB_INDEX_NOTUNIQUE
, array('path'));
2926 $table->addIndexInfo('expiry', XMLDB_INDEX_NOTUNIQUE
, array('expiry'));
2928 /// Launch create table for webdav_locks
2929 $result = $result && create_table($table);
2931 /// Main savepoint reached
2932 upgrade_main_savepoint($result, 2007101508.07);
2935 if ($result && $oldversion < 2007101508.08) { // MDL-13676
2937 /// Define field name to be added to role_names
2938 $table = new XMLDBTable('role_names');
2939 $field = new XMLDBField('name');
2940 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null, 'text');
2942 /// Launch add field name
2943 $result = $result && add_field($table, $field);
2945 /// Copy data from old field to new field
2946 $result = $result && execute_sql('UPDATE '.$CFG->prefix
.'role_names SET name = text');
2948 /// Define field text to be dropped from role_names
2949 $table = new XMLDBTable('role_names');
2950 $field = new XMLDBField('text');
2952 /// Launch drop field text
2953 $result = $result && drop_field($table, $field);
2955 /// Main savepoint reached
2956 upgrade_main_savepoint($result, 2007101508.08);
2959 if ($result && $oldversion < 2007101509) {
2960 // force full regrading
2961 set_field('grade_items', 'needsupdate', 1, 'needsupdate', 0);
2964 if ($result && $oldversion < 2007101510) {
2965 /// Fix minor problem caused by MDL-5482.
2966 require_once($CFG->dirroot
. '/question/upgrade.php');
2967 $result = $result && question_fix_random_question_parents();
2968 upgrade_main_savepoint($result, 2007101510);
2971 if ($result && $oldversion < 2007101511) {
2972 // if guest role used as default user role unset it and force admin to choose new setting
2973 if (!empty($CFG->defaultuserroleid
)) {
2974 if ($role = get_record('role', 'id', $CFG->defaultuserroleid
)) {
2975 if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW
)) {
2976 if (isset($guestroles[$role->id
])) {
2977 set_config('defaultuserroleid', null);
2978 notify('Guest role removed from "Default role for all users" setting, please select another role.', 'notifysuccess');
2982 set_config('defaultuserroleid', null);
2987 if ($result && $oldversion < 2007101512) {
2988 notify('Increasing size of user idnumber field, this may take a while...', 'notifysuccess');
2990 /// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859
2991 if ($CFG->dbfamily
== 'mysql' ||
$CFG->dbfamily
== 'postgres') {
2992 execute_sql("UPDATE {$CFG->prefix}user SET idnumber = '' WHERE idnumber IS NULL", true);
2995 /// Define index idnumber (not unique) to be dropped form user
2996 $table = new XMLDBTable('user');
2997 $index = new XMLDBIndex('idnumber');
2998 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('idnumber'));
3000 /// Launch drop index idnumber
3001 if (index_exists($table, $index)) {
3002 $result = $result && drop_index($table, $index);
3005 /// Changing precision of field idnumber on table user to (255)
3006 $table = new XMLDBTable('user');
3007 $field = new XMLDBField('idnumber');
3008 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null, 'password');
3010 /// Launch change of precision for field idnumber
3011 $result = $result && change_field_precision($table, $field);
3013 /// Launch add index idnumber again
3014 $index = new XMLDBIndex('idnumber');
3015 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('idnumber'));
3016 $result = $result && add_index($table, $index);
3018 /// Main savepoint reached
3019 upgrade_main_savepoint($result, 2007101512);
3022 if ($result && $oldversion < 2007101513) {
3023 $log_action = new stdClass();
3024 $log_action->module
= 'course';
3025 $log_action->action
= 'unenrol';
3026 $log_action->mtable
= 'course';
3027 $log_action->field
= 'fullname';
3028 if (!record_exists("log_display", "action", "unenrol",
3029 "module", "course")){
3030 $result = $result && insert_record('log_display', $log_action);
3032 upgrade_main_savepoint($result, 2007101513);
3035 if ($result && $oldversion < 2007101514) {
3036 $table = new XMLDBTable('mnet_enrol_course');
3037 $field = new XMLDBField('sortorder');
3038 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', true, true, null, false, false, 0);
3039 $result = change_field_precision($table, $field);
3040 upgrade_main_savepoint($result, 2007101514);
3043 if ($result && $oldversion < 2007101515) {
3044 $result = delete_records_select('role_names', sql_isempty('role_names', 'name', false, false));
3045 upgrade_main_savepoint($result, 2007101515);
3048 if ($result && $oldversion < 2007101517) {
3049 if (isset($CFG->defaultuserroleid
) and isset($CFG->guestroleid
) and $CFG->defaultuserroleid
== $CFG->guestroleid
) {
3050 // guest can not be selected in defaultuserroleid!
3051 unset_config('defaultuserroleid');
3053 upgrade_main_savepoint($result, 2007101517);
3056 if ($result && $oldversion < 2007101526) {
3058 /// Changing the default of field lang on table user to en_utf8
3059 $table = new XMLDBTable('user');
3060 $field = new XMLDBField('lang');
3061 $field->setAttributes(XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, 'en_utf8', 'country');
3063 /// Launch change of default for field lang
3064 $result = $result && change_field_default($table, $field);
3066 /// Main savepoint reached
3067 upgrade_main_savepoint($result, 2007101526);
3070 if ($result && $oldversion < 2007101527) {
3071 if (!get_config(NULL, 'statsruntimedays')) {
3072 set_config('statsruntimedays', '31');
3076 /// For MDL-17501. Ensure that any role that has moodle/course:update also
3077 /// has moodle/course:visibility.
3078 if ($result && $oldversion < 2007101532.10) {
3079 if (!empty($CFG->rolesactive
)) { // In case we are upgrading from Moodle 1.6.
3080 /// Get the roles with 'moodle/course:update'.
3081 $systemcontext = get_context_instance(CONTEXT_SYSTEM
);
3082 $roles = get_roles_with_capability('moodle/course:update', CAP_ALLOW
, $systemcontext);
3084 /// Give those roles 'moodle/course:visibility'.
3085 foreach ($roles as $role) {
3086 assign_capability('moodle/course:visibility', CAP_ALLOW
, $role->id
, $systemcontext->id
);
3089 /// Force all sessions to refresh access data.
3090 mark_context_dirty($systemcontext->path
);
3093 /// Main savepoint reached
3094 upgrade_main_savepoint($result, 2007101532.10);
3097 if ($result && $oldversion < 2007101542) {
3098 if (empty($CFG->hiddenuserfields
)) {
3099 set_config('hiddenuserfields','firstaccess');
3101 if (strpos($CFG->hiddenuserfields
, 'firstaccess') === false) { //firstaccess should not already be listed but just in case
3102 set_config('hiddenuserfields',$CFG->hiddenuserfields
.',firstaccess');
3105 /// Main savepoint reached
3106 upgrade_main_savepoint($result, 2007101542);
3109 if ($result && $oldversion < 2007101545.01) {
3110 require_once("$CFG->dirroot/filter/tex/lib.php");
3111 filter_tex_updatedcallback(null);
3112 /// Main savepoint reached
3113 upgrade_main_savepoint($result, 2007101545.01);
3116 if ($result && $oldversion < 2007101546.02) {
3117 if (empty($CFG->gradebook_latest195_upgrade
)) {
3118 require_once($CFG->libdir
.'/gradelib.php'); // we need constants only
3119 // reset current coef for simple mean items - it may contain some rubbish ;-)
3120 $sql = "UPDATE {$CFG->prefix}grade_items
3121 SET aggregationcoef = 0
3122 WHERE categoryid IN (SELECT gc.id
3123 FROM {$CFG->prefix}grade_categories gc
3124 WHERE gc.aggregation = ".GRADE_AGGREGATE_WEIGHTED_MEAN2
.")";
3125 $result = execute_sql($sql);
3127 // direct upgrade from 1.8.x - no need to reset coef, because it is already ok
3128 unset_config('gradebook_latest195_upgrade');
3131 upgrade_main_savepoint($result, 2007101546.02);
3134 if ($result && $oldversion < 2007101546.03) {
3135 /// Deleting orphaned messages from deleted users.
3136 require_once($CFG->dirroot
.'/message/lib.php');
3137 /// Detect deleted users with messages sent(useridfrom) and not read
3138 if ($deletedusers = get_records_sql("SELECT DISTINCT u.id
3139 FROM {$CFG->prefix}user u
3140 JOIN {$CFG->prefix}message m ON m.useridfrom = u.id
3141 WHERE u.deleted = 1")) {
3142 foreach ($deletedusers as $deleteduser) {
3143 message_move_userfrom_unread2read($deleteduser->id
); // move messages
3146 /// Main savepoint reached
3147 upgrade_main_savepoint($result, 2007101546.03);
3150 if ($result && $oldversion < 2007101546.05) {
3151 // force full regrading - the max grade for sum aggregation was not correct when scales involved,
3152 // extra credit grade is not dropped anymore in aggregations if drop low or keep high specified
3153 // sum aggragetion respects drop low and keep high when calculation max value
3154 set_field('grade_items', 'needsupdate', 1, 'needsupdate', 0);
3157 if ($result && $oldversion < 2007101546.06) {
3158 unset_config('grade_report_showgroups');
3159 upgrade_main_savepoint($result, 2007101546.06);
3162 if ($result && $oldversion < 2007101547) {
3163 // Let's check the status of mandatory mnet_host records, fixing them
3164 // and moving "orphan" users to default localhost record. MDL-16879
3165 notify('Fixing mnet records, this may take a while...', 'notifysuccess');
3166 $db->debug
= false; // Can output too much. Disabling
3167 upgrade_fix_incorrect_mnethostids();
3168 $db->debug
= true; // Restoring debug level
3169 upgrade_main_savepoint($result, 2007101547);
3172 if ($result && $oldversion < 2007101551){
3173 //insert new record for log_display table
3174 //used to record tag update.
3175 if (!record_exists("log_display", "action", "update",
3177 $log_action = new stdClass();
3178 $log_action->module
= 'tag';
3179 $log_action->action
= 'update';
3180 $log_action->mtable
= 'tag';
3181 $log_action->field
= 'name';
3183 $result = $result && insert_record('log_display', $log_action);
3185 upgrade_main_savepoint($result, 2007101551);
3188 if ($result && $oldversion < 2007101561.01) {
3189 // As part of security changes password policy will now be enabled by default.
3190 // If it has not already been enabled then we will enable it... Admins will still
3191 // be able to switch it off after this upgrade
3192 if (record_exists('config', 'name', 'passwordpolicy', 'value', 0)) {
3193 unset_config('passwordpolicy');
3196 $message = get_string('upgrade197notice', 'admin');
3197 if (empty($CFG->passwordmainsalt
)) {
3198 $docspath = $CFG->docroot
.'/'.str_replace('_utf8', '', current_language()).'/report/security/report_security_check_passwordsaltmain';
3199 $message .= "\n".get_string('upgrade197salt', 'admin', $docspath);
3201 notify($message, 'notifysuccess');
3205 upgrade_main_savepoint($result, 2007101561.01);
3208 if ($result && $oldversion < 2007101561.02) {
3209 $messagesubject = get_string('upgrade197noticesubject', 'admin');
3210 $message = addslashes(get_string('upgrade197notice', 'admin'));
3211 if (empty($CFG->passwordmainsalt
)) {
3212 $docspath = $CFG->docroot
.'/'.str_replace('_utf8', '', current_language()).'/report/security/report_security_check_passwordsaltmain';
3213 $message .= "\n".get_string('upgrade197salt', 'admin', $docspath);
3216 // Force administrators to change password on next login
3217 $systemcontext = get_context_instance(CONTEXT_SYSTEM
);
3218 $sql = "SELECT DISTINCT u.id, u.firstname, u.lastname, u.picture, u.imagealt, u.email, u.password
3219 FROM {$CFG->prefix}role_capabilities rc
3220 JOIN {$CFG->prefix}role_assignments ra ON (ra.contextid = rc.contextid AND ra.roleid = rc.roleid)
3221 JOIN {$CFG->prefix}user u ON u.id = ra.userid
3222 WHERE rc.capability = 'moodle/site:doanything'
3223 AND rc.permission = ".CAP_ALLOW
."
3225 AND rc.contextid = ".$systemcontext->id
." AND (u.auth='manual' OR u.auth='email')";
3227 $adminusers = get_records_sql($sql);
3228 foreach ($adminusers as $adminuser) {
3229 if ($preference = get_record('user_preferences', 'userid', $adminuser->id
, 'name', 'auth_forcepasswordchange')) {
3230 if ($preference->value
== '1') {
3233 set_field('user_preferences', 'value', '1', 'id', $preference->id
);
3235 $preference = new stdClass
;
3236 $preference->userid
= $adminuser->id
;
3237 $preference->name
= 'auth_forcepasswordchange';
3238 $preference->value
= '1';
3239 insert_record('user_preferences', $preference);
3241 $adminuser->maildisplay
= 0; // do not use return email to self, it might actually help emails to get through and prevents notices
3242 // Message them with the notice about upgrading
3243 email_to_user($adminuser, $adminuser, $messagesubject, html_to_text($message), $message);
3249 unset($messagesubject);
3251 upgrade_main_savepoint($result, 2007101561.02);
3254 if ($result && $oldversion < 2007101563.02) {
3255 // this block tries to undo incorrect forcing of new passwords for admins that have no
3256 // way to change passwords MDL-20933
3257 $systemcontext = get_context_instance(CONTEXT_SYSTEM
);
3258 $sql = "SELECT DISTINCT u.id, u.firstname, u.lastname, u.picture, u.imagealt, u.email, u.password
3259 FROM {$CFG->prefix}role_capabilities rc
3260 JOIN {$CFG->prefix}role_assignments ra ON (ra.contextid = rc.contextid AND ra.roleid = rc.roleid)
3261 JOIN {$CFG->prefix}user u ON u.id = ra.userid
3262 WHERE rc.capability = 'moodle/site:doanything'
3263 AND rc.permission = ".CAP_ALLOW
."
3265 AND rc.contextid = ".$systemcontext->id
." AND u.auth<>'manual' AND u.auth<>'email'";
3267 if ($adminusers = get_records_sql($sql)) {
3268 foreach ($adminusers as $adminuser) {
3269 delete_records('user_preferences', 'userid', $adminuser->id
, 'name', 'auth_forcepasswordchange');
3274 upgrade_main_savepoint($result, 2007101563.02);
3277 if ($result && $oldversion < 2007101563.03) {
3278 // NOTE: this is quite hacky, but anyway it should work fine in 1.9,
3279 // in 2.0 we should always use plugin upgrade code for things like this
3281 $authsavailable = get_list_of_plugins('auth');
3282 foreach($authsavailable as $authname) {
3283 if (!$auth = get_auth_plugin($authname)) {
3286 if ($auth->prevent_local_passwords()) {
3287 execute_sql("UPDATE {$CFG->prefix}user SET password='not cached' WHERE auth='$authname'");
3291 upgrade_main_savepoint($result, 2007101563.03);