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 (!empty($CFG->rolesactive
) && $oldversion < 2006120700) { // add moodle/user:viewdetails to all roles!
126 // note: use of assign_capability() is discouraged in upgrade script!
127 if ($roles = get_records('role')) {
128 $context = get_context_instance(CONTEXT_SYSTEM
);
129 foreach ($roles as $roleid=>$role) {
130 assign_capability('moodle/user:viewdetails', CAP_ALLOW
, $roleid, $context->id
);
135 // Move the auth plugin settings into the config_plugin table
136 if ($oldversion < 2007010300) {
137 if ($CFG->auth
== 'email') {
138 set_config('registerauth', 'email');
140 set_config('registerauth', '');
142 $authplugins = get_list_of_plugins('auth');
143 foreach ($CFG as $k => $v) {
144 if (strpos($k, 'ldap_') === 0) {
145 //upgrade nonstandard ldap settings
146 $setting = substr($k, 5);
147 if (set_config($setting, $v, "auth/ldap")) {
148 delete_records('config', 'name', $k);
153 if (strpos($k, 'auth_') !== 0) {
156 $authsetting = substr($k, 5);
157 foreach ($authplugins as $auth) {
158 if (strpos($authsetting, $auth) !== 0) {
161 $setting = substr($authsetting, strlen($auth));
162 if (set_config($setting, $v, "auth/$auth")) {
163 delete_records('config', 'name', $k);
166 break; // don't check the rest of the auth plugin names
171 if ($oldversion < 2007010301) {
175 $table = new XMLDBTable('mnet_host');
176 $table->comment
= 'Information about the local and remote hosts for RPC';
178 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
179 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
180 $f->comment
= 'Unique Host ID';
181 $f = $table->addFieldInfo('deleted', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
182 XMLDB_NOTNULL
, null, null, null, 0);
183 $f = $table->addFieldInfo('wwwroot', XMLDB_TYPE_CHAR
, '255', null,
184 XMLDB_NOTNULL
, null, null, null, null);
185 $f = $table->addFieldInfo('ip_address', XMLDB_TYPE_CHAR
, '39', null,
186 XMLDB_NOTNULL
, null, null, null, null);
187 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '80', null,
188 XMLDB_NOTNULL
, null, null, null, null);
189 $f = $table->addFieldInfo('public_key', XMLDB_TYPE_TEXT
, 'medium', null,
190 XMLDB_NOTNULL
, null, null, null, null);
191 $f = $table->addFieldInfo('public_key_expires', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
192 XMLDB_NOTNULL
, null, null, null, 0);
193 $f = $table->addFieldInfo('transport', XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
,
194 XMLDB_NOTNULL
, null, null, null, 0);
195 $f = $table->addFieldInfo('portno', XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
,
196 XMLDB_NOTNULL
, null, null, null, 0);
197 $f = $table->addFieldInfo('last_connect_time', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
198 XMLDB_NOTNULL
, null, null, null, 0);
199 $f = $table->addFieldInfo('last_log_id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
200 XMLDB_NOTNULL
, null, null, null, 0);
202 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
204 $result = $result && create_table($table);
206 $table = new XMLDBTable('mnet_host2service');
207 $table->comment
= 'Information about the services for a given host';
209 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
210 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
211 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
212 XMLDB_NOTNULL
, NULL, null, null, 0);
213 $f = $table->addFieldInfo('serviceid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
214 XMLDB_NOTNULL
, NULL, null, null, 0);
215 $f = $table->addFieldInfo('publish', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
216 XMLDB_NOTNULL
, NULL, null, null, 0);
217 $f = $table->addFieldInfo('subscribe', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
218 XMLDB_NOTNULL
, NULL, null, null, 0);
220 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
221 $table->addIndexInfo('hostid_serviceid', XMLDB_INDEX_UNIQUE
, array('hostid', 'serviceid'));
223 $result = $result && create_table($table);
225 $table = new XMLDBTable('mnet_log');
226 $table->comment
= 'Store session data from users migrating to other sites';
228 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
229 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
230 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
231 XMLDB_NOTNULL
, NULL, null, null, 0);
232 $f = $table->addFieldInfo('remoteid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
233 XMLDB_NOTNULL
, NULL, null, null, 0);
234 $f = $table->addFieldInfo('time', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
235 XMLDB_NOTNULL
, NULL, null, null, 0);
236 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
237 XMLDB_NOTNULL
, NULL, null, null, 0);
238 $f = $table->addFieldInfo('ip', XMLDB_TYPE_CHAR
, '15', null,
239 XMLDB_NOTNULL
, NULL, null, null, null);
240 $f = $table->addFieldInfo('course', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
241 XMLDB_NOTNULL
, NULL, null, null, 0);
242 $f = $table->addFieldInfo('coursename', XMLDB_TYPE_CHAR
, '40', null,
243 XMLDB_NOTNULL
, NULL, null, null, null);
244 $f = $table->addFieldInfo('module', XMLDB_TYPE_CHAR
, '20', null,
245 XMLDB_NOTNULL
, NULL, null, null, null);
246 $f = $table->addFieldInfo('cmid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
247 XMLDB_NOTNULL
, NULL, null, null, 0);
248 $f = $table->addFieldInfo('action', XMLDB_TYPE_CHAR
, '40', null,
249 XMLDB_NOTNULL
, NULL, null, null, null);
250 $f = $table->addFieldInfo('url', XMLDB_TYPE_CHAR
, '100', null,
251 XMLDB_NOTNULL
, NULL, null, null, null);
252 $f = $table->addFieldInfo('info', XMLDB_TYPE_CHAR
, '255', null,
253 XMLDB_NOTNULL
, NULL, null, null, null);
255 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
256 $table->addIndexInfo('host_user_course', XMLDB_INDEX_NOTUNIQUE
, array('hostid', 'userid', 'course'));
258 $result = $result && create_table($table);
261 $table = new XMLDBTable('mnet_rpc');
262 $table->comment
= 'Functions or methods that we may publish or subscribe to';
264 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
265 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
266 $f = $table->addFieldInfo('function_name', XMLDB_TYPE_CHAR
, '40', null,
267 XMLDB_NOTNULL
, NULL, null, null, null);
268 $f = $table->addFieldInfo('xmlrpc_path', XMLDB_TYPE_CHAR
, '80', null,
269 XMLDB_NOTNULL
, NULL, null, null, null);
270 $f = $table->addFieldInfo('parent_type', XMLDB_TYPE_CHAR
, '6', null,
271 XMLDB_NOTNULL
, NULL, null, null, null);
272 $f = $table->addFieldInfo('parent', XMLDB_TYPE_CHAR
, '20', null,
273 XMLDB_NOTNULL
, NULL, null, null, null);
274 $f = $table->addFieldInfo('enabled', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
275 XMLDB_NOTNULL
, NULL, null, null, 0);
276 $f = $table->addFieldInfo('help', XMLDB_TYPE_TEXT
, 'medium', null,
277 XMLDB_NOTNULL
, NULL, null, null, null);
278 $f = $table->addFieldInfo('profile', XMLDB_TYPE_TEXT
, 'medium', null,
279 XMLDB_NOTNULL
, NULL, null, null, null);
281 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
282 $table->addIndexInfo('enabled_xpath', XMLDB_INDEX_NOTUNIQUE
, array('enabled', 'xmlrpc_path'));
284 $result = $result && create_table($table);
286 $table = new XMLDBTable('mnet_service');
287 $table->comment
= 'A service is a group of functions';
289 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
290 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
291 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '40', null,
292 XMLDB_NOTNULL
, NULL, null, null, null);
293 $f = $table->addFieldInfo('description', XMLDB_TYPE_CHAR
, '40', null,
294 XMLDB_NOTNULL
, NULL, null, null, null);
295 $f = $table->addFieldInfo('apiversion', XMLDB_TYPE_CHAR
, '10', null,
296 XMLDB_NOTNULL
, NULL, null, null, null);
297 $f = $table->addFieldInfo('offer', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
,
298 XMLDB_NOTNULL
, NULL, null, null, 0);
300 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
302 $result = $result && create_table($table);
304 $table = new XMLDBTable('mnet_service2rpc');
305 $table->comment
= 'Group functions or methods under a service';
307 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
308 XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
309 $f = $table->addFieldInfo('serviceid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
310 XMLDB_NOTNULL
, NULL, null, null, 0);
311 $f = $table->addFieldInfo('rpcid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
312 XMLDB_NOTNULL
, NULL, null, null, 0);
314 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
315 $table->addIndexInfo('unique', XMLDB_INDEX_UNIQUE
, array('rpcid', 'serviceid'));
317 $result = $result && create_table($table);
320 // Prime MNET configuration entries -- will be needed later by auth/mnet
322 include_once $CFG->dirroot
. '/mnet/lib.php';
323 $env = new mnet_environment();
327 // add mnethostid to user-
328 $table = new XMLDBTable('user');
329 $field = new XMLDBField('mnethostid');
330 $field->setType(XMLDB_TYPE_INTEGER
);
331 $field->setLength(10);
332 $field->setNotNull(true);
333 $field->setSequence(null);
334 $field->setEnum(null);
335 $field->setDefault('0');
336 $field->setPrevious("deleted");
337 $field->setNext("username");
338 $result = $result && add_field($table, $field);
340 // The default mnethostid is zero... we need to update this for all
341 // users of the local IdP service.
343 'mnethostid', $CFG->mnet_localhost_id
,
347 $index = new XMLDBIndex('username');
348 $index->setUnique(true);
349 $index->setFields(array('username'));
350 drop_index($table, $index);
351 $index->setFields(array('mnethostid', 'username'));
352 if (!add_index($table, $index)) {
353 notify(get_string('duplicate_usernames', 'mnet', 'http://docs.moodle.org/en/DuplicateUsernames'));
356 unset($table, $field, $index);
361 $table = new XMLDBTable('mnet_session');
362 $table->comment
='Store session data from users migrating to other sites';
364 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
365 XMLDB_NOTNULL
,XMLDB_SEQUENCE
, null, null, null);
366 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
367 XMLDB_NOTNULL
, NULL, null, null, 0);
368 $f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR
, '100', null,
369 XMLDB_NOTNULL
, NULL, null, null, null);
370 $f = $table->addFieldInfo('token', XMLDB_TYPE_CHAR
, '40', null,
371 XMLDB_NOTNULL
, NULL, null, null, null);
372 $f = $table->addFieldInfo('mnethostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
373 XMLDB_NOTNULL
, NULL, null, null, 0);
374 $f = $table->addFieldInfo('useragent', XMLDB_TYPE_CHAR
, '40', null,
375 XMLDB_NOTNULL
, NULL, null, null, null);
376 $f = $table->addFieldInfo('confirm_timeout', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
377 XMLDB_NOTNULL
, NULL, null, null, 0);
378 $f = $table->addFieldInfo('session_id', XMLDB_TYPE_CHAR
, '40', null,
379 XMLDB_NOTNULL
, NULL, null, null, null);
380 $f = $table->addFieldInfo('expires', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
381 XMLDB_NOTNULL
, NULL, null, null, 0);
383 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
384 $table->addIndexInfo('token', XMLDB_INDEX_UNIQUE
, array('token'));
386 $result = $result && create_table($table);
389 $table = new XMLDBTable('mnet_sso_access_control');
390 $table->comment
= 'Users by host permitted (or not) to login from a remote provider';
391 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
392 XMLDB_NOTNULL
,XMLDB_SEQUENCE
, null, null, null);
393 $f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR
, '100', null,
394 XMLDB_NOTNULL
, NULL, null, null, null);
395 $f = $table->addFieldInfo('mnet_host_id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
396 XMLDB_NOTNULL
, NULL, null, null, 0);
397 $f = $table->addFieldInfo('access', XMLDB_TYPE_CHAR
, '20', null,
398 XMLDB_NOTNULL
, NULL, null, null, 'allow');
400 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
401 $table->addIndexInfo('mnethostid_username', XMLDB_INDEX_UNIQUE
, array('mnet_host_id', 'username'));
403 $result = $result && create_table($table);
405 if (empty($USER->mnet_host_id
)) {
406 $USER->mnet_host_id
= $CFG->mnet_localhost_id
; // Something for the current user to prevent warnings
412 $table = new XMLDBTable('mnet_enrol_course');
413 $table->comment
= 'Information about courses on remote hosts';
414 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
415 XMLDB_NOTNULL
,XMLDB_SEQUENCE
, null, null, null);
416 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
417 XMLDB_NOTNULL
, NULL, null, null, 0);
418 $f = $table->addFieldInfo('remoteid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
419 XMLDB_NOTNULL
, NULL, null, null, 0);
420 $f = $table->addFieldInfo('cat_id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
421 XMLDB_NOTNULL
, NULL, null, null, 0);
422 $f = $table->addFieldInfo('cat_name', XMLDB_TYPE_CHAR
, '255', null,
423 XMLDB_NOTNULL
, NULL, null, null, null);
424 $f = $table->addFieldInfo('cat_description', XMLDB_TYPE_TEXT
, 'medium', null,
425 XMLDB_NOTNULL
, NULL, null, null, null);
426 $f = $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER
, '4', XMLDB_UNSIGNED
,
427 XMLDB_NOTNULL
, NULL, null, null, 0);
428 $f = $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR
, '254', null,
429 XMLDB_NOTNULL
, NULL, null, null, null);
430 $f = $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR
, '15', null,
431 XMLDB_NOTNULL
, NULL, null, null, null);
432 $f = $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR
, '100', null,
433 XMLDB_NOTNULL
, NULL, null, null, null);
434 $f = $table->addFieldInfo('summary', XMLDB_TYPE_TEXT
, 'medium', null,
435 XMLDB_NOTNULL
, NULL, null, null, null);
436 $f = $table->addFieldInfo('startdate', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
437 XMLDB_NOTNULL
, NULL, null, null, 0);
438 $f = $table->addFieldInfo('cost', XMLDB_TYPE_CHAR
, '10', null,
439 XMLDB_NOTNULL
, NULL, null, null, null);
440 $f = $table->addFieldInfo('currency', XMLDB_TYPE_CHAR
, '3', null,
441 XMLDB_NOTNULL
, NULL, null, null, null);
442 $f = $table->addFieldInfo('defaultroleid', XMLDB_TYPE_INTEGER
, '4', XMLDB_UNSIGNED
,
443 XMLDB_NOTNULL
, NULL, null, null, 0);
444 $f = $table->addFieldInfo('defaultrolename', XMLDB_TYPE_CHAR
, '255', null,
445 XMLDB_NOTNULL
, NULL, null, null, null);
447 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
448 $table->addIndexInfo('hostid_remoteid', XMLDB_INDEX_UNIQUE
, array('hostid', 'remoteid'));
450 $result = $result && create_table($table);
453 $table = new XMLDBTable('mnet_enrol_assignments');
455 $table->comment
= 'Information about enrolments on courses on remote hosts';
456 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
457 XMLDB_NOTNULL
,XMLDB_SEQUENCE
, null, null, null);
458 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
459 XMLDB_NOTNULL
, NULL, null, null, 0);
460 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
461 XMLDB_NOTNULL
, NULL, null, null, 0);
462 $f = $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
463 XMLDB_NOTNULL
, NULL, null, null, 0);
464 $f = $table->addFieldInfo('rolename', XMLDB_TYPE_CHAR
, '255', null,
465 XMLDB_NOTNULL
, NULL, null, null, null);
466 $f = $table->addFieldInfo('enroltime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
,
467 XMLDB_NOTNULL
, NULL, null, null, 0);
468 $f = $table->addFieldInfo('enroltype', XMLDB_TYPE_CHAR
, '20', null,
469 XMLDB_NOTNULL
, NULL, null, null, null);
472 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
473 $table->addIndexInfo('hostid_courseid', XMLDB_INDEX_NOTUNIQUE
, array('hostid', 'courseid'));
474 $table->addIndexInfo('userid', XMLDB_INDEX_NOTUNIQUE
, array('userid'));
476 $result = $result && create_table($table);
480 if ($result && $oldversion < 2007010404) {
482 /// Define field shortname to be added to user_info_field
483 $table = new XMLDBTable('user_info_field');
484 $field = new XMLDBField('shortname');
485 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, 'shortname', 'id');
487 /// Launch add field shortname
488 $result = $result && add_field($table, $field);
490 /// Changing type of field name on table user_info_field to text
491 $table = new XMLDBTable('user_info_field');
492 $field = new XMLDBField('name');
493 $field->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, XMLDB_NOTNULL
, null, null, null, null, 'shortname');
495 /// Launch change of type for field name
496 $result = $result && change_field_type($table, $field);
498 /// For existing fields use 'name' as the 'shortname' entry
499 if ($fields = get_records_select('user_info_field', '', '', 'id, name')) {
500 foreach ($fields as $field) {
501 $field->shortname
= clean_param($field->name
, PARAM_ALPHANUM
);
502 $result && update_record('user_info_field', $field);
507 if ($result && $oldversion < 2007011200) {
509 /// Define table context_rel to be created
510 $table = new XMLDBTable('context_rel');
512 /// Adding fields to table context_rel
513 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
514 $table->addFieldInfo('c1', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
515 $table->addFieldInfo('c2', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
517 /// Adding keys to table context_rel
518 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
519 $table->addKeyInfo('c1', XMLDB_KEY_FOREIGN
, array('c1'), 'context', array('id'));
520 $table->addKeyInfo('c2', XMLDB_KEY_FOREIGN
, array('c2'), 'context', array('id'));
521 $table->addKeyInfo('c1c2', XMLDB_KEY_UNIQUE
, array('c1', 'c2'));
523 /// Launch create table for context_rel
524 $result = $result && create_table($table);
526 /// code here to fill the context_rel table
527 /// use get record set to iterate slower
528 /// /deprecated and gone / build_context_rel();
531 if ($result && $oldversion < 2007011501) {
532 if (!empty($CFG->enablerecordcache
) && empty($CFG->rcache
) &&
533 // Note: won't force-load these settings into CFG
534 // we don't need or want cache during the upgrade itself
535 empty($CFG->cachetype
) && empty($CFG->intcachemax
)) {
536 set_config('cachetype', 'internal');
537 set_config('rcache', true);
538 set_config('intcachemax', $CFG->enablerecordcache
);
539 unset_config('enablerecordcache');
540 unset($CFG->enablerecordcache
);
544 if ($result && $oldversion < 2007012100) {
545 /// Some old PG servers have user->firstname & user->lastname with 30cc. They must be 100cc.
546 /// Fixing that conditionally. MDL-7110
547 if ($CFG->dbfamily
== 'postgres') {
548 /// Get Metadata from user table
549 $cols = array_change_key_case($db->MetaColumns($CFG->prefix
. 'user'), CASE_LOWER
);
551 /// Process user->firstname if needed
552 if ($col = $cols['firstname']) {
553 if ($col->max_length
< 100) {
554 /// Changing precision of field firstname on table user to (100)
555 $table = new XMLDBTable('user');
556 $field = new XMLDBField('firstname');
557 $field->setAttributes(XMLDB_TYPE_CHAR
, '100', null, XMLDB_NOTNULL
, null, null, null, null, 'idnumber');
559 /// Launch change of precision for field firstname
560 $result = $result && change_field_precision($table, $field);
564 /// Process user->lastname if needed
565 if ($col = $cols['lastname']) {
566 if ($col->max_length
< 100) {
567 /// Changing precision of field lastname on table user to (100)
568 $table = new XMLDBTable('user');
569 $field = new XMLDBField('lastname');
570 $field->setAttributes(XMLDB_TYPE_CHAR
, '100', null, XMLDB_NOTNULL
, null, null, null, null, 'firstname');
572 /// Launch change of precision for field lastname
573 $result = $result && change_field_precision($table, $field);
579 if ($result && $oldversion < 2007012101) {
581 /// Changing precision of field lang on table course to (30)
582 $table = new XMLDBTable('course');
583 $field = new XMLDBField('lang');
584 $field->setAttributes(XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, null, 'groupmodeforce');
586 /// Launch change of precision for field course->lang
587 $result = $result && change_field_precision($table, $field);
589 /// Changing precision of field lang on table user to (30)
590 $table = new XMLDBTable('user');
591 $field = new XMLDBField('lang');
592 $field->setAttributes(XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, 'en', 'country');
594 /// Launch change of precision for field user->lang
595 $result = $result && change_field_precision($table, $field);
598 if ($result && $oldversion < 2007012400) {
600 /// Rename field access on table mnet_sso_access_control to accessctrl
601 $table = new XMLDBTable('mnet_sso_access_control');
602 $field = new XMLDBField('access');
603 $field->setAttributes(XMLDB_TYPE_CHAR
, '20', null, XMLDB_NOTNULL
, null, null, null, 'allow', 'mnet_host_id');
605 /// Launch rename field accessctrl
606 $result = $result && rename_field($table, $field, 'accessctrl');
609 if ($result && $oldversion < 2007012500) {
610 execute_sql("DELETE FROM {$CFG->prefix}user WHERE username='changeme'", true);
613 if ($result && $oldversion < 2007020400) {
614 /// Only for MySQL and PG, declare the user->ajax field as not null. MDL-8421.
615 if ($CFG->dbfamily
== 'mysql' ||
$CFG->dbfamily
== 'postgres') {
616 /// Changing nullability of field ajax on table user to not null
617 $table = new XMLDBTable('user');
618 $field = new XMLDBField('ajax');
619 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '1', 'htmleditor');
621 /// Launch change of nullability for field ajax
622 $result = $result && change_field_notnull($table, $field);
626 if (!empty($CFG->rolesactive
) && $result && $oldversion < 2007021401) {
627 /// create default logged in user role if not present - upgrade rom 1.7.x
628 if (empty($CFG->defaultuserroleid
) or empty($CFG->guestroleid
) or $CFG->defaultuserroleid
== $CFG->guestroleid
) {
629 if (!get_records('role', 'shortname', 'user')) {
630 $userroleid = create_role(addslashes(get_string('authenticateduser')), 'user',
631 addslashes(get_string('authenticateduserdescription')), 'moodle/legacy:user');
633 reset_role_capabilities($userroleid);
634 set_config('defaultuserroleid', $userroleid);
640 if ($result && $oldversion < 2007021501) {
641 /// delete removed setting from config
642 unset_config('tabselectedtofront');
646 if ($result && $oldversion < 2007032200) {
648 /// Define table role_sortorder to be created
649 $table = new XMLDBTable('role_sortorder');
651 /// Adding fields to table role_sortorder
652 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
653 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
654 $table->addFieldInfo('roleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
655 $table->addFieldInfo('contextid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
656 $table->addFieldInfo('sortoder', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, null);
658 /// Adding keys to table role_sortorder
659 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
660 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
661 $table->addKeyInfo('roleid', XMLDB_KEY_FOREIGN
, array('roleid'), 'role', array('id'));
662 $table->addKeyInfo('contextid', XMLDB_KEY_FOREIGN
, array('contextid'), 'context', array('id'));
664 /// Adding indexes to table role_sortorder
665 $table->addIndexInfo('userid-roleid-contextid', XMLDB_INDEX_UNIQUE
, array('userid', 'roleid', 'contextid'));
667 /// Launch create table for role_sortorder
668 $result = $result && create_table($table);
672 /// code to change lenghen tag field to 255, MDL-9095
673 if ($result && $oldversion < 2007040400) {
675 /// Define index text (not unique) to be dropped form tags
676 $table = new XMLDBTable('tags');
677 $index = new XMLDBIndex('text');
678 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('text'));
680 /// Launch drop index text
681 $result = $result && drop_index($table, $index);
683 $field = new XMLDBField('text');
684 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null, 'userid');
686 /// Launch change of type for field text
687 $result = $result && change_field_type($table, $field);
689 $index = new XMLDBIndex('text');
690 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('text'));
692 /// Launch add index text
693 $result = $result && add_index($table, $index);
696 if ($result && $oldversion < 2007041100) {
698 /// Define field idnumber to be added to course_modules
699 $table = new XMLDBTable('course_modules');
700 $field = new XMLDBField('idnumber');
701 $field->setAttributes(XMLDB_TYPE_CHAR
, '100', null, null, null, null, null, null, 'section');
703 /// Launch add field idnumber
704 $result = $result && add_field($table, $field);
706 /// Define index idnumber (unique) to be added to course_modules
707 $table = new XMLDBTable('course_modules');
708 $index = new XMLDBIndex('idnumber');
709 $index->setAttributes(XMLDB_INDEX_UNIQUE
, array('idnumber'));
711 /// Launch add index idnumber
712 $result = $result && add_index($table, $index);
716 /* Changes to the custom profile menu type - store values rather than indices.
717 We could do all this with one tricky SQL statement but it's a one-off so no
718 harm in using PHP loops */
719 if ($result && $oldversion < 2007041600) {
721 /// Get the menu fields
722 if ($fields = get_records('user_info_field', 'datatype', 'menu')) {
723 foreach ($fields as $field) {
725 /// Get user data for the menu field
726 if ($data = get_records('user_info_data', 'fieldid', $field->id
)) {
728 /// Get the menu options
729 $options = explode("\n", $field->param1
);
730 foreach ($data as $d) {
731 $key = array_search($d->data
, $options);
733 /// If the data is an integer and is not one of the options,
734 /// set the respective option value
735 if (is_int($d->data
) and (($key === NULL) or ($key === false)) and isset($options[$d->data
])) {
736 $d->data
= $options[$d->data
];
737 $result = $result && update_record('user_info_data', $d);
746 /// adding new gradebook tables
747 if ($result && $oldversion < 2007041800) {
749 /// Define table events_handlers to be created
750 $table = new XMLDBTable('events_handlers');
752 /// Adding fields to table events_handlers
753 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
754 $table->addFieldInfo('eventname', XMLDB_TYPE_CHAR
, '166', null, XMLDB_NOTNULL
, null, null, null, null);
755 $table->addFieldInfo('handlermodule', XMLDB_TYPE_CHAR
, '166', null, XMLDB_NOTNULL
, null, null, null, null);
756 $table->addFieldInfo('handlerfile', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
757 $table->addFieldInfo('handlerfunction', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
759 /// Adding keys to table events_handlers
760 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
762 /// Adding indexes to table events_handlers
763 $table->addIndexInfo('eventname-handlermodule', XMLDB_INDEX_UNIQUE
, array('eventname', 'handlermodule'));
765 /// Launch create table for events_handlers
766 $result = $result && create_table($table);
768 /// Define table events_queue to be created
769 $table = new XMLDBTable('events_queue');
771 /// Adding fields to table events_queue
772 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
773 $table->addFieldInfo('eventdata', XMLDB_TYPE_TEXT
, 'big', null, XMLDB_NOTNULL
, null, null, null, null);
774 $table->addFieldInfo('schedule', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
775 $table->addFieldInfo('stackdump', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
776 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
777 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
779 /// Adding keys to table events_queue
780 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
781 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
783 /// Launch create table for events_queue
784 $result = $result && create_table($table);
786 /// Define table events_queue_handlers to be created
787 $table = new XMLDBTable('events_queue_handlers');
789 /// Adding fields to table events_queue_handlers
790 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
791 $table->addFieldInfo('queuedeventid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
792 $table->addFieldInfo('handlerid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
793 $table->addFieldInfo('status', XMLDB_TYPE_INTEGER
, '10', null, null, null, null, null, null);
794 $table->addFieldInfo('errormessage', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
795 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
797 /// Adding keys to table events_queue_handlers
798 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
799 $table->addKeyInfo('queuedeventid', XMLDB_KEY_FOREIGN
, array('queuedeventid'), 'events_queue', array('id'));
800 $table->addKeyInfo('handlerid', XMLDB_KEY_FOREIGN
, array('handlerid'), 'events_handlers', array('id'));
802 /// Launch create table for events_queue_handlers
803 $result = $result && create_table($table);
807 if ($result && $oldversion < 2007043001) {
809 /// Define field schedule to be added to events_handlers
810 $table = new XMLDBTable('events_handlers');
811 $field = new XMLDBField('schedule');
812 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null, 'handlerfunction');
814 /// Launch add field schedule
815 $result = $result && add_field($table, $field);
817 /// Define field status to be added to events_handlers
818 $table = new XMLDBTable('events_handlers');
819 $field = new XMLDBField('status');
820 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'schedule');
822 /// Launch add field status
823 $result = $result && add_field($table, $field);
826 if ($result && $oldversion < 2007050201) {
828 /// Define field theme to be added to course_categories
829 $table = new XMLDBTable('course_categories');
830 $field = new XMLDBField('theme');
831 $field->setAttributes(XMLDB_TYPE_CHAR
, '50', null, null, null, null, null, null, 'path');
833 /// Launch add field theme
834 $result = $result && add_field($table, $field);
837 if ($result && $oldversion < 2007051100) {
839 /// Define field forceunique to be added to user_info_field
840 $table = new XMLDBTable('user_info_field');
841 $field = new XMLDBField('forceunique');
842 $field->setAttributes(XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'visible');
844 /// Launch add field forceunique
845 $result = $result && add_field($table, $field);
847 /// Define field signup to be added to user_info_field
848 $table = new XMLDBTable('user_info_field');
849 $field = new XMLDBField('signup');
850 $field->setAttributes(XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'forceunique');
852 /// Launch add field signup
853 $result = $result && add_field($table, $field);
856 if (!empty($CFG->rolesactive
) && $result && $oldversion < 2007051801) {
857 // Get the role id of the "Auth. User" role and check if the default role id is different
858 // note: use of assign_capability() is discouraged in upgrade script!
859 $userrole = get_record( 'role', 'shortname', 'user' );
860 $defaultroleid = $CFG->defaultuserroleid
;
862 if( $defaultroleid != $userrole->id
) {
863 // Add in the new moodle/my:manageblocks capibility to the default user role
864 $context = get_context_instance(CONTEXT_SYSTEM
, SITEID
);
865 assign_capability('moodle/my:manageblocks',CAP_ALLOW
,$defaultroleid,$context->id
);
869 if ($result && $oldversion < 2007052200) {
871 /// Define field schedule to be dropped from events_queue
872 $table = new XMLDBTable('events_queue');
873 $field = new XMLDBField('schedule');
875 /// Launch drop field stackdump
876 $result = $result && drop_field($table, $field);
879 if ($result && $oldversion < 2007052300) {
880 require_once($CFG->dirroot
. '/question/upgrade.php');
881 $result = $result && question_remove_rqp_qtype();
884 if ($result && $oldversion < 2007060500) {
886 /// Define field usermodified to be added to post
887 $table = new XMLDBTable('post');
888 $field = new XMLDBField('usermodified');
889 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null, 'created');
891 /// Launch add field usermodified
892 $result = $result && add_field($table, $field);
894 /// Define key usermodified (foreign) to be added to post
895 $table = new XMLDBTable('post');
896 $key = new XMLDBKey('usermodified');
897 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
899 /// Launch add key usermodified
900 $result = $result && add_key($table, $key);
903 if ($result && $oldversion < 2007070603) {
904 // Small update of guest user to be 100% sure it has the correct mnethostid (MDL-10375)
905 set_field('user', 'mnethostid', $CFG->mnet_localhost_id
, 'username', 'guest');
908 if ($result && $oldversion < 2007071400) {
910 ** mnet application table
912 $table = new XMLDBTable('mnet_application');
913 $table->comment
= 'Information about applications on remote hosts';
914 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', false,
915 XMLDB_NOTNULL
,XMLDB_SEQUENCE
, null, null, null);
916 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '50', null,
917 XMLDB_NOTNULL
, NULL, null, null, null);
918 $f = $table->addFieldInfo('display_name', XMLDB_TYPE_CHAR
, '50', null,
919 XMLDB_NOTNULL
, NULL, null, null, null);
920 $f = $table->addFieldInfo('xmlrpc_server_url', XMLDB_TYPE_CHAR
, '255', null,
921 XMLDB_NOTNULL
, NULL, null, null, null);
922 $f = $table->addFieldInfo('sso_land_url', XMLDB_TYPE_CHAR
, '255', null,
923 XMLDB_NOTNULL
, NULL, null, null, null);
926 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
928 $result = $result && create_table($table);
930 // Insert initial applications (moodle and mahara)
931 $application = new stdClass();
932 $application->name
= 'moodle';
933 $application->display_name
= 'Moodle';
934 $application->xmlrpc_server_url
= '/mnet/xmlrpc/server.php';
935 $application->sso_land_url
= '/auth/mnet/land.php';
937 $newid = insert_record('mnet_application', $application, false);
940 $application = new stdClass();
941 $application->name
= 'mahara';
942 $application->display_name
= 'Mahara';
943 $application->xmlrpc_server_url
= '/api/xmlrpc/server.php';
944 $application->sso_land_url
= '/auth/xmlrpc/land.php';
945 $result = $result && insert_record('mnet_application', $application, false);
947 // New mnet_host->applicationid field
948 $table = new XMLDBTable('mnet_host');
949 $field = new XMLDBField('applicationid');
950 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, $newid , 'last_log_id');
952 $result = $result && add_field($table, $field);
954 /// Define key applicationid (foreign) to be added to mnet_host
955 $table = new XMLDBTable('mnet_host');
956 $key = new XMLDBKey('applicationid');
957 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('applicationid'), 'mnet_application', array('id'));
959 /// Launch add key applicationid
960 $result = $result && add_key($table, $key);
964 if ($result && $oldversion < 2007071607) {
965 require_once($CFG->dirroot
. '/question/upgrade.php');
966 $result = $result && question_remove_rqp_qtype_config_string();
969 if ($result && $oldversion < 2007072200) {
971 /// Remove all grade tables used in development phases - we need new empty tables for final gradebook upgrade
972 $tables = array('grade_categories',
974 'grade_calculations',
977 'grade_grades_final',
980 'grade_outcomes_courses',
982 'grade_import_newitem',
983 'grade_import_values');
985 foreach ($tables as $table) {
986 $table = new XMLDBTable($table);
987 if (table_exists($table)) {
992 $tables = array('grade_categories_history',
993 'grade_items_history',
994 'grade_grades_history',
995 'grade_grades_text_history',
996 'grade_scale_history',
997 'grade_outcomes_history');
999 foreach ($tables as $table) {
1000 $table = new XMLDBTable($table);
1001 if (table_exists($table)) {
1007 /// Define table grade_outcomes to be created
1008 $table = new XMLDBTable('grade_outcomes');
1010 /// Adding fields to table grade_outcomes
1011 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1012 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1013 $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1014 $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
1015 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1016 $table->addFieldInfo('description', XMLDB_TYPE_TEXT
, 'small', null, null, null, null, null, null);
1017 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1018 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1019 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1021 /// Adding keys to table grade_outcomes
1022 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1023 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1024 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
1025 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
1027 /// Launch create table for grade_outcomes
1028 $result = $result && create_table($table);
1031 /// Define table grade_categories to be created
1032 $table = new XMLDBTable('grade_categories');
1034 /// Adding fields to table grade_categories
1035 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1036 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1037 $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1038 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1039 $table->addFieldInfo('path', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1040 $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1041 $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1042 $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1043 $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1044 $table->addFieldInfo('aggregateonlygraded', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1045 $table->addFieldInfo('aggregateoutcomes', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1046 $table->addFieldInfo('aggregatesubcats', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1047 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1048 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1050 /// Adding keys to table grade_categories
1051 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1052 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1053 $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN
, array('parent'), 'grade_categories', array('id'));
1055 /// Launch create table for grade_categories
1056 $result = $result && create_table($table);
1059 /// Define table grade_items to be created
1060 $table = new XMLDBTable('grade_items');
1062 /// Adding fields to table grade_items
1063 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1064 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1065 $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1066 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1067 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, null);
1068 $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR
, '30', null, null, null, null, null, null);
1069 $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1070 $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1071 $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1072 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1073 $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1074 $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '1');
1075 $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
1076 $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1077 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1078 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1079 $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1080 $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '1.0');
1081 $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1082 $table->addFieldInfo('aggregationcoef', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1083 $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1084 $table->addFieldInfo('display', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1085 $table->addFieldInfo('decimals', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, null, null, null, null, null);
1086 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1087 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1088 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1089 $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1090 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1091 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1093 /// Adding keys to table grade_items
1094 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1095 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1096 $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN
, array('categoryid'), 'grade_categories', array('id'));
1097 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
1098 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN
, array('outcomeid'), 'grade_outcomes', array('id'));
1100 /// Adding indexes to table grade_grades
1101 $table->addIndexInfo('locked-locktime', XMLDB_INDEX_NOTUNIQUE
, array('locked', 'locktime'));
1102 $table->addIndexInfo('itemtype-needsupdate', XMLDB_INDEX_NOTUNIQUE
, array('itemtype', 'needsupdate'));
1103 $table->addIndexInfo('gradetype', XMLDB_INDEX_NOTUNIQUE
, array('gradetype'));
1105 /// Launch create table for grade_items
1106 $result = $result && create_table($table);
1109 /// Define table grade_grades to be created
1110 $table = new XMLDBTable('grade_grades');
1112 /// Adding fields to table grade_grades
1113 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1114 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1115 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1116 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
1117 $table->addFieldInfo('rawgrademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
1118 $table->addFieldInfo('rawgrademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1119 $table->addFieldInfo('rawscaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1120 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1121 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
1122 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1123 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1124 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1125 $table->addFieldInfo('exported', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1126 $table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1127 $table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1128 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT
, 'medium', XMLDB_UNSIGNED
, null, null, null, null, null);
1129 $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1130 $table->addFieldInfo('information', XMLDB_TYPE_TEXT
, 'medium', XMLDB_UNSIGNED
, null, null, null, null, null);
1131 $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1132 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1133 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1135 /// Adding keys to table grade_grades
1136 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1137 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN
, array('itemid'), 'grade_items', array('id'));
1138 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
1139 $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN
, array('rawscaleid'), 'scale', array('id'));
1140 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
1142 /// Adding indexes to table grade_grades
1143 $table->addIndexInfo('locked-locktime', XMLDB_INDEX_NOTUNIQUE
, array('locked', 'locktime'));
1145 /// Launch create table for grade_grades
1146 $result = $result && create_table($table);
1149 /// Define table grade_outcomes_history to be created
1150 $table = new XMLDBTable('grade_outcomes_history');
1152 /// Adding fields to table grade_outcomes_history
1153 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1154 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1155 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1156 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1157 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1158 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1159 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1160 $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1161 $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
1162 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1163 $table->addFieldInfo('description', XMLDB_TYPE_TEXT
, 'small', null, null, null, null, null, null);
1165 /// Adding keys to table grade_outcomes_history
1166 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1167 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_outcomes', array('id'));
1168 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1169 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
1170 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN
, array('loggeduser'), 'user', array('id'));
1172 /// Adding indexes to table grade_outcomes_history
1173 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1175 /// Launch create table for grade_outcomes_history
1176 $result = $result && create_table($table);
1179 /// Define table grade_categories_history to be created
1180 $table = new XMLDBTable('grade_categories_history');
1182 /// Adding fields to table grade_categories_history
1183 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1184 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1185 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1186 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1187 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1188 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1189 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1190 $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1191 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1192 $table->addFieldInfo('path', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1193 $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1194 $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1195 $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1196 $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1197 $table->addFieldInfo('aggregateonlygraded', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1198 $table->addFieldInfo('aggregateoutcomes', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1199 $table->addFieldInfo('aggregatesubcats', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1201 /// Adding keys to table grade_categories_history
1202 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1203 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_categories', array('id'));
1204 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1205 $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN
, array('parent'), 'grade_categories', array('id'));
1206 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN
, array('loggeduser'), 'user', array('id'));
1208 /// Adding indexes to table grade_categories_history
1209 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1211 /// Launch create table for grade_categories_history
1212 $result = $result && create_table($table);
1215 /// Define table grade_items_history to be created
1216 $table = new XMLDBTable('grade_items_history');
1218 /// Adding fields to table grade_items_history
1219 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1220 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1221 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1222 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1223 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1224 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1225 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1226 $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1227 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1228 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, null);
1229 $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR
, '30', null, null, null, null, null, null);
1230 $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1231 $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1232 $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1233 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1234 $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1235 $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER
, '4', null, XMLDB_NOTNULL
, null, null, null, '1');
1236 $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
1237 $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1238 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1239 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1240 $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1241 $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '1.0');
1242 $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1243 $table->addFieldInfo('aggregationcoef', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1244 $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1245 $table->addFieldInfo('display', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1246 $table->addFieldInfo('decimals', XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, null, null, null, null, null);
1247 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1248 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1249 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1250 $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0');
1252 /// Adding keys to table grade_items_history
1253 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1254 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_items', array('id'));
1255 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1256 $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN
, array('categoryid'), 'grade_categories', array('id'));
1257 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN
, array('scaleid'), 'scale', array('id'));
1258 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN
, array('outcomeid'), 'grade_outcomes', array('id'));
1259 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN
, array('loggeduser'), 'user', array('id'));
1261 /// Adding indexes to table grade_items_history
1262 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1264 /// Launch create table for grade_items_history
1265 $result = $result && create_table($table);
1268 /// Define table grade_grades_history to be created
1269 $table = new XMLDBTable('grade_grades_history');
1271 /// Adding fields to table grade_grades_history
1272 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1273 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1274 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1275 $table->addFieldInfo('source', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1276 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1277 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1278 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1279 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1280 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
1281 $table->addFieldInfo('rawgrademax', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '100');
1282 $table->addFieldInfo('rawgrademin', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1283 $table->addFieldInfo('rawscaleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1284 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1285 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, null, null, null, null, null);
1286 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1287 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1288 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1289 $table->addFieldInfo('exported', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1290 $table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1291 $table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1292 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT
, 'medium', XMLDB_UNSIGNED
, null, null, null, null, null);
1293 $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1294 $table->addFieldInfo('information', XMLDB_TYPE_TEXT
, 'medium', XMLDB_UNSIGNED
, null, null, null, null, null);
1295 $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
1297 /// Adding keys to table grade_grades_history
1298 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1299 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN
, array('oldid'), 'grade_grades', array('id'));
1300 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN
, array('itemid'), 'grade_items', array('id'));
1301 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
1302 $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN
, array('rawscaleid'), 'scale', array('id'));
1303 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN
, array('usermodified'), 'user', array('id'));
1304 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN
, array('loggeduser'), 'user', array('id'));
1306 /// Adding indexes to table grade_grades_history
1307 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE
, array('action'));
1309 /// Launch create table for grade_grades_history
1310 $result = $result && create_table($table);
1313 /// Define table grade_import_newitem to be created
1314 $table = new XMLDBTable('grade_import_newitem');
1316 /// Adding fields to table grade_import_newitem
1317 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1318 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1319 $table->addFieldInfo('import_code', XMLDB_TYPE_INTEGER
, '12', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1321 /// Adding keys to table grade_import_newitem
1322 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1324 /// Launch create table for grade_import_newitem
1325 $result = $result && create_table($table);
1328 /// Define table grade_import_values to be created
1329 $table = new XMLDBTable('grade_import_values');
1331 /// Adding fields to table grade_import_values
1332 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1333 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1334 $table->addFieldInfo('newgradeitem', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1335 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1336 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER
, '10, 5', null, XMLDB_NOTNULL
, null, null, null, '0');
1337 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT
, 'medium', null, null, null, null, null, null);
1338 $table->addFieldInfo('import_code', XMLDB_TYPE_INTEGER
, '12', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1340 /// Adding keys to table grade_import_values
1341 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1342 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN
, array('itemid'), 'grade_items', array('id'));
1343 $table->addKeyInfo('newgradeitem', XMLDB_KEY_FOREIGN
, array('newgradeitem'), 'grade_import_newitem', array('id'));
1345 /// Launch create table for grade_import_values
1346 $result = $result && create_table($table);
1348 /// upgrade the old 1.8 gradebook - migrade data into new grade tables
1350 require_once($CFG->libdir
.'/db/upgradelib.php');
1351 if ($rs = get_recordset('course')) {
1352 if ($rs->RecordCount() > 0) {
1353 while ($course = rs_fetch_next_record($rs)) {
1354 // this function uses SQL only, it must not be changed after 1.9 goes stable!!
1355 if (!upgrade_18_gradebook($course->id
)) {
1365 /// migrate grade letter table
1366 $result = $result && upgrade_18_letters();
1369 if ($result && $oldversion < 2007072400) {
1370 /// Dropping one DEFAULT in a TEXT column. It's was only one remaining
1371 /// since Moodle 1.7, so new servers won't have those anymore.
1373 /// Changing the default of field sessdata on table sessions2 to drop it
1374 $table = new XMLDBTable('sessions2');
1375 $field = new XMLDBField('sessdata');
1376 $field->setAttributes(XMLDB_TYPE_TEXT
, 'big', null, null, null, null, null, null, 'modified');
1378 /// Launch change of default for field sessdata
1379 $result = $result && change_field_default($table, $field);
1383 if ($result && $oldversion < 2007073100) {
1384 /// Define table grade_outcomes_courses to be created
1385 $table = new XMLDBTable('grade_outcomes_courses');
1387 /// Adding fields to table grade_outcomes_courses
1388 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1389 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1390 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1392 /// Adding keys to table grade_outcomes_courses
1393 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1394 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN
, array('courseid'), 'course', array('id'));
1395 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN
, array('outcomeid'), 'grade_outcomes', array('id'));
1396 $table->addKeyInfo('courseid-outcomeid', XMLDB_KEY_UNIQUE
, array('courseid', 'outcomeid'));
1397 /// Launch create table for grade_outcomes_courses
1398 $result = $result && create_table($table);
1403 if ($result && $oldversion < 2007073101) { // Add new tag tables
1405 /// Define table tag to be created
1406 $table = new XMLDBTable('tag');
1408 /// Adding fields to table tag
1409 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '11', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1410 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '11', null, XMLDB_NOTNULL
, null, null, null, null);
1411 $table->addFieldInfo('name', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1412 $table->addFieldInfo('tagtype', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1413 $table->addFieldInfo('description', XMLDB_TYPE_TEXT
, 'small', null, null, null, null, null, null);
1414 $table->addFieldInfo('descriptionformat', XMLDB_TYPE_INTEGER
, '2', null, XMLDB_NOTNULL
, null, null, null, null);
1415 $table->addFieldInfo('flag', XMLDB_TYPE_INTEGER
, '4', XMLDB_UNSIGNED
, null, null, null, null, '0');
1416 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1418 /// Adding keys to table tag
1419 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1421 /// Adding indexes to table tag
1422 $table->addIndexInfo('name', XMLDB_INDEX_UNIQUE
, array('name'));
1424 /// Launch create table for tag
1425 $result = $result && create_table($table);
1429 /// Define table tag_correlation to be created
1430 $table = new XMLDBTable('tag_correlation');
1432 /// Adding fields to table tag_correlation
1433 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '11', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1434 $table->addFieldInfo('tagid', XMLDB_TYPE_INTEGER
, '11', null, XMLDB_NOTNULL
, null, null, null, null);
1435 $table->addFieldInfo('correlatedtags', XMLDB_TYPE_TEXT
, 'small', null, XMLDB_NOTNULL
, null, null, null, null);
1437 /// Adding keys to table tag_correlation
1438 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1440 /// Adding indexes to table tag_correlation
1441 $table->addIndexInfo('tagid', XMLDB_INDEX_UNIQUE
, array('tagid'));
1443 /// Launch create table for tag_correlation
1444 $result = $result && create_table($table);
1448 /// Define table tag_instance to be created
1449 $table = new XMLDBTable('tag_instance');
1451 /// Adding fields to table tag_instance
1452 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '11', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1453 $table->addFieldInfo('tagid', XMLDB_TYPE_INTEGER
, '11', null, XMLDB_NOTNULL
, null, null, null, null);
1454 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
1455 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER
, '11', null, XMLDB_NOTNULL
, null, null, null, null);
1457 /// Adding keys to table tag_instance
1458 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1460 /// Adding indexes to table tag_instance
1461 $table->addIndexInfo('tagiditem', XMLDB_INDEX_NOTUNIQUE
, array('tagid', 'itemtype', 'itemid'));
1463 /// Launch create table for tag_instance
1464 $result = $result && create_table($table);
1469 if ($result && $oldversion < 2007073103) {
1471 /// Define field rawname to be added to tag
1472 $table = new XMLDBTable('tag');
1473 $field = new XMLDBField('rawname');
1474 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null, 'name');
1476 /// Launch add field rawname
1477 $result = $result && add_field($table, $field);
1480 if ($result && $oldversion < 2007073105) {
1482 /// Define field description to be added to grade_outcomes
1483 $table = new XMLDBTable('grade_outcomes');
1484 $field = new XMLDBField('description');
1485 if (!field_exists($table, $field)) {
1486 $field->setAttributes(XMLDB_TYPE_TEXT
, 'small', null, null, null, null, null, null, 'scaleid');
1487 /// Launch add field description
1488 $result = $result && add_field($table, $field);
1491 $table = new XMLDBTable('grade_outcomes_history');
1492 $field = new XMLDBField('description');
1493 if (!field_exists($table, $field)) {
1494 $field->setAttributes(XMLDB_TYPE_TEXT
, 'small', null, null, null, null, null, null, 'scaleid');
1495 /// Launch add field description
1496 $result = $result && add_field($table, $field);
1500 // adding unique contraint on (courseid,shortname) of an outcome
1501 if ($result && $oldversion < 2007080100) {
1503 /// Define key courseid-shortname (unique) to be added to grade_outcomes
1504 $table = new XMLDBTable('grade_outcomes');
1505 $key = new XMLDBKey('courseid-shortname');
1506 $key->setAttributes(XMLDB_KEY_UNIQUE
, array('courseid', 'shortname'));
1508 /// Launch add key courseid-shortname
1509 $result = $result && add_key($table, $key);
1512 if ($result && $oldversion < 2007080101) {
1513 if ($firstadmin = get_admin()) { // the person currently used for support emails
1514 set_config('supportname', s(fullname($firstadmin))); // New settings same as old
1515 set_config('supportemail', s($firstadmin->email
));
1519 /// MDL-10679, context_rel clean up
1520 if ($result && $oldversion < 2007080200) {
1521 delete_records('context_rel');
1522 /// /deprecated and gone / build_context_rel();
1525 if ($result && $oldversion < 2007080202) {
1527 /// Define index tagiditem (not unique) to be dropped form tag_instance
1528 $table = new XMLDBTable('tag_instance');
1529 $index = new XMLDBIndex('tagiditem');
1530 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('tagid', 'itemtype', 'itemid'));
1532 /// Launch drop index tagiditem
1533 drop_index($table, $index);
1535 /// Define index tagiditem (unique) to be added to tag_instance
1536 $table = new XMLDBTable('tag_instance');
1537 $index = new XMLDBIndex('tagiditem');
1538 $index->setAttributes(XMLDB_INDEX_UNIQUE
, array('tagid', 'itemtype', 'itemid'));
1540 /// Launch add index tagiditem
1541 $result = $result && add_index($table, $index);
1545 if ($result && $oldversion < 2007080300) {
1547 /// Define field aggregateoutcomes to be added to grade_categories
1548 $table = new XMLDBTable('grade_categories');
1549 $field = new XMLDBField('aggregateoutcomes');
1550 if (!field_exists($table, $field)) {
1551 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'droplow');
1553 /// Launch add field aggregateoutcomes
1554 $result = $result && add_field($table, $field);
1557 /// Define field aggregateoutcomes to be added to grade_categories
1558 $table = new XMLDBTable('grade_categories_history');
1559 $field = new XMLDBField('aggregateoutcomes');
1560 if (!field_exists($table, $field)) {
1561 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'droplow');
1563 /// Launch add field aggregateoutcomes
1564 $result = $result && add_field($table, $field);
1568 if ($result && $oldversion < 2007080800) { /// Normalize course->shortname MDL-10026
1570 /// Changing precision of field shortname on table course to (100)
1571 $table = new XMLDBTable('course');
1572 $field = new XMLDBField('shortname');
1573 $field->setAttributes(XMLDB_TYPE_CHAR
, '100', null, XMLDB_NOTNULL
, null, null, null, null, 'fullname');
1575 /// Launch change of precision for field shortname
1576 $result = $result && change_field_precision($table, $field);
1579 if ($result && $oldversion < 2007080900) {
1580 /// Add context.path & index
1581 $table = new XMLDBTable('context');
1582 $field = new XMLDBField('path');
1583 $field->setAttributes(XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null, 'instanceid');
1584 $result = $result && add_field($table, $field);
1585 $table = new XMLDBTable('context');
1586 $index = new XMLDBIndex('path');
1587 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('path'));
1588 $result = $result && add_index($table, $index);
1590 /// Add context.depth
1591 $table = new XMLDBTable('context');
1592 $field = new XMLDBField('depth');
1593 $field->setAttributes(XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'path');
1594 $result = $result && add_field($table, $field);
1597 if ($result && $oldversion < 2007080903) {
1599 $table = new XMLDBTable('grade_grades');
1600 $index = new XMLDBIndex('locked-locktime');
1601 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('locked', 'locktime'));
1603 if (!index_exists($table, $index)) {
1604 /// Launch add index
1605 $result = $result && add_index($table, $index);
1609 $table = new XMLDBTable('grade_items');
1610 $index = new XMLDBIndex('locked-locktime');
1611 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('locked', 'locktime'));
1613 if (!index_exists($table, $index)) {
1614 /// Launch add index
1615 $result = $result && add_index($table, $index);
1618 /// Define index itemtype-needsupdate (not unique) to be added to grade_items
1619 $table = new XMLDBTable('grade_items');
1620 $index = new XMLDBIndex('itemtype-needsupdate');
1621 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('itemtype', 'needsupdate'));
1622 if (!index_exists($table, $index)) {
1623 /// Launch add index itemtype-needsupdate
1624 $result = $result && add_index($table, $index);
1628 $table = new XMLDBTable('grade_items');
1629 $index = new XMLDBIndex('gradetype');
1630 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('gradetype'));
1632 if (!index_exists($table, $index)) {
1633 /// Launch add index
1634 $result = $result && add_index($table, $index);
1639 if ($result && $oldversion < 2007081000) {
1640 require_once($CFG->dirroot
. '/question/upgrade.php');
1641 $result = $result && question_upgrade_context_etc();
1644 if ($result && $oldversion < 2007081302) {
1645 require_once($CFG->libdir
.'/db/upgradelib.php');
1647 if (table_exists(new XMLDBTable('groups_groupings'))) {
1648 /// IF 'groups_groupings' table exists, this is for 1.8.* only.
1649 $result = $result && upgrade_18_groups();
1652 /// ELSE, 1.7.*/1.6.*/1.5.* - create 'groupings' and 'groupings_groups' + rename password to enrolmentkey
1653 $result = $result && upgrade_17_groups();
1656 /// For both 1.8.* and 1.7.*/1.6.*..
1658 // delete not used fields
1659 $table = new XMLDBTable('groups');
1660 $field = new XMLDBField('theme');
1661 if (field_exists($table, $field)) {
1662 drop_field($table, $field);
1664 $table = new XMLDBTable('groups');
1665 $field = new XMLDBField('lang');
1666 if (field_exists($table, $field)) {
1667 drop_field($table, $field);
1670 /// Add groupingid field/f.key to 'course' table.
1671 $table = new XMLDBTable('course');
1672 $field = new XMLDBField('defaultgroupingid');
1673 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', $prev='groupmodeforce');
1674 $result = $result && add_field($table, $field);
1677 /// Add grouping ID, grouponly field/f.key to 'course_modules' table.
1678 $table = new XMLDBTable('course_modules');
1679 $field = new XMLDBField('groupingid');
1680 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', $prev='groupmode');
1681 $result = $result && add_field($table, $field);
1683 $table = new XMLDBTable('course_modules');
1684 $field = new XMLDBField('groupmembersonly');
1685 $field->setAttributes(XMLDB_TYPE_INTEGER
, '4', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', $prev='groupingid');
1686 $result = $result && add_field($table, $field);
1688 $table = new XMLDBTable('course_modules');
1689 $key = new XMLDBKey('groupingid');
1690 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('groupingid'), 'groupings', array('id'));
1691 $result = $result && add_key($table, $key);
1695 if ($result && $oldversion < 2007082300) {
1697 /// Define field ordering to be added to tag_instance table
1698 $table = new XMLDBTable('tag_instance');
1699 $field = new XMLDBField('ordering');
1701 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'itemid');
1703 /// Launch add field rawname
1704 $result = $result && add_field($table, $field);
1707 if ($result && $oldversion < 2007082700) {
1709 /// Define field timemodified to be added to tag_instance
1710 $table = new XMLDBTable('tag_instance');
1711 $field = new XMLDBField('timemodified');
1712 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'ordering');
1714 /// Launch add field timemodified
1715 $result = $result && add_field($table, $field);
1718 /// migrate all tags table to tag - this code MUST use SQL only,
1719 /// because if the db structure changes the library functions will fail in future
1720 if ($result && $oldversion < 2007082701) {
1721 $tagrefs = array(); // $tagrefs[$oldtagid] = $newtagid
1722 if ($rs = get_recordset('tags')) {
1724 if ($rs->RecordCount() > 0) {
1725 while ($oldtag = rs_fetch_next_record($rs)) {
1726 $raw_normalized = clean_param($oldtag->text
, PARAM_TAG
);
1727 $normalized = moodle_strtolower($raw_normalized);
1728 // if this tag does not exist in tag table yet
1729 if (!$newtag = get_record('tag', 'name', $normalized, '', '', '', '', 'id')) {
1730 $itag = new object();
1731 $itag->name
= $normalized;
1732 $itag->rawname
= $raw_normalized;
1733 $itag->userid
= $oldtag->userid
;
1734 $itag->timemodified
= time();
1735 if ($oldtag->type
== 'official') {
1736 $itag->tagtype
= 'official';
1738 $itag->tagtype
= 'default';
1741 if ($idx = insert_record('tag', $itag)) {
1742 $tagrefs[$oldtag->id
] = $idx;
1744 // if this tag is already used by tag table
1746 $tagrefs[$oldtag->id
] = $newtag->id
;
1754 // fetch all the tag instances and migrate them as well
1755 if ($rs = get_recordset('blog_tag_instance')) {
1757 if ($rs->RecordCount() > 0) {
1758 while ($blogtag = rs_fetch_next_record($rs)) {
1759 if (array_key_exists($blogtag->tagid
, $tagrefs)) {
1760 $tag_instance = new object();
1761 $tag_instance->tagid
= $tagrefs[$blogtag->tagid
];
1762 $tag_instance->itemtype
= 'blog';
1763 $tag_instance->itemid
= $blogtag->entryid
;
1764 $tag_instance->ordering
= 1; // does not matter much, because originally there was no ordering in blogs
1765 $tag_instance->timemodified
= time();
1766 insert_record('tag_instance', $tag_instance);
1774 unset($tagrefs); // release memory
1776 $table = new XMLDBTable('tags');
1778 $table = new XMLDBTable('blog_tag_instance');
1782 /// MDL-11015, MDL-11016
1783 if ($result && $oldversion < 2007082800) {
1785 /// Changing type of field userid on table tag to int
1786 $table = new XMLDBTable('tag');
1787 $field = new XMLDBField('userid');
1788 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null, 'id');
1790 /// Launch change of type for field userid
1791 $result = $result && change_field_type($table, $field);
1793 /// Changing type of field descriptionformat on table tag to int
1794 $table = new XMLDBTable('tag');
1795 $field = new XMLDBField('descriptionformat');
1796 $field->setAttributes(XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'description');
1798 /// Launch change of type for field descriptionformat
1799 $result = $result && change_field_type($table, $field);
1801 /// Define key userid (foreign) to be added to tag
1802 $table = new XMLDBTable('tag');
1803 $key = new XMLDBKey('userid');
1804 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
1806 /// Launch add key userid
1807 $result = $result && add_key($table, $key);
1809 /// Define index tagiditem (unique) to be dropped form tag_instance
1810 $table = new XMLDBTable('tag_instance');
1811 $index = new XMLDBIndex('tagiditem');
1812 $index->setAttributes(XMLDB_INDEX_UNIQUE
, array('tagid', 'itemtype', 'itemid'));
1814 /// Launch drop index tagiditem
1815 $result = $result && drop_index($table, $index);
1817 /// Changing type of field tagid on table tag_instance to int
1818 $table = new XMLDBTable('tag_instance');
1819 $field = new XMLDBField('tagid');
1820 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null, 'id');
1822 /// Launch change of type for field tagid
1823 $result = $result && change_field_type($table, $field);
1825 /// Define key tagid (foreign) to be added to tag_instance
1826 $table = new XMLDBTable('tag_instance');
1827 $key = new XMLDBKey('tagid');
1828 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('tagid'), 'tag', array('id'));
1830 /// Launch add key tagid
1831 $result = $result && add_key($table, $key);
1833 /// Changing sign of field itemid on table tag_instance to unsigned
1834 $table = new XMLDBTable('tag_instance');
1835 $field = new XMLDBField('itemid');
1836 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null, 'itemtype');
1838 /// Launch change of sign for field itemid
1839 $result = $result && change_field_unsigned($table, $field);
1841 /// Changing sign of field ordering on table tag_instance to unsigned
1842 $table = new XMLDBTable('tag_instance');
1843 $field = new XMLDBField('ordering');
1844 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null, 'itemid');
1846 /// Launch change of sign for field ordering
1847 $result = $result && change_field_unsigned($table, $field);
1849 /// Define index itemtype-itemid-tagid (unique) to be added to tag_instance
1850 $table = new XMLDBTable('tag_instance');
1851 $index = new XMLDBIndex('itemtype-itemid-tagid');
1852 $index->setAttributes(XMLDB_INDEX_UNIQUE
, array('itemtype', 'itemid', 'tagid'));
1854 /// Launch add index itemtype-itemid-tagid
1855 $result = $result && add_index($table, $index);
1857 /// Define index tagid (unique) to be dropped form tag_correlation
1858 $table = new XMLDBTable('tag_correlation');
1859 $index = new XMLDBIndex('tagid');
1860 $index->setAttributes(XMLDB_INDEX_UNIQUE
, array('tagid'));
1862 /// Launch drop index tagid
1863 $result = $result && drop_index($table, $index);
1865 /// Changing type of field tagid on table tag_correlation to int
1866 $table = new XMLDBTable('tag_correlation');
1867 $field = new XMLDBField('tagid');
1868 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null, 'id');
1870 /// Launch change of type for field tagid
1871 $result = $result && change_field_type($table, $field);
1874 /// Define key tagid (foreign) to be added to tag_correlation
1875 $table = new XMLDBTable('tag_correlation');
1876 $key = new XMLDBKey('tagid');
1877 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('tagid'), 'tag', array('id'));
1879 /// Launch add key tagid
1880 $result = $result && add_key($table, $key);
1885 if ($result && $oldversion < 2007082801) {
1887 /// Define table user_private_key to be created
1888 $table = new XMLDBTable('user_private_key');
1890 /// Adding fields to table user_private_key
1891 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
1892 $table->addFieldInfo('script', XMLDB_TYPE_CHAR
, '128', null, XMLDB_NOTNULL
, null, null, null, null);
1893 $table->addFieldInfo('value', XMLDB_TYPE_CHAR
, '128', null, XMLDB_NOTNULL
, null, null, null, null);
1894 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
1895 $table->addFieldInfo('instance', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1896 $table->addFieldInfo('iprestriction', XMLDB_TYPE_CHAR
, '255', null, null, null, null, null, null);
1897 $table->addFieldInfo('validuntil', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1898 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, null, null, null, null, null);
1900 /// Adding keys to table user_private_key
1901 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
1902 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN
, array('userid'), 'user', array('id'));
1904 /// Adding indexes to table user_private_key
1905 $table->addIndexInfo('script-value', XMLDB_INDEX_NOTUNIQUE
, array('script', 'value'));
1907 /// Launch create table for user_private_key
1908 $result = $result && create_table($table);
1911 /// Going to modify the applicationid from int(1) to int(10). Dropping and
1912 /// re-creating the associated keys/indexes is mandatory to be cross-db. MDL-11042
1913 if ($result && $oldversion < 2007082803) {
1915 /// Define key applicationid (foreign) to be dropped form mnet_host
1916 $table = new XMLDBTable('mnet_host');
1917 $key = new XMLDBKey('applicationid');
1918 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('applicationid'), 'mnet_application', array('id'));
1920 /// Launch drop key applicationid
1921 $result = $result && drop_key($table, $key);
1923 /// Changing type of field applicationid on table mnet_host to int
1924 $field = new XMLDBField('applicationid');
1925 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '1', 'last_log_id');
1927 /// Launch change of type for field applicationid
1928 $result = $result && change_field_type($table, $field);
1930 /// Define key applicationid (foreign) to be added to mnet_host
1931 $key = new XMLDBKey('applicationid');
1932 $key->setAttributes(XMLDB_KEY_FOREIGN
, array('applicationid'), 'mnet_application', array('id'));
1934 /// Launch add key applicationid
1935 $result = $result && add_key($table, $key);
1939 if ($result && $oldversion < 2007090503) {
1940 /// Define field aggregatesubcats to be added to grade_categories
1941 $table = new XMLDBTable('grade_categories');
1942 $field = new XMLDBField('aggregatesubcats');
1943 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'aggregateoutcomes');
1945 if (!field_exists($table, $field)) {
1946 /// Launch add field aggregateonlygraded
1947 $result = $result && add_field($table, $field);
1950 /// Define field aggregateonlygraded to be added to grade_categories
1951 $table = new XMLDBTable('grade_categories');
1952 $field = new XMLDBField('aggregateonlygraded');
1953 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'droplow');
1955 if (!field_exists($table, $field)) {
1956 /// Launch add field aggregateonlygraded
1957 $result = $result && add_field($table, $field);
1960 /// Define field aggregatesubcats to be added to grade_categories_history
1961 $table = new XMLDBTable('grade_categories_history');
1962 $field = new XMLDBField('aggregatesubcats');
1963 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'aggregateoutcomes');
1965 if (!field_exists($table, $field)) {
1966 /// Launch add field aggregateonlygraded
1967 $result = $result && add_field($table, $field);
1970 /// Define field aggregateonlygraded to be added to grade_categories_history
1971 $table = new XMLDBTable('grade_categories_history');
1972 $field = new XMLDBField('aggregateonlygraded');
1973 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'droplow');
1975 if (!field_exists($table, $field)) {
1976 /// Launch add field aggregateonlygraded
1977 $result = $result && add_field($table, $field);
1980 /// upgrade path in grade_categrories table - now using slash on both ends
1981 $concat = sql_concat('path', "'/'");
1982 $sql = "UPDATE {$CFG->prefix}grade_categories SET path = $concat WHERE path NOT LIKE '/%/'";
1983 execute_sql($sql, true);
1985 /// convert old aggregation constants if needed
1986 for ($i=0; $i<=12; $i=$i+
2) {
1988 $sql = "UPDATE {$CFG->prefix}grade_categories SET aggregation = $i, aggregateonlygraded = 1 WHERE aggregation = $j";
1989 execute_sql($sql, true);
1993 /// To have UNIQUE indexes over NULLable columns isn't cross-db at all
1994 /// so we create a non unique index and programatically enforce uniqueness
1995 if ($result && $oldversion < 2007090600) {
1997 /// Define index idnumber (unique) to be dropped form course_modules
1998 $table = new XMLDBTable('course_modules');
1999 $index = new XMLDBIndex('idnumber');
2000 $index->setAttributes(XMLDB_INDEX_UNIQUE
, array('idnumber'));
2002 /// Launch drop index idnumber
2003 $result = $result && drop_index($table, $index);
2005 /// Define index idnumber-course (not unique) to be added to course_modules
2006 $table = new XMLDBTable('course_modules');
2007 $index = new XMLDBIndex('idnumber-course');
2008 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('idnumber', 'course'));
2010 /// Launch add index idnumber-course
2011 $result = $result && add_index($table, $index);
2013 /// Define index idnumber-courseid (not unique) to be added to grade_items
2014 $table = new XMLDBTable('grade_items');
2015 $index = new XMLDBIndex('idnumber-courseid');
2016 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('idnumber', 'courseid'));
2018 /// Launch add index idnumber-courseid
2019 $result = $result && add_index($table, $index);
2023 /// Create the permanent context_temp table to be used by build_context_path()
2024 if ($result && $oldversion < 2007092001) {
2026 /// Define table context_temp to be created
2027 $table = new XMLDBTable('context_temp');
2029 /// Adding fields to table context_temp
2030 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
2031 $table->addFieldInfo('path', XMLDB_TYPE_CHAR
, '255', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
2032 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, null);
2034 /// Adding keys to table context_temp
2035 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
2037 /// Launch create table for context_temp
2038 $result = $result && create_table($table);
2040 /// Recalculate depths, paths and so on
2042 build_context_path(true);
2043 load_all_capabilities();
2047 * Merging of grade_grades_text back into grade_grades
2049 if ($result && $oldversion < 2007092002) {
2051 /// Define field feedback to be added to grade_grades
2052 $table = new XMLDBTable('grade_grades');
2053 $field = new XMLDBField('feedback');
2054 $field->setAttributes(XMLDB_TYPE_TEXT
, 'medium', XMLDB_UNSIGNED
, null, null, null, null, null, 'excluded');
2056 if (!field_exists($table, $field)) {
2057 /// Launch add field feedback
2058 $result = $result && add_field($table, $field);
2061 /// Define field feedbackformat to be added to grade_grades
2062 $table = new XMLDBTable('grade_grades');
2063 $field = new XMLDBField('feedbackformat');
2064 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'feedback');
2066 if (!field_exists($table, $field)) {
2067 /// Launch add field feedbackformat
2068 $result = $result && add_field($table, $field);
2071 /// Define field information to be added to grade_grades
2072 $table = new XMLDBTable('grade_grades');
2073 $field = new XMLDBField('information');
2074 $field->setAttributes(XMLDB_TYPE_TEXT
, 'medium', XMLDB_UNSIGNED
, null, null, null, null, null, 'feedbackformat');
2076 if (!field_exists($table, $field)) {
2077 /// Launch add field information
2078 $result = $result && add_field($table, $field);
2081 /// Define field informationformat to be added to grade_grades
2082 $table = new XMLDBTable('grade_grades');
2083 $field = new XMLDBField('informationformat');
2084 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'information');
2086 if (!field_exists($table, $field)) {
2087 /// Launch add field informationformat
2088 $result = $result && add_field($table, $field);
2091 /// Define field feedback to be added to grade_grades_history
2092 $table = new XMLDBTable('grade_grades_history');
2093 $field = new XMLDBField('feedback');
2094 $field->setAttributes(XMLDB_TYPE_TEXT
, 'medium', XMLDB_UNSIGNED
, null, null, null, null, null, 'excluded');
2096 if (!field_exists($table, $field)) {
2097 /// Launch add field feedback
2098 $result = $result && add_field($table, $field);
2101 /// Define field feedbackformat to be added to grade_grades_history
2102 $table = new XMLDBTable('grade_grades_history');
2103 $field = new XMLDBField('feedbackformat');
2104 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'feedback');
2106 if (!field_exists($table, $field)) {
2107 /// Launch add field feedbackformat
2108 $result = $result && add_field($table, $field);
2111 /// Define field information to be added to grade_grades_history
2112 $table = new XMLDBTable('grade_grades_history');
2113 $field = new XMLDBField('information');
2114 $field->setAttributes(XMLDB_TYPE_TEXT
, 'medium', XMLDB_UNSIGNED
, null, null, null, null, null, 'feedbackformat');
2116 if (!field_exists($table, $field)) {
2117 /// Launch add field information
2118 $result = $result && add_field($table, $field);
2121 /// Define field informationformat to be added to grade_grades_history
2122 $table = new XMLDBTable('grade_grades_history');
2123 $field = new XMLDBField('informationformat');
2124 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'information');
2126 if (!field_exists($table, $field)) {
2127 /// Launch add field informationformat
2128 $result = $result && add_field($table, $field);
2131 $table = new XMLDBTable('grade_grades_text');
2132 if ($result and table_exists($table)) {
2133 //migrade existing data into grade_grades table - this is slow but works for all dbs,
2134 //it will be executed on development sites only
2135 $fields = array('feedback', 'information');
2136 foreach ($fields as $field) {
2137 $sql = "UPDATE {$CFG->prefix}grade_grades
2140 FROM {$CFG->prefix}grade_grades_text ggt
2141 WHERE ggt.gradeid = {$CFG->prefix}grade_grades.id)";
2142 $result = execute_sql($sql) && $result;
2144 $fields = array('feedbackformat', 'informationformat');
2145 foreach ($fields as $field) {
2146 $sql = "UPDATE {$CFG->prefix}grade_grades
2147 SET $field = COALESCE((
2149 FROM {$CFG->prefix}grade_grades_text ggt
2150 WHERE ggt.gradeid = {$CFG->prefix}grade_grades.id), 0)";
2151 $result = execute_sql($sql) && $result;
2155 $tables = array('grade_grades_text', 'grade_grades_text_history');
2157 foreach ($tables as $table) {
2158 $table = new XMLDBTable($table);
2159 if (table_exists($table)) {
2167 if ($result && $oldversion < 2007092803) {
2169 /// Remove obsoleted unit tests tables - they will be recreated automatically
2170 $tables = array('grade_categories',
2173 'grade_calculations',
2176 'grade_grades_final',
2177 'grade_grades_text',
2179 'grade_outcomes_courses');
2181 foreach ($tables as $tablename) {
2182 $table = new XMLDBTable('unittest_'.$tablename);
2183 if (table_exists($table)) {
2186 $table = new XMLDBTable('unittest_'.$tablename.'_history');
2187 if (table_exists($table)) {
2192 /// Define field display to be added to grade_items
2193 $table = new XMLDBTable('grade_items');
2194 $field = new XMLDBField('display');
2195 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0', 'sortorder');
2197 /// Launch add field display
2198 if (!field_exists($table, $field)) {
2199 $result = $result && add_field($table, $field);
2201 $result = $result && change_field_default($table, $field);
2204 /// Define field display to be added to grade_items_history
2205 $table = new XMLDBTable('grade_items_history');
2206 $field = new XMLDBField('display');
2207 $field->setAttributes(XMLDB_TYPE_INTEGER
, '10', null, XMLDB_NOTNULL
, null, null, null, '0', 'sortorder');
2209 /// Launch add field display
2210 if (!field_exists($table, $field)) {
2211 $result = $result && add_field($table, $field);
2215 /// Define field decimals to be added to grade_items
2216 $table = new XMLDBTable('grade_items');
2217 $field = new XMLDBField('decimals');
2218 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, null, null, null, null, null, 'display');
2220 /// Launch add field decimals
2221 if (!field_exists($table, $field)) {
2222 $result = $result && add_field($table, $field);
2224 $result = $result && change_field_default($table, $field);
2225 $result = $result && change_field_notnull($table, $field);
2228 /// Define field decimals to be added to grade_items_history
2229 $table = new XMLDBTable('grade_items_history');
2230 $field = new XMLDBField('decimals');
2231 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, null, null, null, null, null, 'display');
2233 /// Launch add field decimals
2234 if (!field_exists($table, $field)) {
2235 $result = $result && add_field($table, $field);
2239 /// fix incorrect -1 default for grade_item->display
2240 execute_sql("UPDATE {$CFG->prefix}grade_items SET display=0 WHERE display=-1");
2243 if ($result && $oldversion < 2007092806) {
2244 require_once($CFG->libdir
.'/db/upgradelib.php');
2246 $result = upgrade_18_letters(); // executes on dev sites only
2248 /// Define index contextidlowerboundary (not unique) to be added to grade_letters
2249 $table = new XMLDBTable('grade_letters');
2250 $index = new XMLDBIndex('contextid-lowerboundary');
2251 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE
, array('contextid', 'lowerboundary'));
2253 /// Launch add index contextidlowerboundary
2254 if (!index_exists($table, $index)) {
2255 $result = $result && add_index($table, $index);
2260 /// drop old gradebook tables
2261 if ($result && $oldversion < xxxxxxxx) {
2262 $tables = array('grade_category',
2265 'grade_preferences',
2266 'grade_exceptions');
2268 foreach ($tables as $table) {
2269 $table = new XMLDBTable($table);
2270 if (table_exists($table)) {