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 ($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'));
36 if ($oldversion < 2006100601) { /// Disable the exercise module because it's unmaintained
37 if ($module = get_record('modules', 'name', 'exercise')) {
38 if ($module->visible
) {
39 // Hide/disable the module entry
40 set_field('modules', 'visible', '0', 'id', $module->id
);
41 // Save existing visible state for all activities
42 set_field('course_modules', 'visibleold', '1', 'visible' ,'1', 'module', $module->id
);
43 set_field('course_modules', 'visibleold', '0', 'visible' ,'0', 'module', $module->id
);
44 // Hide all activities
45 set_field('course_modules', 'visible', '0', 'module', $module->id
);
47 require_once($CFG->dirroot
.'/course/lib.php');
48 rebuild_course_cache(); // Rebuld cache for all modules because they might have changed
53 if ($oldversion < 2006101001) { /// Disable the LAMS module by default (if it is installed)
54 if (count_records('modules', 'name', 'lams') && !count_records('lams')) {
55 set_field('modules', 'visible', 0, 'name', 'lams'); // Disable it by default
59 if ($result && $oldversion < 2006102600) {
61 /// Define fields to be added to user_info_field
62 $table = new XMLDBTable('user_info_field');
63 $field = new XMLDBField('description');
64 $field->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, null, null, null, null, null, 'categoryid');
65 $field1 = new XMLDBField('param1');
66 $field1->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, null, null, null, null, null, 'defaultdata');
67 $field2 = new XMLDBField('param2');
68 $field2->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, null, null, null, null, null, 'param1');
69 $field3 = new XMLDBField('param3');
70 $field3->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, null, null, null, null, null, 'param2');
71 $field4 = new XMLDBField('param4');
72 $field4->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, null, null, null, null, null, 'param3');
73 $field5 = new XMLDBField('param5');
74 $field5->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, null, null, null, null, null, 'param4');
77 $result = $result && add_field($table, $field);
78 $result = $result && add_field($table, $field1);
79 $result = $result && add_field($table, $field2);
80 $result = $result && add_field($table, $field3);
81 $result = $result && add_field($table, $field4);
82 $result = $result && add_field($table, $field5);
85 if ($result && $oldversion < 2006112000) {
87 /// Define field attachment to be added to post
88 $table = new XMLDBTable('post');
89 $field = new XMLDBField('attachment');
90 $field->setAttributes(XMLDB_TYPE_CHAR
, '100', null, null, null, null, null, null, 'format');
92 /// Launch add field attachment
93 $result = $result && add_field($table, $field);
96 if ($result && $oldversion < 2006112200) {
98 /// Define field imagealt to be added to user
99 $table = new XMLDBTable('user');
100 $field = new XMLDBField('imagealt');
101 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null, 'trustbitmask');
103 /// Launch add field imagealt
104 $result = $result && add_field($table, $field);
106 $table = new XMLDBTable('user');
107 $field = new XMLDBField('screenreader');
108 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', null, XMLDB_NOTNULL
, null, null, null, '0', 'imagealt');
110 /// Launch add field screenreader
111 $result = $result && add_field($table, $field);
114 if ($oldversion < 2006120300) { /// Delete guest course section settings
115 // following code can be executed repeatedly, such as when upgrading from 1.7.x - it is ok
116 if ($guest = get_record('user', 'username', 'guest')) {
117 execute_sql("DELETE FROM {$CFG->prefix}course_display where userid=$guest->id", true);
121 if ($oldversion < 2006120400) { /// Remove secureforms config setting
122 execute_sql("DELETE FROM {$CFG->prefix}config where name='secureforms'", true);
125 if ($oldversion < 2006120700) { // add moodle/user:viewdetails to all roles!
126 if ($roles = get_records('role')) {
127 $context = get_context_instance(CONTEXT_SYSTEM
);
128 foreach ($roles as $roleid=>$role) {
129 assign_capability('moodle/user:viewdetails', CAP_ALLOW
, $roleid, $context->id
);
134 // Move the auth plugin settings into the config_plugin table
135 if ($oldversion < 2007010300) {
136 if ($CFG->auth
== 'email') {
137 set_config('registerauth', 'email');
139 set_config('registerauth', '');
141 $authplugins = get_list_of_plugins('auth');
142 foreach ($CFG as $k => $v) {
143 if (strpos($k, 'ldap_') === 0) {
144 //upgrade nonstandard ldap settings
145 $setting = substr($k, 5);
146 if (set_config($setting, $v, "auth/ldap")) {
147 delete_records('config', 'name', $k);
152 if (strpos($k, 'auth_') !== 0) {
155 $authsetting = substr($k, 5);
156 foreach ($authplugins as $auth) {
157 if (strpos($authsetting, $auth) !== 0) {
160 $setting = substr($authsetting, strlen($auth));
161 if (set_config($setting, $v, "auth/$auth")) {
162 delete_records('config', 'name', $k);
165 break; // don't check the rest of the auth plugin names
170 if ($oldversion < 2007010301) {
174 $table = new XMLDBTable('mnet_host');
175 $table->comment
= 'Information about the local and remote hosts for RPC';
177 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
178 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
179 $f->comment
= 'Unique Host ID';
180 $f = $table->addFieldInfo('deleted', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
181 XMLDB_NOTNULL
, null, null, null, 0);
182 $f = $table->addFieldInfo('wwwroot', XMLDB_TYPE_CHAR
, '255', null,
183 XMLDB_NOTNULL
, null, null, null, null);
184 $f = $table->addFieldInfo('ip_address', XMLDB_TYPE_CHAR
, '39', null,
185 XMLDB_NOTNULL
, null, null, null, null);
186 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '80', null,
187 XMLDB_NOTNULL
, null, null, null, null);
188 $f = $table->addFieldInfo('public_key', XMLDB_TYPE_TEXT
, 'medium', null,
189 XMLDB_NOTNULL
, null, null, null, null);
190 $f = $table->addFieldInfo('public_key_expires', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
191 XMLDB_NOTNULL
, null, null, null, 0);
192 $f = $table->addFieldInfo('transport', XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
,
193 XMLDB_NOTNULL
, null, null, null, 0);
194 $f = $table->addFieldInfo('portno', XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
,
195 XMLDB_NOTNULL
, null, null, null, 0);
196 $f = $table->addFieldInfo('last_connect_time', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
197 XMLDB_NOTNULL
, null, null, null, 0);
198 $f = $table->addFieldInfo('last_log_id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
199 XMLDB_NOTNULL
, null, null, null, 0);
201 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
203 $result = $result && create_table($table);
205 $table = new XMLDBTable('mnet_host2service');
206 $table->comment
= 'Information about the services for a given host';
208 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
209 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
210 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
211 XMLDB_NOTNULL
, NULL, null, null, 0);
212 $f = $table->addFieldInfo('serviceid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
213 XMLDB_NOTNULL
, NULL, null, null, 0);
214 $f = $table->addFieldInfo('publish', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
215 XMLDB_NOTNULL
, NULL, null, null, 0);
216 $f = $table->addFieldInfo('subscribe', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
217 XMLDB_NOTNULL
, NULL, null, null, 0);
219 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
220 $table->addIndexInfo('hostid_serviceid', XMLDB_INDEX_UNIQUE
, array('hostid', 'serviceid'));
222 $result = $result && create_table($table);
224 $table = new XMLDBTable('mnet_log');
225 $table->comment
= 'Store session data from users migrating to other sites';
227 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
228 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
229 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
230 XMLDB_NOTNULL
, NULL, null, null, 0);
231 $f = $table->addFieldInfo('remoteid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
232 XMLDB_NOTNULL
, NULL, null, null, 0);
233 $f = $table->addFieldInfo('time', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
234 XMLDB_NOTNULL
, NULL, null, null, 0);
235 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
236 XMLDB_NOTNULL
, NULL, null, null, 0);
237 $f = $table->addFieldInfo('ip', XMLDB_TYPE_CHAR
, '15', null,
238 XMLDB_NOTNULL
, NULL, null, null, null);
239 $f = $table->addFieldInfo('course', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
240 XMLDB_NOTNULL
, NULL, null, null, 0);
241 $f = $table->addFieldInfo('coursename', XMLDB_TYPE_CHAR
, '40', null,
242 XMLDB_NOTNULL
, NULL, null, null, null);
243 $f = $table->addFieldInfo('module', XMLDB_TYPE_CHAR
, '20', null,
244 XMLDB_NOTNULL
, NULL, null, null, null);
245 $f = $table->addFieldInfo('cmid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
246 XMLDB_NOTNULL
, NULL, null, null, 0);
247 $f = $table->addFieldInfo('action', XMLDB_TYPE_CHAR
, '40', null,
248 XMLDB_NOTNULL
, NULL, null, null, null);
249 $f = $table->addFieldInfo('url', XMLDB_TYPE_CHAR
, '100', null,
250 XMLDB_NOTNULL
, NULL, null, null, null);
251 $f = $table->addFieldInfo('info', XMLDB_TYPE_CHAR
, '255', null,
252 XMLDB_NOTNULL
, NULL, null, null, null);
254 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
255 $table->addIndexInfo('host_user_course', XMLDB_INDEX_NOTUNIQUE
, array('hostid', 'userid', 'course'));
257 $result = $result && create_table($table);
260 $table = new XMLDBTable('mnet_rpc');
261 $table->comment
= 'Functions or methods that we may publish or subscribe to';
263 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
264 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
265 $f = $table->addFieldInfo('function_name', XMLDB_TYPE_CHAR
, '40', null,
266 XMLDB_NOTNULL
, NULL, null, null, null);
267 $f = $table->addFieldInfo('xmlrpc_path', XMLDB_TYPE_CHAR
, '80', null,
268 XMLDB_NOTNULL
, NULL, null, null, null);
269 $f = $table->addFieldInfo('parent_type', XMLDB_TYPE_CHAR
, '6', null,
270 XMLDB_NOTNULL
, NULL, null, null, null);
271 $f = $table->addFieldInfo('parent', XMLDB_TYPE_CHAR
, '20', null,
272 XMLDB_NOTNULL
, NULL, null, null, null);
273 $f = $table->addFieldInfo('enabled', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
274 XMLDB_NOTNULL
, NULL, null, null, 0);
275 $f = $table->addFieldInfo('help', XMLDB_TYPE_TEXT
, 'medium', null,
276 XMLDB_NOTNULL
, NULL, null, null, null);
277 $f = $table->addFieldInfo('profile', XMLDB_TYPE_TEXT
, 'medium', null,
278 XMLDB_NOTNULL
, NULL, null, null, null);
280 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
281 $table->addIndexInfo('enabled_xpath', XMLDB_INDEX_NOTUNIQUE
, array('enabled', 'xmlrpc_path'));
283 $result = $result && create_table($table);
285 $table = new XMLDBTable('mnet_service');
286 $table->comment
= 'A service is a group of functions';
288 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
289 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
290 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '40', null,
291 XMLDB_NOTNULL
, NULL, null, null, null);
292 $f = $table->addFieldInfo('description', XMLDB_TYPE_CHAR
, '40', null,
293 XMLDB_NOTNULL
, NULL, null, null, null);
294 $f = $table->addFieldInfo('apiversion', XMLDB_TYPE_CHAR
, '10', null,
295 XMLDB_NOTNULL
, NULL, null, null, null);
296 $f = $table->addFieldInfo('offer', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
297 XMLDB_NOTNULL
, NULL, null, null, 0);
299 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
301 $result = $result && create_table($table);
303 $table = new XMLDBTable('mnet_service2rpc');
304 $table->comment
= 'Group functions or methods under a service';
306 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
307 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
308 $f = $table->addFieldInfo('serviceid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
309 XMLDB_NOTNULL
, NULL, null, null, 0);
310 $f = $table->addFieldInfo('rpcid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
311 XMLDB_NOTNULL
, NULL, null, null, 0);
313 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
314 $table->addIndexInfo('unique', XMLDB_INDEX_UNIQUE
, array('rpcid', 'serviceid'));
316 $result = $result && create_table($table);
319 // Prime MNET configuration entries -- will be needed later by auth/mnet
321 include_once $CFG->dirroot
. '/mnet/lib.php';
322 $env = new mnet_environment();
326 // add mnethostid to user-
327 $table = new XMLDBTable('user');
328 $field = new XMLDBField('mnethostid');
329 $field->setType(XMLDB_TYPE_INTEGER
);
330 $field->setLength(10);
331 $field->setNotNull(true);
332 $field->setSequence(null);
333 $field->setEnum(null);
334 $field->setDefault('0');
335 $field->setPrevious("deleted");
336 $field->setNext("username");
337 $result = $result && add_field($table, $field);
339 // The default mnethostid is zero... we need to update this for all
340 // users of the local IdP service.
342 'mnethostid', $CFG->mnet_localhost_id
,
346 $index = new XMLDBIndex('username');
347 $index->setUnique(true);
348 $index->setFields(array('username'));
349 drop_index($table, $index);
350 $index->setFields(array('mnethostid', 'username'));
351 if (!add_index($table, $index)) {
352 notify(get_string('duplicate_usernames', 'mnet', 'http://docs.moodle.org/en/DuplicateUsernames'));
355 unset($table, $field, $index);
360 $table = new XMLDBTable('mnet_session');
361 $table->comment
='Store session data from users migrating to other sites';
363 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
364 XMLDB_NOTNULL
,XMLDB_SEQUENCE
, null, null, null);
365 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
366 XMLDB_NOTNULL
, NULL, null, null, 0);
367 $f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR
, '100', null,
368 XMLDB_NOTNULL
, NULL, null, null, null);
369 $f = $table->addFieldInfo('token', XMLDB_TYPE_CHAR
, '40', null,
370 XMLDB_NOTNULL
, NULL, null, null, null);
371 $f = $table->addFieldInfo('mnethostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
372 XMLDB_NOTNULL
, NULL, null, null, 0);
373 $f = $table->addFieldInfo('useragent', XMLDB_TYPE_CHAR
, '40', null,
374 XMLDB_NOTNULL
, NULL, null, null, null);
375 $f = $table->addFieldInfo('confirm_timeout', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
376 XMLDB_NOTNULL
, NULL, null, null, 0);
377 $f = $table->addFieldInfo('session_id', XMLDB_TYPE_CHAR
, '40', null,
378 XMLDB_NOTNULL
, NULL, null, null, null);
379 $f = $table->addFieldInfo('expires', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
380 XMLDB_NOTNULL
, NULL, null, null, 0);
382 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
383 $table->addIndexInfo('token', XMLDB_INDEX_UNIQUE
, array('token'));
385 $result = $result && create_table($table);
388 $table = new XMLDBTable('mnet_sso_access_control');
389 $table->comment
= 'Users by host permitted (or not) to login from a remote provider';
390 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
391 XMLDB_NOTNULL
,XMLDB_SEQUENCE
, null, null, null);
392 $f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR
, '100', null,
393 XMLDB_NOTNULL
, NULL, null, null, null);
394 $f = $table->addFieldInfo('mnet_host_id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
395 XMLDB_NOTNULL
, NULL, null, null, 0);
396 $f = $table->addFieldInfo('access', XMLDB_TYPE_CHAR
, '20', null,
397 XMLDB_NOTNULL
, NULL, null, null, 'allow');
399 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
400 $table->addIndexInfo('mnethostid_username', XMLDB_INDEX_UNIQUE
, array('mnet_host_id', 'username'));
402 $result = $result && create_table($table);
404 if (empty($USER->mnet_host_id
)) {
405 $USER->mnet_host_id
= $CFG->mnet_localhost_id
; // Something for the current user to prevent warnings
411 $table = new XMLDBTable('mnet_enrol_course');
412 $table->comment
= 'Information about courses on remote hosts';
413 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
414 XMLDB_NOTNULL
,XMLDB_SEQUENCE
, null, null, null);
415 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
416 XMLDB_NOTNULL
, NULL, null, null, 0);
417 $f = $table->addFieldInfo('remoteid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
418 XMLDB_NOTNULL
, NULL, null, null, 0);
419 $f = $table->addFieldInfo('cat_id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
420 XMLDB_NOTNULL
, NULL, null, null, 0);
421 $f = $table->addFieldInfo('cat_name', XMLDB_TYPE_CHAR
, '255', null,
422 XMLDB_NOTNULL
, NULL, null, null, null);
423 $f = $table->addFieldInfo('cat_description', XMLDB_TYPE_TEXT
, 'medium', null,
424 XMLDB_NOTNULL
, NULL, null, null, null);
425 $f = $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER
, '4', XMLDB_UNSIGNED
,
426 XMLDB_NOTNULL
, NULL, null, null, 0);
427 $f = $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR
, '254', null,
428 XMLDB_NOTNULL
, NULL, null, null, null);
429 $f = $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR
, '15', null,
430 XMLDB_NOTNULL
, NULL, null, null, null);
431 $f = $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR
, '100', null,
432 XMLDB_NOTNULL
, NULL, null, null, null);
433 $f = $table->addFieldInfo('summary', XMLDB_TYPE_TEXT
, 'medium', null,
434 XMLDB_NOTNULL
, NULL, null, null, null);
435 $f = $table->addFieldInfo('startdate', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
436 XMLDB_NOTNULL
, NULL, null, null, 0);
437 $f = $table->addFieldInfo('cost', XMLDB_TYPE_CHAR
, '10', null,
438 XMLDB_NOTNULL
, NULL, null, null, null);
439 $f = $table->addFieldInfo('currency', XMLDB_TYPE_CHAR
, '3', null,
440 XMLDB_NOTNULL
, NULL, null, null, null);
441 $f = $table->addFieldInfo('defaultroleid', XMLDB_TYPE_INTEGER
, '4', XMLDB_UNSIGNED
,
442 XMLDB_NOTNULL
, NULL, null, null, 0);
443 $f = $table->addFieldInfo('defaultrolename', XMLDB_TYPE_CHAR
, '255', null,
444 XMLDB_NOTNULL
, NULL, null, null, null);
446 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
447 $table->addIndexInfo('hostid_remoteid', XMLDB_INDEX_UNIQUE
, array('hostid', 'remoteid'));
449 $result = $result && create_table($table);
452 $table = new XMLDBTable('mnet_enrol_assignments');
454 $table->comment
= 'Information about enrolments on courses on remote hosts';
455 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
456 XMLDB_NOTNULL
,XMLDB_SEQUENCE
, null, null, null);
457 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
458 XMLDB_NOTNULL
, NULL, null, null, 0);
459 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
460 XMLDB_NOTNULL
, NULL, null, null, 0);
461 $f = $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
462 XMLDB_NOTNULL
, NULL, null, null, 0);
463 $f = $table->addFieldInfo('rolename', XMLDB_TYPE_CHAR
, '255', null,
464 XMLDB_NOTNULL
, NULL, null, null, null);
465 $f = $table->addFieldInfo('enroltime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
466 XMLDB_NOTNULL
, NULL, null, null, 0);
467 $f = $table->addFieldInfo('enroltype', XMLDB_TYPE_CHAR
, '20', null,
468 XMLDB_NOTNULL
, NULL, null, null, null);
471 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
472 $table->addIndexInfo('hostid_courseid', XMLDB_INDEX_NOTUNIQUE
, array('hostid', 'courseid'));
473 $table->addIndexInfo('userid', XMLDB_INDEX_NOTUNIQUE
, array('userid'));
475 $result = $result && create_table($table);
479 if ($result && $oldversion < 2007010404) {
481 /// Define field shortname to be added to user_info_field
482 $table = new XMLDBTable('user_info_field');
483 $field = new XMLDBField('shortname');
484 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, 'shortname', 'id');
486 /// Launch add field shortname
487 $result = $result && add_field($table, $field);
489 /// Changing type of field name on table user_info_field to text
490 $table = new XMLDBTable('user_info_field');
491 $field = new XMLDBField('name');
492 $field->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, XMLDB_NOTNULL
, null, null, null, null, 'shortname');
494 /// Launch change of type for field name
495 $result = $result && change_field_type($table, $field);
497 /// For existing fields use 'name' as the 'shortname' entry
498 if ($fields = get_records_select('user_info_field', '', '', 'id, name')) {
499 foreach ($fields as $field) {
500 $field->shortname
= clean_param($field->name
, PARAM_ALPHANUM
);
501 $result && update_record('user_info_field', $field);
506 if ($result && $oldversion < 2007011200) {
508 /// Define table context_rel to be created
509 $table = new XMLDBTable('context_rel');
511 /// Adding fields to table context_rel
512 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
513 $table->addFieldInfo('c1', XMLDB_TYPE_INTEGER
, '10', null, null, null, null, null, null);
514 $table->addFieldInfo('c2', XMLDB_TYPE_INTEGER
, '10', null, null, null, null, null, null);
516 /// Adding keys to table context_rel
517 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
518 $table->addKeyInfo('c1', XMLDB_KEY_FOREIGN
, array('c1'), 'context', array('id'));
519 $table->addKeyInfo('c2', XMLDB_KEY_FOREIGN
, array('c2'), 'context', array('id'));
520 $table->addKeyInfo('c1c2', XMLDB_KEY_UNIQUE
, array('c1', 'c2'));
522 /// Launch create table for context_rel
523 $result = $result && create_table($table);
525 /// code here to fill the context_rel table
526 /// use get record set to iterate slower
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
);
543 if ($result && $oldversion < 2007012100) {
544 /// Some old PG servers have user->firstname & user->lastname with 30cc. They must be 100cc.
545 /// Fixing that conditionally. MDL-7110
546 if ($CFG->dbfamily
== 'postgres') {
547 /// Get Metadata from user table
548 $cols = array_change_key_case($db->MetaColumns($CFG->prefix
. 'user'), CASE_LOWER
);
550 /// Process user->firstname if needed
551 if ($col = $cols['firstname']) {
552 if ($col->max_length
< 100) {
553 /// Changing precision of field firstname on table user to (100)
554 $table = new XMLDBTable('user');
555 $field = new XMLDBField('firstname');
556 $field->setAttributes(XMLDB_TYPE_CHAR
, '100', null, XMLDB_NOTNULL
, null, null, null, null, 'idnumber');
558 /// Launch change of precision for field firstname
559 $result = $result && change_field_precision($table, $field);
563 /// Process user->lastname if needed
564 if ($col = $cols['lastname']) {
565 if ($col->max_length
< 100) {
566 /// Changing precision of field lastname on table user to (100)
567 $table = new XMLDBTable('user');
568 $field = new XMLDBField('lastname');
569 $field->setAttributes(XMLDB_TYPE_CHAR
, '100', null, XMLDB_NOTNULL
, null, null, null, null, 'firstname');
571 /// Launch change of precision for field lastname
572 $result = $result && change_field_precision($table, $field);
578 if ($result && $oldversion < 2007012101) {
580 /// Changing precision of field lang on table course to (30)
581 $table = new XMLDBTable('course');
582 $field = new XMLDBField('lang');
583 $field->setAttributes(XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, null, 'groupmodeforce');
585 /// Launch change of precision for field course->lang
586 $result = $result && change_field_precision($table, $field);
588 /// Changing precision of field lang on table user to (30)
589 $table = new XMLDBTable('user');
590 $field = new XMLDBField('lang');
591 $field->setAttributes(XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, 'en', 'country');
593 /// Launch change of precision for field user->lang
594 $result = $result && change_field_precision($table, $field);
597 if ($result && $oldversion < 2007012400) {
599 /// Rename field access on table mnet_sso_access_control to accessctrl
600 $table = new XMLDBTable('mnet_sso_access_control');
601 $field = new XMLDBField('access');
602 $field->setAttributes(XMLDB_TYPE_CHAR
, '20', null, XMLDB_NOTNULL
, null, null, null, 'allow', 'mnet_host_id');
604 /// Launch rename field accessctrl
605 $result = $result && rename_field($table, $field, 'accessctrl');
608 if ($result && $oldversion < 2007012500) {
609 execute_sql("DELETE FROM {$CFG->prefix}user WHERE username='changeme'", true);
612 if ($result && $oldversion < 2007020400) {
613 /// Only for MySQL and PG, declare the user->ajax field as not null. MDL-8421.
614 if ($CFG->dbfamily
== 'mysql' ||
$CFG->dbfamily
== 'postgres') {
615 /// Changing nullability of field ajax on table user to not null
616 $table = new XMLDBTable('user');
617 $field = new XMLDBField('ajax');
618 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '1', 'htmleditor');
620 /// Launch change of nullability for field ajax
621 $result = $result && change_field_notnull($table, $field);
625 if (!empty($CFG->rolesactive
) && $result && $oldversion < 2007021401) {
626 /// create default logged in user role if not present - upgrade rom 1.7.x
627 if (empty($CFG->defaultuserroleid
) or empty($CFG->guestroleid
) or $CFG->defaultuserroleid
== $CFG->guestroleid
) {
628 if (!get_records('role', 'shortname', 'user')) {
629 $userroleid = create_role(addslashes(get_string('authenticateduser')), 'user',
630 addslashes(get_string('authenticateduserdescription')), 'moodle/legacy:user');
632 reset_role_capabilities($userroleid);
633 set_config('defaultuserroleid', $userroleid);
639 if ($result && $oldversion < 2007021501) {
640 /// delete removed setting from config
641 unset_config('tabselectedtofront');
645 if ($result && $oldversion < 2007032200) {
647 /// Define table role_sortorder to be created
648 $table = new XMLDBTable('role_sortorder');
650 /// Adding fields to table role_sortorder
651 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
652 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
653 $table->addFieldInfo('roleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
654 $table->addFieldInfo('contextid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
655 $table->addFieldInfo('sortoder', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
657 /// Adding keys to table role_sortorder
658 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
659 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
660 $table->addKeyInfo('roleid', XMLDB_KEY_FOREIGN
, array('roleid'), 'role', array('id'));
661 $table->addKeyInfo('contextid', XMLDB_KEY_FOREIGN
, array('contextid'), 'context', array('id'));
663 /// Adding indexes to table role_sortorder
664 $table->addIndexInfo('userid-roleid-contextid', XMLDB_INDEX_UNIQUE
, array('userid', 'roleid', 'contextid'));
666 /// Launch create table for role_sortorder
667 $result = $result && create_table($table);
671 /// code to change lenghen tag field to 255, MDL-9095
672 if ($result && $oldversion < 2007040400) {
674 /// Define index text (not unique) to be dropped form tags
675 $table = new XMLDBTable('tags');
676 $index = new XMLDBIndex('text');
677 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('text'));
679 /// Launch drop index text
680 $result = $result && drop_index($table, $index);
682 $field = new XMLDBField('text');
683 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null, 'userid');
685 /// Launch change of type for field text
686 $result = $result && change_field_type($table, $field);
688 $index = new XMLDBIndex('text');
689 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('text'));
691 /// Launch add index text
692 $result = $result && add_index($table, $index);
695 if ($result && $oldversion < 2007041100) {
697 /// Define field idnumber to be added to course_modules
698 $table = new XMLDBTable('course_modules');
699 $field = new XMLDBField('idnumber');
700 $field->setAttributes(XMLDB_TYPE_CHAR
, '100', null, null, null, null, null, null, 'section');
702 /// Launch add field idnumber
703 $result = $result && add_field($table, $field);
705 /// Define index idnumber (unique) to be added to course_modules
706 $table = new XMLDBTable('course_modules');
707 $index = new XMLDBIndex('idnumber');
708 $index->setAttributes(XMLDB_INDEX_UNIQUE
, array('idnumber'));
710 /// Launch add index idnumber
711 $result = $result && add_index($table, $index);
715 /* Changes to the custom profile menu type - store values rather than indices.
716 We could do all this with one tricky SQL statement but it's a one-off so no
717 harm in using PHP loops */
718 if ($result && $oldversion < 2007041600) {
720 /// Get the menu fields
721 if ($fields = get_records('user_info_field', 'datatype', 'menu')) {
722 foreach ($fields as $field) {
724 /// Get user data for the menu field
725 if ($data = get_records('user_info_data', 'fieldid', $field->id
)) {
727 /// Get the menu options
728 $options = explode("\n", $this->field
->param1
);
729 foreach ($data as $d) {
730 $key = array_search($d->data
, $options);
732 /// If the data is an integer and is not one of the options,
733 /// set the respective option value
734 if (is_int($d->data
) and (($key === NULL) or ($key === false)) and isset($options[$d->data
])) {
735 $d->data
= $options[$d->data
];
736 $result = $result && update_record('user_info_data', $d);
745 /// adding new gradebook tables
746 if ($result && $oldversion < 2007041800) {
748 /// Define table events_handlers to be created
749 $table = new XMLDBTable('events_handlers');
751 /// Adding fields to table events_handlers
752 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
753 $table->addFieldInfo('eventname', XMLDB_TYPE_CHAR
, '166', null, XMLDB_NOTNULL
, null, null, null, null);
754 $table->addFieldInfo('handlermodule', XMLDB_TYPE_CHAR
, '166', null, XMLDB_NOTNULL
, null, null, null, null);
755 $table->addFieldInfo('handlerfile', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
756 $table->addFieldInfo('handlerfunction', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
758 /// Adding keys to table events_handlers
759 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
761 /// Adding indexes to table events_handlers
762 $table->addIndexInfo('eventname-handlermodule', XMLDB_INDEX_UNIQUE
, array('eventname', 'handlermodule'));
764 /// Launch create table for events_handlers
765 $result = $result && create_table($table);
767 /// Define table events_queue to be created
768 $table = new XMLDBTable('events_queue');
770 /// Adding fields to table events_queue
771 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
772 $table->addFieldInfo('eventdata', XMLDB_TYPE_TEXT
, 'big', null, XMLDB_NOTNULL
, null, null, null, null);
773 $table->addFieldInfo('schedule', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
774 $table->addFieldInfo('stackdump', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
775 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
776 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
778 /// Adding keys to table events_queue
779 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
780 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
782 /// Launch create table for events_queue
783 $result = $result && create_table($table);
785 /// Define table events_queue_handlers to be created
786 $table = new XMLDBTable('events_queue_handlers');
788 /// Adding fields to table events_queue_handlers
789 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
790 $table->addFieldInfo('queuedeventid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
791 $table->addFieldInfo('handlerid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
792 $table->addFieldInfo('status', XMLDB_TYPE_INTEGER
, '10', null, null, null, null, null, null);
793 $table->addFieldInfo('errormessage', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
794 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
796 /// Adding keys to table events_queue_handlers
797 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
798 $table->addKeyInfo('queuedeventid', XMLDB_KEY_FOREIGN
, array('queuedeventid'), 'events_queue', array('id'));
799 $table->addKeyInfo('handlerid', XMLDB_KEY_FOREIGN
, array('handlerid'), 'events_handlers', array('id'));
801 /// Launch create table for events_queue_handlers
802 $result = $result && create_table($table);
806 if ($result && $oldversion < 2007043001) {
808 /// Define field schedule to be added to events_handlers
809 $table = new XMLDBTable('events_handlers');
810 $field = new XMLDBField('schedule');
811 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null, 'handlerfunction');
813 /// Launch add field schedule
814 $result = $result && add_field($table, $field);
816 /// Define field status to be added to events_handlers
817 $table = new XMLDBTable('events_handlers');
818 $field = new XMLDBField('status');
819 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'schedule');
821 /// Launch add field status
822 $result = $result && add_field($table, $field);
825 if ($result && $oldversion < 2007050201) {
827 /// Define field theme to be added to course_categories
828 $table = new XMLDBTable('course_categories');
829 $field = new XMLDBField('theme');
830 $field->setAttributes(XMLDB_TYPE_CHAR
, '50', null, null, null, null, null, null, 'path');
832 /// Launch add field theme
833 $result = $result && add_field($table, $field);
836 if ($result && $oldversion < 2007051100) {
838 /// Define field forceunique to be added to user_info_field
839 $table = new XMLDBTable('user_info_field');
840 $field = new XMLDBField('forceunique');
841 $field->setAttributes(XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'visible');
843 /// Launch add field forceunique
844 $result = $result && add_field($table, $field);
846 /// Define field signup to be added to user_info_field
847 $table = new XMLDBTable('user_info_field');
848 $field = new XMLDBField('signup');
849 $field->setAttributes(XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'forceunique');
851 /// Launch add field signup
852 $result = $result && add_field($table, $field);
855 if ($result && $oldversion < 2007051101) {
856 if (empty($CFG->enablegroupings
)) {
857 // delete all groupings - they do not work yet :-(
858 // while keeping all existing groups
859 require_once("$CFG->dirroot/group/db/upgrade.php");
864 if ($result && $oldversion < 2007051801) {
865 // Get the role id of the "Auth. User" role and check if the default role id is different
866 $userrole = get_record( 'role', 'shortname', 'user' );
867 $defaultroleid = $CFG->defaultuserroleid
;
869 if( $defaultroleid != $userrole->id
) {
870 // Add in the new moodle/my:manageblocks capibility to the default user role
871 $context = get_context_instance(CONTEXT_SYSTEM
, SITEID
);
872 assign_capability('moodle/my:manageblocks',CAP_ALLOW
,$defaultroleid,$context->id
);
876 if ($result && $oldversion < 2007052200) {
878 /// Define field schedule to be dropped from events_queue
879 $table = new XMLDBTable('events_queue');
880 $field = new XMLDBField('schedule');
882 /// Launch drop field stackdump
883 $result = $result && drop_field($table, $field);
886 if ($result && $oldversion < 2007052300) {
887 require_once($CFG->dirroot
. '/question/upgrade.php');
888 $result = $result && question_remove_rqp_qtype();
891 if ($result && $oldversion < 2007060500) {
893 /// Define field usermodified to be added to post
894 $table = new XMLDBTable('post');
895 $field = new XMLDBField('usermodified');
896 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null, 'created');
898 /// Launch add field usermodified
899 $result = $result && add_field($table, $field);
901 /// Define key usermodified (foreign) to be added to post
902 $table = new XMLDBTable('post');
903 $key = new XMLDBKey('usermodified');
904 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
906 /// Launch add key usermodified
907 $result = $result && add_key($table, $key);
910 /// merge raw and final grade tables
911 if ($result && $oldversion < 2007062007) {
913 /// Define table grade_import_values to be created
914 $table = new XMLDBTable('grade_import_values');
915 if (table_exists($table)) {
919 /// Adding fields to table grade_import_values
920 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
921 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
922 $table->addFieldInfo('newgradeitem', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
923 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
924 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0.0');
925 $table->addFieldInfo('import_code', XMLDB_TYPE_INTEGER
, '12', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
927 /// Adding keys to table grade_import_values
928 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
929 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN
, array('itemid'), 'grade_items', array('id'));
930 $table->addKeyInfo('newgradeitem', XMLDB_KEY_FOREIGN
, array('newgradeitem'), 'grade_import_newitem', array('id'));
932 /// Launch create table for grade_import_values
933 $result = $result && create_table($table);
935 /// Define table grade_import_newitem to be created
936 $table = new XMLDBTable('grade_import_newitem');
937 if (table_exists($table)) {
941 /// Adding fields to table grade_import_newitem
942 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
943 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
944 $table->addFieldInfo('import_code', XMLDB_TYPE_INTEGER
, '12', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
946 /// Adding keys to table grade_import_newitem
947 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
949 /// Launch create table for grade_import_newitem
950 $result = $result && create_table($table);
954 /// clenaup and recreate tables for course grade
955 if ($result && $oldversion < 2007063000) {
957 /// Remove the all grade tables - we need empty db for course grade to work properly
958 $tables = array('grade_categories',
960 'grade_calculations',
963 'grade_grades_final',
968 foreach ($tables as $table) {
969 $table = new XMLDBTable($table);
970 if (table_exists($table)) {
976 /// Define table grade_items to be created
977 $table = new XMLDBTable('grade_items');
979 /// Adding fields to table grade_items
980 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
981 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
982 $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
983 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
984 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, null);
985 $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR
, '30', null, null, null, null, null, null);
986 $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
987 $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
988 $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
989 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
990 $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
991 $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '1');
992 $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
993 $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
994 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
995 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER
, '10', null, null, null, null, null, null);
996 $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
997 $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '1.0');
998 $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
999 $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1000 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1001 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1002 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1003 $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1004 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1005 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1007 /// Adding keys to table grade_items
1008 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1009 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1010 $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN
, array('categoryid'), 'grade_categories', array('id'));
1011 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
1012 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN
, array('outcomeid'), 'grade_outcomes', array('id'));
1014 /// Launch create table for grade_items
1015 $result = $result && create_table($table);
1018 /// Define table grade_categories to be created
1019 $table = new XMLDBTable('grade_categories');
1021 /// Adding fields to table grade_categories
1022 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1023 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1024 $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1025 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1026 $table->addFieldInfo('path', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1027 $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1028 $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1029 $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1030 $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1031 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1032 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1034 /// Adding keys to table grade_categories
1035 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1036 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1037 $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN
, array('parent'), 'grade_categories', array('id'));
1039 /// Launch create table for grade_categories
1040 $result = $result && create_table($table);
1043 /// Define table grade_grades to be created
1044 $table = new XMLDBTable('grade_grades');
1046 /// Adding fields to table grade_grades
1047 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1048 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1049 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1050 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
1051 $table->addFieldInfo('rawgrademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
1052 $table->addFieldInfo('rawgrademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1053 $table->addFieldInfo('rawscaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1054 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1055 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
1056 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1057 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1058 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1059 $table->addFieldInfo('exported', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1060 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1061 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1063 /// Adding keys to table grade_grades
1064 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1065 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN
, array('itemid'), 'grade_items', array('id'));
1066 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
1067 $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN
, array('rawscaleid'), 'scale', array('id'));
1068 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
1070 /// Launch create table for grade_grades
1071 $result = $result && create_table($table);
1074 /// Define table grade_grades_text to be created
1075 $table = new XMLDBTable('grade_grades_text');
1077 /// Adding fields to table grade_grades_text
1078 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1079 $table->addFieldInfo('gradeid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1080 $table->addFieldInfo('information', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1081 $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1082 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1083 $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1084 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1085 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', null, null, null, null, null, null);
1086 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', null, null, null, null, null, null);
1088 /// Adding keys to table grade_grades_text
1089 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1090 $table->addKeyInfo('gradeid', XMLDB_KEY_FOREIGN
, array('gradeid'), 'grade_grades', array('id'));
1091 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
1093 /// Launch create table for grade_grades_text
1094 $result = $result && create_table($table);
1097 /// Define table grade_outcomes to be created
1098 $table = new XMLDBTable('grade_outcomes');
1100 /// Adding fields to table grade_outcomes
1101 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1102 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1103 $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1104 $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
1105 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1106 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1107 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1108 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1110 /// Adding keys to table grade_outcomes
1111 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1112 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1113 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
1114 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
1116 /// Launch create table for grade_outcomes
1117 $result = $result && create_table($table);
1121 // add foreign key that was forgotten in last commit
1122 if ($result && $oldversion < 2007063001) {
1124 /// Define key gradeid (foreign) to be added to grade_grades_text
1125 $table = new XMLDBTable('grade_grades_text');
1126 $key = new XMLDBKey('gradeid');
1127 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('gradeid'), 'grade_grades', array('id'));
1129 /// Launch add key gradeid
1130 add_key($table, $key);
1133 if ($result && $oldversion < 2007070300) {
1134 set_config('grade_report_aggregationview', '0');
1135 set_config('grade_report_aggregationposition', '0');
1136 set_config('grade_report_bulkcheckboxes', '1');
1137 set_config('grade_report_gradedisplaytype', '0');
1138 set_config('grade_report_enableajax', '1');
1139 set_config('grade_report_showeyecons', '1');
1140 set_config('grade_report_showgroups', '1');
1141 set_config('grade_report_showlocks', '1');
1142 set_config('grade_report_shownotes', '1');
1143 set_config('grade_report_showscales', '1');
1144 set_config('grade_report_studentsperpage', '20');
1145 set_config('grade_report_feedbackformat', '0');
1148 if ($result && $oldversion < 2007070602) {
1149 /// Remove obsoleted unitt tests tables - they will be recreated automatically
1150 $tables = array('grade_categories',
1153 'grade_calculations',
1156 'grade_grades_final',
1157 'grade_grades_text',
1161 foreach ($tables as $table) {
1162 $table = new XMLDBTable('unittest_'.$table);
1163 if (table_exists($table)) {
1168 /// drop old grade history table
1169 $table = new XMLDBTable('grade_history');
1170 if (table_exists($table)) {
1174 /// drop old deleted field
1175 $table = new XMLDBTable('grade_items');
1176 $field = new XMLDBField('deleted');
1177 if (field_exists($table, $field)) {
1178 drop_field($table, $field);
1182 /// Define table grade_items_history to be created
1183 $table = new XMLDBTable('grade_items_history');
1185 /// Adding fields to table grade_items_history
1186 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1187 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1188 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', null, 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('userlogged', 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('categoryid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1194 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1195 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, null);
1196 $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR
, '30', null, null, null, null, null, null);
1197 $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1198 $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1199 $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1200 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1201 $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1202 $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '1');
1203 $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
1204 $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1205 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1206 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER
, '10', null, null, null, null, null, null);
1207 $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1208 $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '1.0');
1209 $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1210 $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1211 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1212 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1213 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1214 $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1216 /// Adding keys to table grade_items_history
1217 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1218 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_items', array('id'));
1219 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1220 $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN
, array('categoryid'), 'grade_categories', array('id'));
1221 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
1222 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN
, array('outcomeid'), 'grade_outcomes', array('id'));
1224 /// Adding indexes to table grade_items_history
1225 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1227 /// Launch create table for grade_items_history
1228 $result = $result && create_table($table);
1231 /// Define table grade_categories_history to be created
1232 $table = new XMLDBTable('grade_categories_history');
1234 /// Adding fields to table grade_categories_history
1235 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1236 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1237 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
1238 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1239 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1240 $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1241 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1242 $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1243 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1244 $table->addFieldInfo('path', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1245 $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1246 $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1247 $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1248 $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1250 /// Adding keys to table grade_categories_history
1251 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1252 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_categories', array('id'));
1253 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1254 $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN
, array('parent'), 'grade_categories', array('id'));
1256 /// Adding indexes to table grade_categories_history
1257 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1259 /// Launch create table for grade_categories_history
1260 $result = $result && create_table($table);
1263 /// Define table grade_grades_history to be created
1264 $table = new XMLDBTable('grade_grades_history');
1266 /// Adding fields to table grade_grades_history
1267 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1268 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1269 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
1270 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1271 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1272 $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1273 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1274 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1275 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
1276 $table->addFieldInfo('rawgrademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
1277 $table->addFieldInfo('rawgrademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1278 $table->addFieldInfo('rawscaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1279 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1280 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
1281 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1282 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1283 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1284 $table->addFieldInfo('exported', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1286 /// Adding keys to table grade_grades_history
1287 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1288 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_grades', array('id'));
1289 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN
, array('itemid'), 'grade_items', array('id'));
1290 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
1291 $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN
, array('rawscaleid'), 'scale', array('id'));
1292 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
1293 $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN
, array('userlogged'), 'user', array('id'));
1295 /// Adding indexes to table grade_grades_history
1296 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1298 /// Launch create table for grade_grades_history
1299 $result = $result && create_table($table);
1302 /// Define table grade_grades_text_history to be created
1303 $table = new XMLDBTable('grade_grades_text_history');
1305 /// Adding fields to table grade_grades_text_history
1306 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1307 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1308 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
1309 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1310 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1311 $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1312 $table->addFieldInfo('gradeid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1313 $table->addFieldInfo('information', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1314 $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1315 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1316 $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1317 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1319 /// Adding keys to table grade_grades_text_history
1320 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1321 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_grades_text', array('id'));
1322 $table->addKeyInfo('gradeid', XMLDB_KEY_FOREIGN
, array('gradeid'), 'grade_grades', array('id'));
1323 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
1324 $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN
, array('userlogged'), 'user', array('id'));
1326 /// Adding indexes to table grade_grades_text_history
1327 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1329 /// Launch create table for grade_grades_text_history
1330 $result = $result && create_table($table);
1333 /// Define table grade_outcomes_history to be created
1334 $table = new XMLDBTable('grade_outcomes_history');
1336 /// Adding fields to table grade_outcomes_history
1337 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1338 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1339 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
1340 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1341 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1342 $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1343 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1344 $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1345 $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
1346 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1347 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1349 /// Adding keys to table grade_outcomes_history
1350 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1351 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_outcomes', array('id'));
1352 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1353 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
1354 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
1355 $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN
, array('userlogged'), 'user', array('id'));
1357 /// Adding indexes to table grade_outcomes_history
1358 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1360 /// Launch create table for grade_outcomes_history
1361 $result = $result && create_table($table);
1364 /// Define table scale_history to be created
1365 $table = new XMLDBTable('scale_history');
1367 /// Adding fields to table scale_history
1368 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1369 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1370 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
1371 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1372 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1373 $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1374 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1375 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1376 $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1377 $table->addFieldInfo('scale', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
1378 $table->addFieldInfo('description', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
1380 /// Adding keys to table scale_history
1381 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1382 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'scales', array('id'));
1383 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1384 $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN
, array('userlogged'), 'user', array('id'));
1386 /// Adding indexes to table scale_history
1387 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1389 /// Launch create table for scale_history
1390 $result = $result && create_table($table);
1394 if ($result && $oldversion < 2007070603) {
1395 // Small update of guest user to be 100% sure it has the correct mnethostid (MDL-10375)
1396 set_field('user', 'mnethostid', $CFG->mnet_localhost_id
, 'username', 'guest');