MDL-14451 updated pre-upgrade check (feedbacks, journal, lams, workshop and exercise)
[moodle.git] / lib / db / upgrade.php
CommitLineData
4e423cbf 1<?PHP //$Id$
2
3// This file keeps track of upgrades to Moodle.
4//
5// Sometimes, changes between versions involve
6// alterations to database structures and other
7// major things that may break installations.
8//
9// The upgrade function in this file will attempt
10// to perform all the necessary actions to upgrade
11// your older installtion to the current version.
12//
13// If there's something it cannot do itself, it
14// will tell you what you need to do.
15//
16// The commands in here will all be database-neutral,
17// using the functions defined in lib/ddllib.php
18
19
20function xmldb_main_upgrade($oldversion=0) {
21
8a45fcdf 22 global $CFG, $THEME, $USER, $db;
4e423cbf 23
24 $result = true;
25
26 if ($oldversion < 2006100401) {
27 /// Only for those tracking Moodle 1.7 dev, others will have these dropped in moodle_install_roles()
4c2275d5 28 if (!empty($CFG->rolesactive)) {
acc26e71 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'));
4e423cbf 33 }
8ddcdd86 34
35 upgrade_main_savepoint($result, 2006100401);
4e423cbf 36 }
37
e27a9437 38 if ($oldversion < 2006100601) { /// Disable the exercise module because it's unmaintained
39 if ($module = get_record('modules', 'name', 'exercise')) {
40 if ($module->visible) {
41 // Hide/disable the module entry
271e6dec 42 set_field('modules', 'visible', '0', 'id', $module->id);
e27a9437 43 // Save existing visible state for all activities
44 set_field('course_modules', 'visibleold', '1', 'visible' ,'1', 'module', $module->id);
45 set_field('course_modules', 'visibleold', '0', 'visible' ,'0', 'module', $module->id);
46 // Hide all activities
47 set_field('course_modules', 'visible', '0', 'module', $module->id);
271e6dec 48
dd97c328 49 //require_once($CFG->dirroot.'/course/lib.php');
50 //rebuild_course_cache(); // Rebuld cache for all modules because they might have changed
e27a9437 51 }
52 }
8ddcdd86 53
54 upgrade_main_savepoint($result, 2006100601);
e27a9437 55 }
56
171d8232 57 if ($oldversion < 2006101001) { /// Disable the LAMS module by default (if it is installed)
58 if (count_records('modules', 'name', 'lams') && !count_records('lams')) {
49e67510 59 set_field('modules', 'visible', 0, 'name', 'lams'); // Disable it by default
60 }
8ddcdd86 61
62 upgrade_main_savepoint($result, 2006101001);
49e67510 63 }
271e6dec 64
74807b43 65 if ($result && $oldversion < 2006102600) {
66
67 /// Define fields to be added to user_info_field
68 $table = new XMLDBTable('user_info_field');
69 $field = new XMLDBField('description');
70 $field->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null, 'categoryid');
71 $field1 = new XMLDBField('param1');
72 $field1->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null, 'defaultdata');
73 $field2 = new XMLDBField('param2');
74 $field2->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null, 'param1');
75 $field3 = new XMLDBField('param3');
76 $field3->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null, 'param2');
77 $field4 = new XMLDBField('param4');
78 $field4->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null, 'param3');
79 $field5 = new XMLDBField('param5');
80 $field5->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null, 'param4');
81
82 /// Launch add fields
83 $result = $result && add_field($table, $field);
84 $result = $result && add_field($table, $field1);
85 $result = $result && add_field($table, $field2);
86 $result = $result && add_field($table, $field3);
87 $result = $result && add_field($table, $field4);
88 $result = $result && add_field($table, $field5);
8ddcdd86 89
90 upgrade_main_savepoint($result, 2006102600);
74807b43 91 }
271e6dec 92
7d0e5a95 93 if ($result && $oldversion < 2006112000) {
94
95 /// Define field attachment to be added to post
96 $table = new XMLDBTable('post');
97 $field = new XMLDBField('attachment');
98 $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null, 'format');
99
100 /// Launch add field attachment
101 $result = $result && add_field($table, $field);
8ddcdd86 102
103 upgrade_main_savepoint($result, 2006112000);
7d0e5a95 104 }
271e6dec 105
54dc87b8 106 if ($result && $oldversion < 2006112200) {
107
108 /// Define field imagealt to be added to user
109 $table = new XMLDBTable('user');
110 $field = new XMLDBField('imagealt');
111 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'trustbitmask');
112
113 /// Launch add field imagealt
114 $result = $result && add_field($table, $field);
271e6dec 115
54dc87b8 116 $table = new XMLDBTable('user');
117 $field = new XMLDBField('screenreader');
118 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', 'imagealt');
119
120 /// Launch add field screenreader
121 $result = $result && add_field($table, $field);
8ddcdd86 122
123 upgrade_main_savepoint($result, 2006112200);
54dc87b8 124 }
49e67510 125
7b678e0a 126 if ($oldversion < 2006120300) { /// Delete guest course section settings
127 // following code can be executed repeatedly, such as when upgrading from 1.7.x - it is ok
128 if ($guest = get_record('user', 'username', 'guest')) {
77b09448 129 execute_sql("DELETE FROM {$CFG->prefix}course_display where userid=$guest->id", true);
7b678e0a 130 }
8ddcdd86 131
132 upgrade_main_savepoint($result, 2006120300);
7b678e0a 133 }
134
9c0f063b 135 if ($oldversion < 2006120400) { /// Remove secureforms config setting
77b09448 136 execute_sql("DELETE FROM {$CFG->prefix}config where name='secureforms'", true);
8ddcdd86 137
138 upgrade_main_savepoint($result, 2006120400);
9c0f063b 139 }
271e6dec 140
8c6c185a 141 if (!empty($CFG->rolesactive) && $oldversion < 2006120700) { // add moodle/user:viewdetails to all roles!
142 // note: use of assign_capability() is discouraged in upgrade script!
22ae509e 143 if ($roles = get_records('role')) {
144 $context = get_context_instance(CONTEXT_SYSTEM);
145 foreach ($roles as $roleid=>$role) {
146 assign_capability('moodle/user:viewdetails', CAP_ALLOW, $roleid, $context->id);
147 }
148 }
8ddcdd86 149
150 upgrade_main_savepoint($result, 2006120700);
22ae509e 151 }
9c0f063b 152
5cd129c7 153 // Move the auth plugin settings into the config_plugin table
154 if ($oldversion < 2007010300) {
177df3c6 155 if ($CFG->auth == 'email') {
156 set_config('registerauth', 'email');
157 } else {
158 set_config('registerauth', '');
159 }
5cd129c7 160 $authplugins = get_list_of_plugins('auth');
161 foreach ($CFG as $k => $v) {
922c5b36 162 if (strpos($k, 'ldap_') === 0) {
163 //upgrade nonstandard ldap settings
164 $setting = substr($k, 5);
165 if (set_config($setting, $v, "auth/ldap")) {
166 delete_records('config', 'name', $k);
167 unset($CFG->{$k});
168 }
169 continue;
170 }
5cd129c7 171 if (strpos($k, 'auth_') !== 0) {
172 continue;
173 }
174 $authsetting = substr($k, 5);
175 foreach ($authplugins as $auth) {
176 if (strpos($authsetting, $auth) !== 0) {
177 continue;
178 }
179 $setting = substr($authsetting, strlen($auth));
180 if (set_config($setting, $v, "auth/$auth")) {
181 delete_records('config', 'name', $k);
182 unset($CFG->{$k});
183 }
184 break; // don't check the rest of the auth plugin names
185 }
186 }
8ddcdd86 187
188 upgrade_main_savepoint($result, 2007010300);
5cd129c7 189 }
190
191 if ($oldversion < 2007010301) {
192 //
193 // Core MNET tables
194 //
195 $table = new XMLDBTable('mnet_host');
196 $table->comment = 'Information about the local and remote hosts for RPC';
197 // fields
198 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
199 XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
200 $f->comment = 'Unique Host ID';
201 $f = $table->addFieldInfo('deleted', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
202 XMLDB_NOTNULL, null, null, null, 0);
203 $f = $table->addFieldInfo('wwwroot', XMLDB_TYPE_CHAR, '255', null,
a54d16ef 204 XMLDB_NOTNULL, null, null, null, null);
5cd129c7 205 $f = $table->addFieldInfo('ip_address', XMLDB_TYPE_CHAR, '39', null,
a54d16ef 206 XMLDB_NOTNULL, null, null, null, null);
5cd129c7 207 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '80', null,
a54d16ef 208 XMLDB_NOTNULL, null, null, null, null);
357f08fa 209 $f = $table->addFieldInfo('public_key', XMLDB_TYPE_TEXT, 'medium', null,
5cd129c7 210 XMLDB_NOTNULL, null, null, null, null);
211 $f = $table->addFieldInfo('public_key_expires', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
212 XMLDB_NOTNULL, null, null, null, 0);
213 $f = $table->addFieldInfo('transport', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED,
214 XMLDB_NOTNULL, null, null, null, 0);
215 $f = $table->addFieldInfo('portno', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED,
216 XMLDB_NOTNULL, null, null, null, 0);
217 $f = $table->addFieldInfo('last_connect_time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
218 XMLDB_NOTNULL, null, null, null, 0);
219 $f = $table->addFieldInfo('last_log_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
220 XMLDB_NOTNULL, null, null, null, 0);
271e6dec 221 // PK and indexes
5cd129c7 222 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
223 // Create the table
224 $result = $result && create_table($table);
225
226 $table = new XMLDBTable('mnet_host2service');
227 $table->comment = 'Information about the services for a given host';
228 // fields
229 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
230 XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
231 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
232 XMLDB_NOTNULL, NULL, null, null, 0);
233 $f = $table->addFieldInfo('serviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
234 XMLDB_NOTNULL, NULL, null, null, 0);
235 $f = $table->addFieldInfo('publish', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
236 XMLDB_NOTNULL, NULL, null, null, 0);
237 $f = $table->addFieldInfo('subscribe', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
238 XMLDB_NOTNULL, NULL, null, null, 0);
239 // PK and indexes
240 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
241 $table->addIndexInfo('hostid_serviceid', XMLDB_INDEX_UNIQUE, array('hostid', 'serviceid'));
242 // Create the table
243 $result = $result && create_table($table);
244
245 $table = new XMLDBTable('mnet_log');
246 $table->comment = 'Store session data from users migrating to other sites';
247 // fields
248 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
249 XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
250 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
251 XMLDB_NOTNULL, NULL, null, null, 0);
252 $f = $table->addFieldInfo('remoteid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
253 XMLDB_NOTNULL, NULL, null, null, 0);
254 $f = $table->addFieldInfo('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
255 XMLDB_NOTNULL, NULL, null, null, 0);
256 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
257 XMLDB_NOTNULL, NULL, null, null, 0);
258 $f = $table->addFieldInfo('ip', XMLDB_TYPE_CHAR, '15', null,
259 XMLDB_NOTNULL, NULL, null, null, null);
260 $f = $table->addFieldInfo('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
261 XMLDB_NOTNULL, NULL, null, null, 0);
262 $f = $table->addFieldInfo('coursename', XMLDB_TYPE_CHAR, '40', null,
263 XMLDB_NOTNULL, NULL, null, null, null);
264 $f = $table->addFieldInfo('module', XMLDB_TYPE_CHAR, '20', null,
265 XMLDB_NOTNULL, NULL, null, null, null);
266 $f = $table->addFieldInfo('cmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
267 XMLDB_NOTNULL, NULL, null, null, 0);
268 $f = $table->addFieldInfo('action', XMLDB_TYPE_CHAR, '40', null,
269 XMLDB_NOTNULL, NULL, null, null, null);
270 $f = $table->addFieldInfo('url', XMLDB_TYPE_CHAR, '100', null,
271 XMLDB_NOTNULL, NULL, null, null, null);
272 $f = $table->addFieldInfo('info', XMLDB_TYPE_CHAR, '255', null,
273 XMLDB_NOTNULL, NULL, null, null, null);
274 // PK and indexes
275 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
276 $table->addIndexInfo('host_user_course', XMLDB_INDEX_NOTUNIQUE, array('hostid', 'userid', 'course'));
277 // Create the table
278 $result = $result && create_table($table);
279
280
281 $table = new XMLDBTable('mnet_rpc');
282 $table->comment = 'Functions or methods that we may publish or subscribe to';
283 // fields
284 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
285 XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
286 $f = $table->addFieldInfo('function_name', XMLDB_TYPE_CHAR, '40', null,
287 XMLDB_NOTNULL, NULL, null, null, null);
288 $f = $table->addFieldInfo('xmlrpc_path', XMLDB_TYPE_CHAR, '80', null,
289 XMLDB_NOTNULL, NULL, null, null, null);
290 $f = $table->addFieldInfo('parent_type', XMLDB_TYPE_CHAR, '6', null,
291 XMLDB_NOTNULL, NULL, null, null, null);
292 $f = $table->addFieldInfo('parent', XMLDB_TYPE_CHAR, '20', null,
293 XMLDB_NOTNULL, NULL, null, null, null);
294 $f = $table->addFieldInfo('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
295 XMLDB_NOTNULL, NULL, null, null, 0);
296 $f = $table->addFieldInfo('help', XMLDB_TYPE_TEXT, 'medium', null,
297 XMLDB_NOTNULL, NULL, null, null, null);
298 $f = $table->addFieldInfo('profile', XMLDB_TYPE_TEXT, 'medium', null,
299 XMLDB_NOTNULL, NULL, null, null, null);
300 // PK and indexes
301 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
302 $table->addIndexInfo('enabled_xpath', XMLDB_INDEX_NOTUNIQUE, array('enabled', 'xmlrpc_path'));
303 // Create the table
304 $result = $result && create_table($table);
305
306 $table = new XMLDBTable('mnet_service');
307 $table->comment = 'A service is a group of functions';
308 // fields
309 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
310 XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
311 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '40', null,
312 XMLDB_NOTNULL, NULL, null, null, null);
313 $f = $table->addFieldInfo('description', XMLDB_TYPE_CHAR, '40', null,
314 XMLDB_NOTNULL, NULL, null, null, null);
315 $f = $table->addFieldInfo('apiversion', XMLDB_TYPE_CHAR, '10', null,
316 XMLDB_NOTNULL, NULL, null, null, null);
317 $f = $table->addFieldInfo('offer', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
318 XMLDB_NOTNULL, NULL, null, null, 0);
319 // PK and indexes
320 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
321 // Create the table
322 $result = $result && create_table($table);
323
324 $table = new XMLDBTable('mnet_service2rpc');
357f08fa 325 $table->comment = 'Group functions or methods under a service';
5cd129c7 326 // fields
327 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
328 XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
329 $f = $table->addFieldInfo('serviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
330 XMLDB_NOTNULL, NULL, null, null, 0);
331 $f = $table->addFieldInfo('rpcid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
332 XMLDB_NOTNULL, NULL, null, null, 0);
333 // PK and indexes
334 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
335 $table->addIndexInfo('unique', XMLDB_INDEX_UNIQUE, array('rpcid', 'serviceid'));
336 // Create the table
337 $result = $result && create_table($table);
338
339 //
271e6dec 340 // Prime MNET configuration entries -- will be needed later by auth/mnet
5cd129c7 341 //
342 include_once $CFG->dirroot . '/mnet/lib.php';
343 $env = new mnet_environment();
344 $env->init();
345 unset($env);
346
271e6dec 347 // add mnethostid to user-
5cd129c7 348 $table = new XMLDBTable('user');
349 $field = new XMLDBField('mnethostid');
350 $field->setType(XMLDB_TYPE_INTEGER);
351 $field->setLength(10);
352 $field->setNotNull(true);
353 $field->setSequence(null);
354 $field->setEnum(null);
355 $field->setDefault('0');
356 $field->setPrevious("deleted");
357 $field->setNext("username");
358 $result = $result && add_field($table, $field);
359
360 // The default mnethostid is zero... we need to update this for all
361 // users of the local IdP service.
271e6dec 362 set_field('user',
363 'mnethostid', $CFG->mnet_localhost_id,
5cd129c7 364 'mnethostid', '0');
365
366
367 $index = new XMLDBIndex('username');
368 $index->setUnique(true);
369 $index->setFields(array('username'));
370 drop_index($table, $index);
371 $index->setFields(array('mnethostid', 'username'));
b7791fab 372 if (!add_index($table, $index)) {
68879a58 373 notify(get_string('duplicate_usernames', 'mnet', 'http://docs.moodle.org/en/DuplicateUsernames'));
374 }
5cd129c7 375
271e6dec 376 unset($table, $field, $index);
5cd129c7 377
378 /**
379 ** auth/mnet tables
380 **/
381 $table = new XMLDBTable('mnet_session');
382 $table->comment='Store session data from users migrating to other sites';
383 // fields
384 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
385 XMLDB_NOTNULL,XMLDB_SEQUENCE, null, null, null);
386 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
387 XMLDB_NOTNULL, NULL, null, null, 0);
388 $f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR, '100', null,
389 XMLDB_NOTNULL, NULL, null, null, null);
390 $f = $table->addFieldInfo('token', XMLDB_TYPE_CHAR, '40', null,
391 XMLDB_NOTNULL, NULL, null, null, null);
392 $f = $table->addFieldInfo('mnethostid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
393 XMLDB_NOTNULL, NULL, null, null, 0);
394 $f = $table->addFieldInfo('useragent', XMLDB_TYPE_CHAR, '40', null,
395 XMLDB_NOTNULL, NULL, null, null, null);
396 $f = $table->addFieldInfo('confirm_timeout', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
397 XMLDB_NOTNULL, NULL, null, null, 0);
398 $f = $table->addFieldInfo('session_id', XMLDB_TYPE_CHAR, '40', null,
399 XMLDB_NOTNULL, NULL, null, null, null);
400 $f = $table->addFieldInfo('expires', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
401 XMLDB_NOTNULL, NULL, null, null, 0);
402 // PK and indexes
403 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
357f08fa 404 $table->addIndexInfo('token', XMLDB_INDEX_UNIQUE, array('token'));
5cd129c7 405 // Create the table
406 $result = $result && create_table($table);
407
408
409 $table = new XMLDBTable('mnet_sso_access_control');
410 $table->comment = 'Users by host permitted (or not) to login from a remote provider';
411 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
412 XMLDB_NOTNULL,XMLDB_SEQUENCE, null, null, null);
413 $f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR, '100', null,
414 XMLDB_NOTNULL, NULL, null, null, null);
415 $f = $table->addFieldInfo('mnet_host_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
416 XMLDB_NOTNULL, NULL, null, null, 0);
417 $f = $table->addFieldInfo('access', XMLDB_TYPE_CHAR, '20', null,
418 XMLDB_NOTNULL, NULL, null, null, 'allow');
419 // PK and indexes
420 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
421 $table->addIndexInfo('mnethostid_username', XMLDB_INDEX_UNIQUE, array('mnet_host_id', 'username'));
422 // Create the table
423 $result = $result && create_table($table);
424
8a45fcdf 425 if (empty($USER->mnet_host_id)) {
cac88d40 426 $USER->mnet_host_id = $CFG->mnet_localhost_id; // Something for the current user to prevent warnings
8a45fcdf 427 }
428
5cd129c7 429 /**
430 ** enrol/mnet tables
431 **/
432 $table = new XMLDBTable('mnet_enrol_course');
433 $table->comment = 'Information about courses on remote hosts';
434 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
435 XMLDB_NOTNULL,XMLDB_SEQUENCE, null, null, null);
436 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
437 XMLDB_NOTNULL, NULL, null, null, 0);
438 $f = $table->addFieldInfo('remoteid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
439 XMLDB_NOTNULL, NULL, null, null, 0);
440 $f = $table->addFieldInfo('cat_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
441 XMLDB_NOTNULL, NULL, null, null, 0);
442 $f = $table->addFieldInfo('cat_name', XMLDB_TYPE_CHAR, '255', null,
443 XMLDB_NOTNULL, NULL, null, null, null);
444 $f = $table->addFieldInfo('cat_description', XMLDB_TYPE_TEXT, 'medium', null,
445 XMLDB_NOTNULL, NULL, null, null, null);
446 $f = $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED,
447 XMLDB_NOTNULL, NULL, null, null, 0);
448 $f = $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '254', null,
a54d16ef 449 XMLDB_NOTNULL, NULL, null, null, null);
5cd129c7 450 $f = $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '15', null,
451 XMLDB_NOTNULL, NULL, null, null, null);
452 $f = $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '100', null,
453 XMLDB_NOTNULL, NULL, null, null, null);
454 $f = $table->addFieldInfo('summary', XMLDB_TYPE_TEXT, 'medium', null,
455 XMLDB_NOTNULL, NULL, null, null, null);
456 $f = $table->addFieldInfo('startdate', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
457 XMLDB_NOTNULL, NULL, null, null, 0);
458 $f = $table->addFieldInfo('cost', XMLDB_TYPE_CHAR, '10', null,
459 XMLDB_NOTNULL, NULL, null, null, null);
460 $f = $table->addFieldInfo('currency', XMLDB_TYPE_CHAR, '3', null,
461 XMLDB_NOTNULL, NULL, null, null, null);
462 $f = $table->addFieldInfo('defaultroleid', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED,
463 XMLDB_NOTNULL, NULL, null, null, 0);
464 $f = $table->addFieldInfo('defaultrolename', XMLDB_TYPE_CHAR, '255', null,
465 XMLDB_NOTNULL, NULL, null, null, null);
466 // PK and indexes
467 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
468 $table->addIndexInfo('hostid_remoteid', XMLDB_INDEX_UNIQUE, array('hostid', 'remoteid'));
469 // Create the table
470 $result = $result && create_table($table);
471
472
473 $table = new XMLDBTable('mnet_enrol_assignments');
474
475 $table->comment = 'Information about enrolments on courses on remote hosts';
476 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
477 XMLDB_NOTNULL,XMLDB_SEQUENCE, null, null, null);
478 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
479 XMLDB_NOTNULL, NULL, null, null, 0);
480 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
271e6dec 481 XMLDB_NOTNULL, NULL, null, null, 0);
5cd129c7 482 $f = $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
483 XMLDB_NOTNULL, NULL, null, null, 0);
484 $f = $table->addFieldInfo('rolename', XMLDB_TYPE_CHAR, '255', null,
485 XMLDB_NOTNULL, NULL, null, null, null);
486 $f = $table->addFieldInfo('enroltime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
487 XMLDB_NOTNULL, NULL, null, null, 0);
488 $f = $table->addFieldInfo('enroltype', XMLDB_TYPE_CHAR, '20', null,
489 XMLDB_NOTNULL, NULL, null, null, null);
490
491 // PK and indexes
492 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
493 $table->addIndexInfo('hostid_courseid', XMLDB_INDEX_NOTUNIQUE, array('hostid', 'courseid'));
357f08fa 494 $table->addIndexInfo('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
5cd129c7 495 // Create the table
496 $result = $result && create_table($table);
497
8ddcdd86 498 upgrade_main_savepoint($result, 2007010301);
5cd129c7 499 }
500
dedda83d 501 if ($result && $oldversion < 2007010404) {
502
503 /// Define field shortname to be added to user_info_field
504 $table = new XMLDBTable('user_info_field');
505 $field = new XMLDBField('shortname');
506 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, 'shortname', 'id');
507
508 /// Launch add field shortname
509 $result = $result && add_field($table, $field);
510
511 /// Changing type of field name on table user_info_field to text
512 $table = new XMLDBTable('user_info_field');
513 $field = new XMLDBField('name');
514 $field->setAttributes(XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null, null, null, 'shortname');
515
516 /// Launch change of type for field name
517 $result = $result && change_field_type($table, $field);
518
519 /// For existing fields use 'name' as the 'shortname' entry
4218c9b2 520 if ($fields = get_records_select('user_info_field', '', '', 'id, name')) {
dedda83d 521 foreach ($fields as $field) {
522 $field->shortname = clean_param($field->name, PARAM_ALPHANUM);
523 $result && update_record('user_info_field', $field);
524 }
525 }
8ddcdd86 526
527 upgrade_main_savepoint($result, 2007010404);
dedda83d 528 }
529
bb931a61 530 if ($result && $oldversion < 2007011501) {
271e6dec 531 if (!empty($CFG->enablerecordcache) && empty($CFG->rcache) &&
bb931a61 532 // Note: won't force-load these settings into CFG
533 // we don't need or want cache during the upgrade itself
534 empty($CFG->cachetype) && empty($CFG->intcachemax)) {
535 set_config('cachetype', 'internal');
536 set_config('rcache', true);
537 set_config('intcachemax', $CFG->enablerecordcache);
538 unset_config('enablerecordcache');
539 unset($CFG->enablerecordcache);
540 }
8ddcdd86 541
542 upgrade_main_savepoint($result, 2007011501);
bb931a61 543 }
544
9fc57f4c 545 if ($result && $oldversion < 2007012100) {
546 /// Some old PG servers have user->firstname & user->lastname with 30cc. They must be 100cc.
547 /// Fixing that conditionally. MDL-7110
548 if ($CFG->dbfamily == 'postgres') {
549 /// Get Metadata from user table
550 $cols = array_change_key_case($db->MetaColumns($CFG->prefix . 'user'), CASE_LOWER);
551
552 /// Process user->firstname if needed
553 if ($col = $cols['firstname']) {
554 if ($col->max_length < 100) {
555 /// Changing precision of field firstname on table user to (100)
556 $table = new XMLDBTable('user');
557 $field = new XMLDBField('firstname');
558 $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null, 'idnumber');
559
560 /// Launch change of precision for field firstname
561 $result = $result && change_field_precision($table, $field);
562 }
563 }
564
565 /// Process user->lastname if needed
566 if ($col = $cols['lastname']) {
567 if ($col->max_length < 100) {
568 /// Changing precision of field lastname on table user to (100)
569 $table = new XMLDBTable('user');
570 $field = new XMLDBField('lastname');
571 $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null, 'firstname');
572
573 /// Launch change of precision for field lastname
574 $result = $result && change_field_precision($table, $field);
575 }
576 }
577 }
8ddcdd86 578
579 upgrade_main_savepoint($result, 2007012100);
9fc57f4c 580 }
581
deb12ef4 582 if ($result && $oldversion < 2007012101) {
583
584 /// Changing precision of field lang on table course to (30)
585 $table = new XMLDBTable('course');
586 $field = new XMLDBField('lang');
587 $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null, 'groupmodeforce');
588
589 /// Launch change of precision for field course->lang
590 $result = $result && change_field_precision($table, $field);
591
592 /// Changing precision of field lang on table user to (30)
593 $table = new XMLDBTable('user');
594 $field = new XMLDBField('lang');
595 $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'en', 'country');
596
597 /// Launch change of precision for field user->lang
598 $result = $result && change_field_precision($table, $field);
8ddcdd86 599
600 upgrade_main_savepoint($result, 2007012101);
deb12ef4 601 }
602
cdf22329 603 if ($result && $oldversion < 2007012400) {
604
605 /// Rename field access on table mnet_sso_access_control to accessctrl
606 $table = new XMLDBTable('mnet_sso_access_control');
607 $field = new XMLDBField('access');
fdaacd8b 608 $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'allow', 'mnet_host_id');
cdf22329 609
610 /// Launch rename field accessctrl
611 $result = $result && rename_field($table, $field, 'accessctrl');
8ddcdd86 612
613 upgrade_main_savepoint($result, 2007012400);
cdf22329 614 }
615
e8e0bb2d 616 if ($result && $oldversion < 2007012500) {
77b09448 617 execute_sql("DELETE FROM {$CFG->prefix}user WHERE username='changeme'", true);
8ddcdd86 618
619 upgrade_main_savepoint($result, 2007012500);
e8e0bb2d 620 }
621
8dadea88 622 if ($result && $oldversion < 2007020400) {
623 /// Only for MySQL and PG, declare the user->ajax field as not null. MDL-8421.
624 if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') {
625 /// Changing nullability of field ajax on table user to not null
626 $table = new XMLDBTable('user');
627 $field = new XMLDBField('ajax');
628 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'htmleditor');
629
630 /// Launch change of nullability for field ajax
631 $result = $result && change_field_notnull($table, $field);
632 }
8ddcdd86 633
634 upgrade_main_savepoint($result, 2007020400);
8dadea88 635 }
636
ee266f33 637 if (!empty($CFG->rolesactive) && $result && $oldversion < 2007021401) {
efe12f6c 638 /// create default logged in user role if not present - upgrade rom 1.7.x
c7888a90 639 if (empty($CFG->defaultuserroleid) or empty($CFG->guestroleid) or $CFG->defaultuserroleid == $CFG->guestroleid) {
efe12f6c 640 if (!get_records('role', 'shortname', 'user')) {
641 $userroleid = create_role(addslashes(get_string('authenticateduser')), 'user',
642 addslashes(get_string('authenticateduserdescription')), 'moodle/legacy:user');
643 if ($userroleid) {
644 reset_role_capabilities($userroleid);
645 set_config('defaultuserroleid', $userroleid);
646 }
647 }
648 }
8ddcdd86 649
650 upgrade_main_savepoint($result, 2007021401);
efe12f6c 651 }
652
77d08333 653 if ($result && $oldversion < 2007021501) {
654 /// delete removed setting from config
655 unset_config('tabselectedtofront');
8ddcdd86 656
657 upgrade_main_savepoint($result, 2007021501);
77d08333 658 }
659
b318ecfd 660
661 if ($result && $oldversion < 2007032200) {
662
663 /// Define table role_sortorder to be created
664 $table = new XMLDBTable('role_sortorder');
665
666 /// Adding fields to table role_sortorder
abd30252 667 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
b318ecfd 668 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
669 $table->addFieldInfo('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
670 $table->addFieldInfo('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
671 $table->addFieldInfo('sortoder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
672
673 /// Adding keys to table role_sortorder
674 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
675 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
676 $table->addKeyInfo('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
677 $table->addKeyInfo('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
678
679 /// Adding indexes to table role_sortorder
680 $table->addIndexInfo('userid-roleid-contextid', XMLDB_INDEX_UNIQUE, array('userid', 'roleid', 'contextid'));
681
682 /// Launch create table for role_sortorder
683 $result = $result && create_table($table);
8ddcdd86 684
685 upgrade_main_savepoint($result, 2007032200);
b318ecfd 686 }
687
07076b70 688
689 /// code to change lenghen tag field to 255, MDL-9095
690 if ($result && $oldversion < 2007040400) {
691
692 /// Define index text (not unique) to be dropped form tags
693 $table = new XMLDBTable('tags');
694 $index = new XMLDBIndex('text');
695 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('text'));
696
697 /// Launch drop index text
698 $result = $result && drop_index($table, $index);
271e6dec 699
07076b70 700 $field = new XMLDBField('text');
701 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'userid');
702
703 /// Launch change of type for field text
704 $result = $result && change_field_type($table, $field);
271e6dec 705
07076b70 706 $index = new XMLDBIndex('text');
707 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('text'));
708
709 /// Launch add index text
271e6dec 710 $result = $result && add_index($table, $index);
8ddcdd86 711
712 upgrade_main_savepoint($result, 2007040400);
07076b70 713 }
271e6dec 714
177d4abf 715 if ($result && $oldversion < 2007041100) {
716
717 /// Define field idnumber to be added to course_modules
718 $table = new XMLDBTable('course_modules');
719 $field = new XMLDBField('idnumber');
720 $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null, 'section');
271e6dec 721
177d4abf 722 /// Launch add field idnumber
723 $result = $result && add_field($table, $field);
271e6dec 724
8ddcdd86 725 upgrade_main_savepoint($result, 2007041100);
177d4abf 726 }
727
334415e9 728 /* Changes to the custom profile menu type - store values rather than indices.
729 We could do all this with one tricky SQL statement but it's a one-off so no
730 harm in using PHP loops */
731 if ($result && $oldversion < 2007041600) {
271e6dec 732
334415e9 733 /// Get the menu fields
734 if ($fields = get_records('user_info_field', 'datatype', 'menu')) {
735 foreach ($fields as $field) {
736
737 /// Get user data for the menu field
738 if ($data = get_records('user_info_data', 'fieldid', $field->id)) {
739
740 /// Get the menu options
540286f1 741 $options = explode("\n", $field->param1);
334415e9 742 foreach ($data as $d) {
743 $key = array_search($d->data, $options);
271e6dec 744
334415e9 745 /// If the data is an integer and is not one of the options,
746 /// set the respective option value
747 if (is_int($d->data) and (($key === NULL) or ($key === false)) and isset($options[$d->data])) {
748 $d->data = $options[$d->data];
749 $result = $result && update_record('user_info_data', $d);
750 }
751 }
752 }
753 }
754 }
271e6dec 755
8ddcdd86 756 upgrade_main_savepoint($result, 2007041600);
334415e9 757 }
271e6dec 758
5cb564aa 759 /// adding new gradebook tables
ec36253d 760 if ($result && $oldversion < 2007041800) {
761
762 /// Define table events_handlers to be created
763 $table = new XMLDBTable('events_handlers');
764
765 /// Adding fields to table events_handlers
197ba19c 766 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
5cb564aa 767 $table->addFieldInfo('eventname', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null);
768 $table->addFieldInfo('handlermodule', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null);
ec36253d 769 $table->addFieldInfo('handlerfile', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
770 $table->addFieldInfo('handlerfunction', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
771
772 /// Adding keys to table events_handlers
773 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
774
775 /// Adding indexes to table events_handlers
5cb564aa 776 $table->addIndexInfo('eventname-handlermodule', XMLDB_INDEX_UNIQUE, array('eventname', 'handlermodule'));
ec36253d 777
778 /// Launch create table for events_handlers
779 $result = $result && create_table($table);
271e6dec 780
ec36253d 781 /// Define table events_queue to be created
782 $table = new XMLDBTable('events_queue');
783
784 /// Adding fields to table events_queue
197ba19c 785 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
ec36253d 786 $table->addFieldInfo('eventdata', XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null, null, null);
787 $table->addFieldInfo('schedule', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
788 $table->addFieldInfo('stackdump', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
789 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
790 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
791
792 /// Adding keys to table events_queue
793 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
794 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
334415e9 795
ec36253d 796 /// Launch create table for events_queue
797 $result = $result && create_table($table);
271e6dec 798
ec36253d 799 /// Define table events_queue_handlers to be created
800 $table = new XMLDBTable('events_queue_handlers');
801
802 /// Adding fields to table events_queue_handlers
197ba19c 803 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
ec36253d 804 $table->addFieldInfo('queuedeventid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
805 $table->addFieldInfo('handlerid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
806 $table->addFieldInfo('status', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
807 $table->addFieldInfo('errormessage', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
808 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
809
810 /// Adding keys to table events_queue_handlers
811 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
812 $table->addKeyInfo('queuedeventid', XMLDB_KEY_FOREIGN, array('queuedeventid'), 'events_queue', array('id'));
813 $table->addKeyInfo('handlerid', XMLDB_KEY_FOREIGN, array('handlerid'), 'events_handlers', array('id'));
814
815 /// Launch create table for events_queue_handlers
816 $result = $result && create_table($table);
817
8ddcdd86 818 upgrade_main_savepoint($result, 2007041800);
ec36253d 819 }
9d2cddf1 820
896f1e03 821 if ($result && $oldversion < 2007043001) {
822
896f1e03 823 /// Define field schedule to be added to events_handlers
824 $table = new XMLDBTable('events_handlers');
825 $field = new XMLDBField('schedule');
826 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'handlerfunction');
827
828 /// Launch add field schedule
829 $result = $result && add_field($table, $field);
271e6dec 830
896f1e03 831 /// Define field status to be added to events_handlers
832 $table = new XMLDBTable('events_handlers');
833 $field = new XMLDBField('status');
834 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'schedule');
835
836 /// Launch add field status
837 $result = $result && add_field($table, $field);
8ddcdd86 838
839 upgrade_main_savepoint($result, 2007043001);
896f1e03 840 }
841
ec75a182 842 if ($result && $oldversion < 2007050201) {
843
844 /// Define field theme to be added to course_categories
845 $table = new XMLDBTable('course_categories');
846 $field = new XMLDBField('theme');
847 $field->setAttributes(XMLDB_TYPE_CHAR, '50', null, null, null, null, null, null, 'path');
848
849 /// Launch add field theme
850 $result = $result && add_field($table, $field);
8ddcdd86 851
852 upgrade_main_savepoint($result, 2007050201);
ec75a182 853 }
9aaa214e 854
855 if ($result && $oldversion < 2007051100) {
856
857 /// Define field forceunique to be added to user_info_field
858 $table = new XMLDBTable('user_info_field');
859 $field = new XMLDBField('forceunique');
860 $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'visible');
861
862 /// Launch add field forceunique
863 $result = $result && add_field($table, $field);
864
865 /// Define field signup to be added to user_info_field
866 $table = new XMLDBTable('user_info_field');
867 $field = new XMLDBField('signup');
868 $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'forceunique');
869
870 /// Launch add field signup
871 $result = $result && add_field($table, $field);
8ddcdd86 872
873 upgrade_main_savepoint($result, 2007051100);
9aaa214e 874 }
93759def 875
8c6c185a 876 if (!empty($CFG->rolesactive) && $result && $oldversion < 2007051801) {
877 // Get the role id of the "Auth. User" role and check if the default role id is different
878 // note: use of assign_capability() is discouraged in upgrade script!
282c1695 879 $userrole = get_record( 'role', 'shortname', 'user' );
880 $defaultroleid = $CFG->defaultuserroleid;
881
882 if( $defaultroleid != $userrole->id ) {
883 // Add in the new moodle/my:manageblocks capibility to the default user role
12d06877 884 $context = get_context_instance(CONTEXT_SYSTEM);
282c1695 885 assign_capability('moodle/my:manageblocks',CAP_ALLOW,$defaultroleid,$context->id);
886 }
8ddcdd86 887
888 upgrade_main_savepoint($result, 2007051801);
282c1695 889 }
890
d46306de 891 if ($result && $oldversion < 2007052200) {
892
893 /// Define field schedule to be dropped from events_queue
894 $table = new XMLDBTable('events_queue');
895 $field = new XMLDBField('schedule');
896
897 /// Launch drop field stackdump
898 $result = $result && drop_field($table, $field);
8ddcdd86 899
900 upgrade_main_savepoint($result, 2007052200);
d46306de 901 }
902
ec4560cc 903 if ($result && $oldversion < 2007052300) {
904 require_once($CFG->dirroot . '/question/upgrade.php');
905 $result = $result && question_remove_rqp_qtype();
8ddcdd86 906
907 upgrade_main_savepoint($result, 2007052300);
ec4560cc 908 }
909
1b63e573 910 if ($result && $oldversion < 2007060500) {
911
912 /// Define field usermodified to be added to post
913 $table = new XMLDBTable('post');
914 $field = new XMLDBField('usermodified');
915 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'created');
916
917 /// Launch add field usermodified
918 $result = $result && add_field($table, $field);
271e6dec 919
1b63e573 920 /// Define key usermodified (foreign) to be added to post
921 $table = new XMLDBTable('post');
922 $key = new XMLDBKey('usermodified');
923 $key->setAttributes(XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
924
925 /// Launch add key usermodified
926 $result = $result && add_key($table, $key);
8ddcdd86 927
928 upgrade_main_savepoint($result, 2007060500);
1b63e573 929 }
ac9b0805 930
42ff9ce6 931 if ($result && $oldversion < 2007070603) {
932 // Small update of guest user to be 100% sure it has the correct mnethostid (MDL-10375)
933 set_field('user', 'mnethostid', $CFG->mnet_localhost_id, 'username', 'guest');
8ddcdd86 934
935 upgrade_main_savepoint($result, 2007070603);
42ff9ce6 936 }
937
938 if ($result && $oldversion < 2007071400) {
939 /**
940 ** mnet application table
941 **/
942 $table = new XMLDBTable('mnet_application');
943 $table->comment = 'Information about applications on remote hosts';
944 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
945 XMLDB_NOTNULL,XMLDB_SEQUENCE, null, null, null);
946 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '50', null,
947 XMLDB_NOTNULL, NULL, null, null, null);
948 $f = $table->addFieldInfo('display_name', XMLDB_TYPE_CHAR, '50', null,
949 XMLDB_NOTNULL, NULL, null, null, null);
950 $f = $table->addFieldInfo('xmlrpc_server_url', XMLDB_TYPE_CHAR, '255', null,
951 XMLDB_NOTNULL, NULL, null, null, null);
952 $f = $table->addFieldInfo('sso_land_url', XMLDB_TYPE_CHAR, '255', null,
953 XMLDB_NOTNULL, NULL, null, null, null);
954
955 // PK and indexes
956 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
957 // Create the table
958 $result = $result && create_table($table);
959
960 // Insert initial applications (moodle and mahara)
961 $application = new stdClass();
962 $application->name = 'moodle';
963 $application->display_name = 'Moodle';
964 $application->xmlrpc_server_url = '/mnet/xmlrpc/server.php';
965 $application->sso_land_url = '/auth/mnet/land.php';
966 if ($result) {
967 $newid = insert_record('mnet_application', $application, false);
968 }
969
970 $application = new stdClass();
971 $application->name = 'mahara';
972 $application->display_name = 'Mahara';
973 $application->xmlrpc_server_url = '/api/xmlrpc/server.php';
974 $application->sso_land_url = '/auth/xmlrpc/land.php';
975 $result = $result && insert_record('mnet_application', $application, false);
271e6dec 976
42ff9ce6 977 // New mnet_host->applicationid field
978 $table = new XMLDBTable('mnet_host');
979 $field = new XMLDBField('applicationid');
980 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, $newid , 'last_log_id');
981
982 $result = $result && add_field($table, $field);
983
984 /// Define key applicationid (foreign) to be added to mnet_host
985 $table = new XMLDBTable('mnet_host');
986 $key = new XMLDBKey('applicationid');
987 $key->setAttributes(XMLDB_KEY_FOREIGN, array('applicationid'), 'mnet_application', array('id'));
988
989 /// Launch add key applicationid
990 $result = $result && add_key($table, $key);
578075c6 991
8ddcdd86 992 upgrade_main_savepoint($result, 2007071400);
42ff9ce6 993 }
994
995 if ($result && $oldversion < 2007071607) {
996 require_once($CFG->dirroot . '/question/upgrade.php');
997 $result = $result && question_remove_rqp_qtype_config_string();
8ddcdd86 998
999 upgrade_main_savepoint($result, 2007071607);
42ff9ce6 1000 }
1001
42ff9ce6 1002 if ($result && $oldversion < 2007072200) {
42ff9ce6 1003
1004/// Remove all grade tables used in development phases - we need new empty tables for final gradebook upgrade
1005 $tables = array('grade_categories',
1006 'grade_items',
1007 'grade_calculations',
1008 'grade_grades',
1009 'grade_grades_raw',
1010 'grade_grades_final',
1011 'grade_grades_text',
1012 'grade_outcomes',
1013 'grade_outcomes_courses',
1014 'grade_history',
1015 'grade_import_newitem',
1016 'grade_import_values');
578075c6 1017
b3ac6c3e 1018 foreach ($tables as $table) {
1019 $table = new XMLDBTable($table);
1020 if (table_exists($table)) {
1021 drop_table($table);
1022 }
578075c6 1023 }
578075c6 1024
42ff9ce6 1025 $tables = array('grade_categories_history',
1026 'grade_items_history',
1027 'grade_grades_history',
1028 'grade_grades_text_history',
1029 'grade_scale_history',
1030 'grade_outcomes_history');
1031
1032 foreach ($tables as $table) {
1033 $table = new XMLDBTable($table);
1034 if (table_exists($table)) {
1035 drop_table($table);
1036 }
1037 }
1038
1039
1040 /// Define table grade_outcomes to be created
1041 $table = new XMLDBTable('grade_outcomes');
1042
1043 /// Adding fields to table grade_outcomes
1044 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1045 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1046 $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1047 $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
1048 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
678a79ca 1049 $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
42ff9ce6 1050 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1051 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1052 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1053
1054 /// Adding keys to table grade_outcomes
1055 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1056 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1057 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
1058 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
1059
1060 /// Launch create table for grade_outcomes
1061 $result = $result && create_table($table);
1062
1063
42ff9ce6 1064 /// Define table grade_categories to be created
1065 $table = new XMLDBTable('grade_categories');
1066
1067 /// Adding fields to table grade_categories
1068 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1069 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1070 $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1071 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1072 $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1073 $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1074 $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1075 $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1076 $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
c2efb501 1077 $table->addFieldInfo('aggregateonlygraded', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
29d509f5 1078 $table->addFieldInfo('aggregateoutcomes', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
c2efb501 1079 $table->addFieldInfo('aggregatesubcats', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
42ff9ce6 1080 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1081 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1082
1083 /// Adding keys to table grade_categories
1084 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1085 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1086 $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id'));
1087
1088 /// Launch create table for grade_categories
1089 $result = $result && create_table($table);
1090
61c33818 1091
b3ac6c3e 1092 /// Define table grade_items to be created
1093 $table = new XMLDBTable('grade_items');
61c33818 1094
b3ac6c3e 1095 /// Adding fields to table grade_items
197ba19c 1096 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
b3ac6c3e 1097 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1098 $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1099 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1100 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
1101 $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
1102 $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1103 $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1104 $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1105 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1106 $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1107 $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '1');
1108 $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');
1109 $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1110 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
abd30252 1111 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
b3ac6c3e 1112 $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1113 $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '1.0');
1114 $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
cea2542b 1115 $table->addFieldInfo('aggregationcoef', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
b3ac6c3e 1116 $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
d9266304 1117 $table->addFieldInfo('display', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1118 $table->addFieldInfo('decimals', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null);
b3ac6c3e 1119 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1120 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1121 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
b3ac6c3e 1122 $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1123 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1124 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
61c33818 1125
b3ac6c3e 1126 /// Adding keys to table grade_items
1127 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1128 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1129 $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN, array('categoryid'), 'grade_categories', array('id'));
1130 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
1131 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id'));
61c33818 1132
173403cf 1133 /// Adding indexes to table grade_grades
6c9f6725 1134 $table->addIndexInfo('locked-locktime', XMLDB_INDEX_NOTUNIQUE, array('locked', 'locktime'));
90274c73 1135 $table->addIndexInfo('itemtype-needsupdate', XMLDB_INDEX_NOTUNIQUE, array('itemtype', 'needsupdate'));
1136 $table->addIndexInfo('gradetype', XMLDB_INDEX_NOTUNIQUE, array('gradetype'));
173403cf 1137
b3ac6c3e 1138 /// Launch create table for grade_items
1139 $result = $result && create_table($table);
f92dcad8 1140
f92dcad8 1141
b3ac6c3e 1142 /// Define table grade_grades to be created
1143 $table = new XMLDBTable('grade_grades');
f92dcad8 1144
b3ac6c3e 1145 /// Adding fields to table grade_grades
197ba19c 1146 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
b3ac6c3e 1147 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1148 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1149 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
1150 $table->addFieldInfo('rawgrademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');
1151 $table->addFieldInfo('rawgrademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1152 $table->addFieldInfo('rawscaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1153 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1154 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
1155 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1156 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1157 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1158 $table->addFieldInfo('exported', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
98353ff1 1159 $table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
23207a1a 1160 $table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
4a5d0a39 1161 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
3f2b0c8a 1162 $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
4a5d0a39 1163 $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
3f2b0c8a 1164 $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
b3ac6c3e 1165 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1166 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
f92dcad8 1167
b3ac6c3e 1168 /// Adding keys to table grade_grades
1169 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1170 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
1171 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1172 $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN, array('rawscaleid'), 'scale', array('id'));
1173 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
f92dcad8 1174
173403cf 1175 /// Adding indexes to table grade_grades
6c9f6725 1176 $table->addIndexInfo('locked-locktime', XMLDB_INDEX_NOTUNIQUE, array('locked', 'locktime'));
173403cf 1177
b3ac6c3e 1178 /// Launch create table for grade_grades
1179 $result = $result && create_table($table);
f92dcad8 1180
61c33818 1181
42ff9ce6 1182 /// Define table grade_outcomes_history to be created
1183 $table = new XMLDBTable('grade_outcomes_history');
b3ac6c3e 1184
42ff9ce6 1185 /// Adding fields to table grade_outcomes_history
197ba19c 1186 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
abd30252 1187 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1188 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
42ff9ce6 1189 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1190 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1191 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
b3ac6c3e 1192 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1193 $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1194 $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
1195 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
678a79ca 1196 $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
b3ac6c3e 1197
42ff9ce6 1198 /// Adding keys to table grade_outcomes_history
b3ac6c3e 1199 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
42ff9ce6 1200 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_outcomes', array('id'));
b3ac6c3e 1201 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1202 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
42ff9ce6 1203 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id'));
b3ac6c3e 1204
42ff9ce6 1205 /// Adding indexes to table grade_outcomes_history
1206 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
b3ac6c3e 1207
42ff9ce6 1208 /// Launch create table for grade_outcomes_history
1209 $result = $result && create_table($table);
61c33818 1210
f13002d5 1211
42ff9ce6 1212 /// Define table grade_categories_history to be created
1213 $table = new XMLDBTable('grade_categories_history');
f13002d5 1214
42ff9ce6 1215 /// Adding fields to table grade_categories_history
1216 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
abd30252 1217 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1218 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
42ff9ce6 1219 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1220 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1221 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1222 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1223 $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1224 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1225 $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1226 $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1227 $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1228 $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1229 $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
c2efb501 1230 $table->addFieldInfo('aggregateonlygraded', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
29d509f5 1231 $table->addFieldInfo('aggregateoutcomes', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
c2efb501 1232 $table->addFieldInfo('aggregatesubcats', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
4a129c47 1233
42ff9ce6 1234 /// Adding keys to table grade_categories_history
1235 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1236 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_categories', array('id'));
1237 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1238 $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id'));
1239 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id'));
aaff71da 1240
42ff9ce6 1241 /// Adding indexes to table grade_categories_history
1242 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
aaff71da 1243
42ff9ce6 1244 /// Launch create table for grade_categories_history
1245 $result = $result && create_table($table);
aaff71da 1246
1247
1248 /// Define table grade_items_history to be created
1249 $table = new XMLDBTable('grade_items_history');
1250
1251 /// Adding fields to table grade_items_history
197ba19c 1252 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
abd30252 1253 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1254 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
aaff71da 1255 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1256 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
42ff9ce6 1257 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
aaff71da 1258 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1259 $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1260 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1261 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
1262 $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
1263 $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1264 $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1265 $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1266 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1267 $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1268 $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '1');
1269 $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');
1270 $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1271 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
abd30252 1272 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
aaff71da 1273 $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1274 $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '1.0');
1275 $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
cea2542b 1276 $table->addFieldInfo('aggregationcoef', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
aaff71da 1277 $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
d9266304 1278 $table->addFieldInfo('display', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1279 $table->addFieldInfo('decimals', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null);
aaff71da 1280 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1281 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1282 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1283 $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1284
1285 /// Adding keys to table grade_items_history
1286 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1287 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_items', array('id'));
1288 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1289 $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN, array('categoryid'), 'grade_categories', array('id'));
1290 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
1291 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id'));
42ff9ce6 1292 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id'));
aaff71da 1293
1294 /// Adding indexes to table grade_items_history
1295 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
1296
1297 /// Launch create table for grade_items_history
1298 $result = $result && create_table($table);
1299
1300
aaff71da 1301 /// Define table grade_grades_history to be created
1302 $table = new XMLDBTable('grade_grades_history');
1303
1304 /// Adding fields to table grade_grades_history
197ba19c 1305 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
abd30252 1306 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1307 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
aaff71da 1308 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1309 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
42ff9ce6 1310 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
aaff71da 1311 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1312 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1313 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
1314 $table->addFieldInfo('rawgrademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');
1315 $table->addFieldInfo('rawgrademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1316 $table->addFieldInfo('rawscaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1317 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1318 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
1319 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1320 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1321 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1322 $table->addFieldInfo('exported', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
98353ff1 1323 $table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
23207a1a 1324 $table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
4a5d0a39 1325 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
3f2b0c8a 1326 $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
4a5d0a39 1327 $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
3f2b0c8a 1328 $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
aaff71da 1329
1330 /// Adding keys to table grade_grades_history
1331 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1332 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_grades', array('id'));
1333 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
1334 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1335 $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN, array('rawscaleid'), 'scale', array('id'));
1336 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
42ff9ce6 1337 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id'));
aaff71da 1338
1339 /// Adding indexes to table grade_grades_history
1340 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
1341
1342 /// Launch create table for grade_grades_history
1343 $result = $result && create_table($table);
1344
46d5b312 1345
1346 /// Define table scale_history to be created
1347 $table = new XMLDBTable('scale_history');
1348
1349 /// Adding fields to table scale_history
1350 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1351 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1352 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1353 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1354 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1355 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1356 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1357 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1358 $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1359 $table->addFieldInfo('scale', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
1360 $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
1361
1362 /// Adding keys to table scale_history
1363 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1364 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'scale', array('id'));
1365 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1366 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id'));
1367
1368 /// Adding indexes to table scale_history
1369 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
1370
1371 /// Launch create table for scale_history
1372 $result = $result && create_table($table);
1373
42ff9ce6 1374 /// upgrade the old 1.8 gradebook - migrade data into new grade tables
1375 if ($result) {
42ff9ce6 1376 if ($rs = get_recordset('course')) {
03cedd62 1377 while ($course = rs_fetch_next_record($rs)) {
1378 // this function uses SQL only, it must not be changed after 1.9 goes stable!!
1379 if (!upgrade_18_gradebook($course->id)) {
1380 $result = false;
1381 break;
42ff9ce6 1382 }
1383 }
1384 rs_close($rs);
1385 }
cea2542b 1386 }
8ddcdd86 1387
1388 upgrade_main_savepoint($result, 2007072200);
cea2542b 1389 }
1390
b264019b 1391 if ($result && $oldversion < 2007072400) {
1392 /// Dropping one DEFAULT in a TEXT column. It's was only one remaining
1393 /// since Moodle 1.7, so new servers won't have those anymore.
1394
1395 /// Changing the default of field sessdata on table sessions2 to drop it
1396 $table = new XMLDBTable('sessions2');
1397 $field = new XMLDBField('sessdata');
1398 $field->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null, 'modified');
1399
1400 /// Launch change of default for field sessdata
1401 $result = $result && change_field_default($table, $field);
8ddcdd86 1402
1403 upgrade_main_savepoint($result, 2007072400);
b264019b 1404 }
1405
521d54ec 1406
1407 if ($result && $oldversion < 2007073100) {
271e6dec 1408 /// Define table grade_outcomes_courses to be created
1409 $table = new XMLDBTable('grade_outcomes_courses');
1410
1411 /// Adding fields to table grade_outcomes_courses
abd30252 1412 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
271e6dec 1413 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1414 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1415
1416 /// Adding keys to table grade_outcomes_courses
1417 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1418 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1419 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id'));
f37cc4bb 1420 $table->addKeyInfo('courseid-outcomeid', XMLDB_KEY_UNIQUE, array('courseid', 'outcomeid'));
271e6dec 1421 /// Launch create table for grade_outcomes_courses
e480c18c 1422 $result = $result && create_table($table);
1423
8ddcdd86 1424 upgrade_main_savepoint($result, 2007073100);
e99c48d8 1425 }
173a9d21 1426
79642064 1427
1428 if ($result && $oldversion < 2007073101) { // Add new tag tables
1429
1430 /// Define table tag to be created
1431 $table = new XMLDBTable('tag');
1432
1433 /// Adding fields to table tag
d0578e4e 1434 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1435 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
79642064 1436 $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1437 $table->addFieldInfo('tagtype', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1438 $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
1439 $table->addFieldInfo('descriptionformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, null, null, null);
1440 $table->addFieldInfo('flag', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '0');
1441 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1442
1443 /// Adding keys to table tag
1444 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1445
1446 /// Adding indexes to table tag
1447 $table->addIndexInfo('name', XMLDB_INDEX_UNIQUE, array('name'));
1448
1449 /// Launch create table for tag
1450 $result = $result && create_table($table);
1451
1452
1453
1454 /// Define table tag_correlation to be created
1455 $table = new XMLDBTable('tag_correlation');
1456
1457 /// Adding fields to table tag_correlation
d0578e4e 1458 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1459 $table->addFieldInfo('tagid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
79642064 1460 $table->addFieldInfo('correlatedtags', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
1461
1462 /// Adding keys to table tag_correlation
1463 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1464
1465 /// Adding indexes to table tag_correlation
1466 $table->addIndexInfo('tagid', XMLDB_INDEX_UNIQUE, array('tagid'));
1467
1468 /// Launch create table for tag_correlation
1469 $result = $result && create_table($table);
1470
1471
1472
1473 /// Define table tag_instance to be created
1474 $table = new XMLDBTable('tag_instance');
1475
1476 /// Adding fields to table tag_instance
d0578e4e 1477 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1478 $table->addFieldInfo('tagid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
79642064 1479 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
d0578e4e 1480 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
79642064 1481
1482 /// Adding keys to table tag_instance
1483 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1484
1485 /// Adding indexes to table tag_instance
1486 $table->addIndexInfo('tagiditem', XMLDB_INDEX_NOTUNIQUE, array('tagid', 'itemtype', 'itemid'));
1487
1488 /// Launch create table for tag_instance
1489 $result = $result && create_table($table);
1490
8ddcdd86 1491 upgrade_main_savepoint($result, 2007073101);
79642064 1492 }
1493
1494
705789bd 1495 if ($result && $oldversion < 2007073103) {
1496
1497 /// Define field rawname to be added to tag
1498 $table = new XMLDBTable('tag');
1499 $field = new XMLDBField('rawname');
1500 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'name');
1501
1502 /// Launch add field rawname
1503 $result = $result && add_field($table, $field);
8ddcdd86 1504
1505 upgrade_main_savepoint($result, 2007073103);
705789bd 1506 }
1507
678a79ca 1508 if ($result && $oldversion < 2007073105) {
1509
1510 /// Define field description to be added to grade_outcomes
1511 $table = new XMLDBTable('grade_outcomes');
1512 $field = new XMLDBField('description');
1513 if (!field_exists($table, $field)) {
1514 $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'scaleid');
1515 /// Launch add field description
1516 $result = $result && add_field($table, $field);
1517 }
1518
1519 $table = new XMLDBTable('grade_outcomes_history');
1520 $field = new XMLDBField('description');
1521 if (!field_exists($table, $field)) {
1522 $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'scaleid');
1523 /// Launch add field description
1524 $result = $result && add_field($table, $field);
1525 }
8ddcdd86 1526
1527 upgrade_main_savepoint($result, 2007073105);
678a79ca 1528 }
271e6dec 1529
1f496ded 1530 // adding unique contraint on (courseid,shortname) of an outcome
1531 if ($result && $oldversion < 2007080100) {
1532
1533 /// Define key courseid-shortname (unique) to be added to grade_outcomes
1534 $table = new XMLDBTable('grade_outcomes');
1535 $key = new XMLDBKey('courseid-shortname');
1536 $key->setAttributes(XMLDB_KEY_UNIQUE, array('courseid', 'shortname'));
705789bd 1537
1f496ded 1538 /// Launch add key courseid-shortname
1539 $result = $result && add_key($table, $key);
8ddcdd86 1540
1541 upgrade_main_savepoint($result, 2007080100);
1f496ded 1542 }
705789bd 1543
7d0c81b3 1544 /// originally there was supportname and supportemail upgrade code - this is handled in upgradesettings.php instead
271e6dec 1545
1a85d89a 1546 if ($result && $oldversion < 2007080202) {
32ef9149 1547
1548 /// Define index tagiditem (not unique) to be dropped form tag_instance
1549 $table = new XMLDBTable('tag_instance');
1550 $index = new XMLDBIndex('tagiditem');
1a85d89a 1551 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('tagid', 'itemtype', 'itemid'));
32ef9149 1552
1553 /// Launch drop index tagiditem
1554 drop_index($table, $index);
1555
1556 /// Define index tagiditem (unique) to be added to tag_instance
1a85d89a 1557 $table = new XMLDBTable('tag_instance');
1558 $index = new XMLDBIndex('tagiditem');
32ef9149 1559 $index->setAttributes(XMLDB_INDEX_UNIQUE, array('tagid', 'itemtype', 'itemid'));
1560
1561 /// Launch add index tagiditem
1562 $result = $result && add_index($table, $index);
1563
8ddcdd86 1564 upgrade_main_savepoint($result, 2007080202);
32ef9149 1565 }
1566
29d509f5 1567 if ($result && $oldversion < 2007080300) {
1568
1569 /// Define field aggregateoutcomes to be added to grade_categories
1570 $table = new XMLDBTable('grade_categories');
1571 $field = new XMLDBField('aggregateoutcomes');
1572 if (!field_exists($table, $field)) {
1573 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'droplow');
1574
1575 /// Launch add field aggregateoutcomes
1576 $result = $result && add_field($table, $field);
1577 }
1578
1579 /// Define field aggregateoutcomes to be added to grade_categories
1580 $table = new XMLDBTable('grade_categories_history');
1581 $field = new XMLDBField('aggregateoutcomes');
1582 if (!field_exists($table, $field)) {
1583 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'droplow');
1584
1585 /// Launch add field aggregateoutcomes
1586 $result = $result && add_field($table, $field);
1587 }
8ddcdd86 1588
1589 upgrade_main_savepoint($result, 2007080300);
29d509f5 1590 }
32ef9149 1591
341426f0 1592 if ($result && $oldversion < 2007080800) { /// Normalize course->shortname MDL-10026
1593
1594 /// Changing precision of field shortname on table course to (100)
1595 $table = new XMLDBTable('course');
1596 $field = new XMLDBField('shortname');
1597 $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null, 'fullname');
1598
1599 /// Launch change of precision for field shortname
1600 $result = $result && change_field_precision($table, $field);
8ddcdd86 1601
1602 upgrade_main_savepoint($result, 2007080800);
341426f0 1603 }
1604
c7c57cfb 1605 if ($result && $oldversion < 2007080900) {
1606 /// Add context.path & index
1607 $table = new XMLDBTable('context');
1608 $field = new XMLDBField('path');
7d0c81b3 1609 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'instanceid');
c7c57cfb 1610 $result = $result && add_field($table, $field);
1611 $table = new XMLDBTable('context');
1612 $index = new XMLDBIndex('path');
1613 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('path'));
1614 $result = $result && add_index($table, $index);
1615
1616 /// Add context.depth
1617 $table = new XMLDBTable('context');
1618 $field = new XMLDBField('depth');
1619 $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'path');
1620 $result = $result && add_field($table, $field);
7d0c81b3 1621
1622 /// make sure the system context has proper data
1623 get_system_context(false);
8ddcdd86 1624
1625 upgrade_main_savepoint($result, 2007080900);
c7c57cfb 1626 }
1627
6c9f6725 1628 if ($result && $oldversion < 2007080903) {
173403cf 1629 /// Define index
1630 $table = new XMLDBTable('grade_grades');
6c9f6725 1631 $index = new XMLDBIndex('locked-locktime');
1632 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('locked', 'locktime'));
173403cf 1633
1634 if (!index_exists($table, $index)) {
1635 /// Launch add index
1636 $result = $result && add_index($table, $index);
1637 }
1638
1639 /// Define index
1640 $table = new XMLDBTable('grade_items');
6c9f6725 1641 $index = new XMLDBIndex('locked-locktime');
1642 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('locked', 'locktime'));
173403cf 1643
1644 if (!index_exists($table, $index)) {
1645 /// Launch add index
1646 $result = $result && add_index($table, $index);
1647 }
1648
90274c73 1649 /// Define index itemtype-needsupdate (not unique) to be added to grade_items
1650 $table = new XMLDBTable('grade_items');
1651 $index = new XMLDBIndex('itemtype-needsupdate');
1652 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('itemtype', 'needsupdate'));
1653 if (!index_exists($table, $index)) {
1654 /// Launch add index itemtype-needsupdate
1655 $result = $result && add_index($table, $index);
1656 }
1657
173403cf 1658 /// Define index
1659 $table = new XMLDBTable('grade_items');
90274c73 1660 $index = new XMLDBIndex('gradetype');
1661 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('gradetype'));
173403cf 1662
1663 if (!index_exists($table, $index)) {
1664 /// Launch add index
1665 $result = $result && add_index($table, $index);
1666 }
1667
8ddcdd86 1668 upgrade_main_savepoint($result, 2007080903);
173403cf 1669 }
1670
2524b0f2 1671 if ($result && $oldversion < 2007081000) {
1672 require_once($CFG->dirroot . '/question/upgrade.php');
1673 $result = $result && question_upgrade_context_etc();
8ddcdd86 1674
1675 upgrade_main_savepoint($result, 2007081000);
2524b0f2 1676 }
1677
1678 if ($result && $oldversion < 2007081302) {
2524b0f2 1679
1680 if (table_exists(new XMLDBTable('groups_groupings'))) {
1681 /// IF 'groups_groupings' table exists, this is for 1.8.* only.
1682 $result = $result && upgrade_18_groups();
1683
1684 } else {
1685 /// ELSE, 1.7.*/1.6.*/1.5.* - create 'groupings' and 'groupings_groups' + rename password to enrolmentkey
1686 $result = $result && upgrade_17_groups();
1687 }
1688
1689 /// For both 1.8.* and 1.7.*/1.6.*..
1690
1691 // delete not used fields
1692 $table = new XMLDBTable('groups');
1693 $field = new XMLDBField('theme');
1694 if (field_exists($table, $field)) {
1695 drop_field($table, $field);
1696 }
1697 $table = new XMLDBTable('groups');
1698 $field = new XMLDBField('lang');
1699 if (field_exists($table, $field)) {
1700 drop_field($table, $field);
1701 }
1702
1703 /// Add groupingid field/f.key to 'course' table.
1704 $table = new XMLDBTable('course');
1705 $field = new XMLDBField('defaultgroupingid');
1706 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', $prev='groupmodeforce');
1707 $result = $result && add_field($table, $field);
1708
1709
1710 /// Add grouping ID, grouponly field/f.key to 'course_modules' table.
1711 $table = new XMLDBTable('course_modules');
1712 $field = new XMLDBField('groupingid');
1713 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', $prev='groupmode');
1714 $result = $result && add_field($table, $field);
1715
1716 $table = new XMLDBTable('course_modules');
1717 $field = new XMLDBField('groupmembersonly');
1718 $field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', $prev='groupingid');
1719 $result = $result && add_field($table, $field);
1720
1721 $table = new XMLDBTable('course_modules');
1722 $key = new XMLDBKey('groupingid');
1723 $key->setAttributes(XMLDB_KEY_FOREIGN, array('groupingid'), 'groupings', array('id'));
1724 $result = $result && add_key($table, $key);
1725
8ddcdd86 1726 upgrade_main_savepoint($result, 2007081302);
2524b0f2 1727 }
1728
1acd661d 1729 if ($result && $oldversion < 2007082300) {
1730
1731 /// Define field ordering to be added to tag_instance table
1732 $table = new XMLDBTable('tag_instance');
1733 $field = new XMLDBField('ordering');
e480c18c 1734
1acd661d 1735 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'itemid');
1736
1737 /// Launch add field rawname
1738 $result = $result && add_field($table, $field);
8ddcdd86 1739
1740 upgrade_main_savepoint($result, 2007082300);
e480c18c 1741 }
2524b0f2 1742
a4232e95 1743 if ($result && $oldversion < 2007082700) {
1744
1745 /// Define field timemodified to be added to tag_instance
1746 $table = new XMLDBTable('tag_instance');
1747 $field = new XMLDBField('timemodified');
1748 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'ordering');
1749
1750 /// Launch add field timemodified
1751 $result = $result && add_field($table, $field);
8ddcdd86 1752
1753 upgrade_main_savepoint($result, 2007082700);
a4232e95 1754 }
e480c18c 1755
535c0080 1756 /// migrate all tags table to tag - this code MUST use SQL only,
1757 /// because if the db structure changes the library functions will fail in future
bd1f4559 1758 if ($result && $oldversion < 2007082701) {
bd1f4559 1759 $tagrefs = array(); // $tagrefs[$oldtagid] = $newtagid
535c0080 1760 if ($rs = get_recordset('tags')) {
1761 $db->debug = false;
03cedd62 1762 while ($oldtag = rs_fetch_next_record($rs)) {
1763 $raw_normalized = clean_param($oldtag->text, PARAM_TAG);
1764 $normalized = moodle_strtolower($raw_normalized);
1765 // if this tag does not exist in tag table yet
1766 if (!$newtag = get_record('tag', 'name', $normalized, '', '', '', '', 'id')) {
1767 $itag = new object();
1768 $itag->name = $normalized;
1769 $itag->rawname = $raw_normalized;
1770 $itag->userid = $oldtag->userid;
1771 $itag->timemodified = time();
1772 $itag->descriptionformat = 0; // default format
1773 if ($oldtag->type == 'official') {
1774 $itag->tagtype = 'official';
535c0080 1775 } else {
03cedd62 1776 $itag->tagtype = 'default';
bd1f4559 1777 }
03cedd62 1778
1779 if ($idx = insert_record('tag', $itag)) {
1780 $tagrefs[$oldtag->id] = $idx;
1781 }
1782 // if this tag is already used by tag table
1783 } else {
1784 $tagrefs[$oldtag->id] = $newtag->id;
bd1f4559 1785 }
1786 }
535c0080 1787 $db->debug = true;
1788 rs_close($rs);
bd1f4559 1789 }
e480c18c 1790
bd1f4559 1791 // fetch all the tag instances and migrate them as well
535c0080 1792 if ($rs = get_recordset('blog_tag_instance')) {
1793 $db->debug = false;
03cedd62 1794 while ($blogtag = rs_fetch_next_record($rs)) {
1795 if (array_key_exists($blogtag->tagid, $tagrefs)) {
1796 $tag_instance = new object();
1797 $tag_instance->tagid = $tagrefs[$blogtag->tagid];
1798 $tag_instance->itemtype = 'blog';
1799 $tag_instance->itemid = $blogtag->entryid;
1800 $tag_instance->ordering = 1; // does not matter much, because originally there was no ordering in blogs
1801 $tag_instance->timemodified = time();
1802 insert_record('tag_instance', $tag_instance);
bd1f4559 1803 }
1804 }
535c0080 1805 $db->debug = true;
1806 rs_close($rs);
bd1f4559 1807 }
1808
535c0080 1809 unset($tagrefs); // release memory
1810
bd1f4559 1811 $table = new XMLDBTable('tags');
1812 drop_table($table);
1813 $table = new XMLDBTable('blog_tag_instance');
1814 drop_table($table);
8ddcdd86 1815
1816 upgrade_main_savepoint($result, 2007082701);
bd1f4559 1817 }
e480c18c 1818
c4956945 1819 /// MDL-11015, MDL-11016
1820 if ($result && $oldversion < 2007082800) {
1821
1822 /// Changing type of field userid on table tag to int
1823 $table = new XMLDBTable('tag');
1824 $field = new XMLDBField('userid');
1825 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');
1826
1827 /// Launch change of type for field userid
1828 $result = $result && change_field_type($table, $field);
e480c18c 1829
c4956945 1830 /// Changing type of field descriptionformat on table tag to int
1831 $table = new XMLDBTable('tag');
1832 $field = new XMLDBField('descriptionformat');
1833 $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'description');
1834
1835 /// Launch change of type for field descriptionformat
1836 $result = $result && change_field_type($table, $field);
e480c18c 1837
c4956945 1838 /// Define key userid (foreign) to be added to tag
1839 $table = new XMLDBTable('tag');
1840 $key = new XMLDBKey('userid');
1841 $key->setAttributes(XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1842
1843 /// Launch add key userid
1844 $result = $result && add_key($table, $key);
e480c18c 1845
c4956945 1846 /// Define index tagiditem (unique) to be dropped form tag_instance
1847 $table = new XMLDBTable('tag_instance');
1848 $index = new XMLDBIndex('tagiditem');
1849 $index->setAttributes(XMLDB_INDEX_UNIQUE, array('tagid', 'itemtype', 'itemid'));
1850
1851 /// Launch drop index tagiditem
1852 $result = $result && drop_index($table, $index);
e480c18c 1853
c4956945 1854 /// Changing type of field tagid on table tag_instance to int
1855 $table = new XMLDBTable('tag_instance');
1856 $field = new XMLDBField('tagid');
1857 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');
1858
1859 /// Launch change of type for field tagid
1860 $result = $result && change_field_type($table, $field);
e480c18c 1861
c4956945 1862 /// Define key tagid (foreign) to be added to tag_instance
1863 $table = new XMLDBTable('tag_instance');
1864 $key = new XMLDBKey('tagid');
1865 $key->setAttributes(XMLDB_KEY_FOREIGN, array('tagid'), 'tag', array('id'));
1866
1867 /// Launch add key tagid
e480c18c 1868 $result = $result && add_key($table, $key);
c4956945 1869
1870 /// Changing sign of field itemid on table tag_instance to unsigned
1871 $table = new XMLDBTable('tag_instance');
1872 $field = new XMLDBField('itemid');
1873 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'itemtype');
1874
1875 /// Launch change of sign for field itemid
1876 $result = $result && change_field_unsigned($table, $field);
e480c18c 1877
c4956945 1878 /// Changing sign of field ordering on table tag_instance to unsigned
1879 $table = new XMLDBTable('tag_instance');
1880 $field = new XMLDBField('ordering');
1881 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'itemid');
1882
1883 /// Launch change of sign for field ordering
e480c18c 1884 $result = $result && change_field_unsigned($table, $field);
1885
c4956945 1886 /// Define index itemtype-itemid-tagid (unique) to be added to tag_instance
1887 $table = new XMLDBTable('tag_instance');
1888 $index = new XMLDBIndex('itemtype-itemid-tagid');
1889 $index->setAttributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));
1890
1891 /// Launch add index itemtype-itemid-tagid
1892 $result = $result && add_index($table, $index);
e480c18c 1893
c4956945 1894 /// Define index tagid (unique) to be dropped form tag_correlation
1895 $table = new XMLDBTable('tag_correlation');
1896 $index = new XMLDBIndex('tagid');
1897 $index->setAttributes(XMLDB_INDEX_UNIQUE, array('tagid'));
1898
1899 /// Launch drop index tagid
e480c18c 1900 $result = $result && drop_index($table, $index);
1901
c4956945 1902 /// Changing type of field tagid on table tag_correlation to int
1903 $table = new XMLDBTable('tag_correlation');
1904 $field = new XMLDBField('tagid');
1905 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');
1906
1907 /// Launch change of type for field tagid
1908 $result = $result && change_field_type($table, $field);
e480c18c 1909
1910
c4956945 1911 /// Define key tagid (foreign) to be added to tag_correlation
1912 $table = new XMLDBTable('tag_correlation');
1913 $key = new XMLDBKey('tagid');
1914 $key->setAttributes(XMLDB_KEY_FOREIGN, array('tagid'), 'tag', array('id'));
1915
1916 /// Launch add key tagid
1917 $result = $result && add_key($table, $key);
e480c18c 1918
8ddcdd86 1919 upgrade_main_savepoint($result, 2007082800);
e480c18c 1920 }
61c6071f 1921
1922
1923 if ($result && $oldversion < 2007082801) {
1924
1925 /// Define table user_private_key to be created
1926 $table = new XMLDBTable('user_private_key');
1927
1928 /// Adding fields to table user_private_key
1929 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1930 $table->addFieldInfo('script', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null, null, null);
1931 $table->addFieldInfo('value', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null, null, null);
1932 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1933 $table->addFieldInfo('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1934 $table->addFieldInfo('iprestriction', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1935 $table->addFieldInfo('validuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1936 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1937
1938 /// Adding keys to table user_private_key
1939 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1940 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1941
1942 /// Adding indexes to table user_private_key
1943 $table->addIndexInfo('script-value', XMLDB_INDEX_NOTUNIQUE, array('script', 'value'));
1944
1945 /// Launch create table for user_private_key
1946 $result = $result && create_table($table);
8ddcdd86 1947
1948 upgrade_main_savepoint($result, 2007082801);
61c6071f 1949 }
1950
4149e289 1951/// Going to modify the applicationid from int(1) to int(10). Dropping and
1952/// re-creating the associated keys/indexes is mandatory to be cross-db. MDL-11042
1953 if ($result && $oldversion < 2007082803) {
1954
1955 /// Define key applicationid (foreign) to be dropped form mnet_host
1956 $table = new XMLDBTable('mnet_host');
1957 $key = new XMLDBKey('applicationid');
1958 $key->setAttributes(XMLDB_KEY_FOREIGN, array('applicationid'), 'mnet_application', array('id'));
1959
1960 /// Launch drop key applicationid
1961 $result = $result && drop_key($table, $key);
1962
1963 /// Changing type of field applicationid on table mnet_host to int
1964 $field = new XMLDBField('applicationid');
1965 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'last_log_id');
1966
1967 /// Launch change of type for field applicationid
1968 $result = $result && change_field_type($table, $field);
1969
1970 /// Define key applicationid (foreign) to be added to mnet_host
1971 $key = new XMLDBKey('applicationid');
1972 $key->setAttributes(XMLDB_KEY_FOREIGN, array('applicationid'), 'mnet_application', array('id'));
1973
1974 /// Launch add key applicationid
1975 $result = $result && add_key($table, $key);
1976
8ddcdd86 1977 upgrade_main_savepoint($result, 2007082803);
4149e289 1978 }
1979
c2efb501 1980 if ($result && $oldversion < 2007090503) {
c2efb501 1981 /// Define field aggregatesubcats to be added to grade_categories
1982 $table = new XMLDBTable('grade_categories');
1983 $field = new XMLDBField('aggregatesubcats');
1984 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'aggregateoutcomes');
1985
1986 if (!field_exists($table, $field)) {
1987 /// Launch add field aggregateonlygraded
1988 $result = $result && add_field($table, $field);
1989 }
1990
1991 /// Define field aggregateonlygraded to be added to grade_categories
1992 $table = new XMLDBTable('grade_categories');
1993 $field = new XMLDBField('aggregateonlygraded');
1994 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'droplow');
1995
1996 if (!field_exists($table, $field)) {
1997 /// Launch add field aggregateonlygraded
1998 $result = $result && add_field($table, $field);
1999 }
2000
2001 /// Define field aggregatesubcats to be added to grade_categories_history
2002 $table = new XMLDBTable('grade_categories_history');
2003 $field = new XMLDBField('aggregatesubcats');
2004 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'aggregateoutcomes');
2005
2006 if (!field_exists($table, $field)) {
2007 /// Launch add field aggregateonlygraded
2008 $result = $result && add_field($table, $field);
2009 }
2010
2011 /// Define field aggregateonlygraded to be added to grade_categories_history
2012 $table = new XMLDBTable('grade_categories_history');
2013 $field = new XMLDBField('aggregateonlygraded');
2014 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'droplow');
2015
2016 if (!field_exists($table, $field)) {
2017 /// Launch add field aggregateonlygraded
2018 $result = $result && add_field($table, $field);
2019 }
2020
2021 /// upgrade path in grade_categrories table - now using slash on both ends
2022 $concat = sql_concat('path', "'/'");
2023 $sql = "UPDATE {$CFG->prefix}grade_categories SET path = $concat WHERE path NOT LIKE '/%/'";
2024 execute_sql($sql, true);
2025
2026 /// convert old aggregation constants if needed
2027 for ($i=0; $i<=12; $i=$i+2) {
2028 $j = $i+1;
2029 $sql = "UPDATE {$CFG->prefix}grade_categories SET aggregation = $i, aggregateonlygraded = 1 WHERE aggregation = $j";
2030 execute_sql($sql, true);
2031 }
8ddcdd86 2032
2033 upgrade_main_savepoint($result, 2007090503);
c2efb501 2034 }
2035
4a039315 2036/// To have UNIQUE indexes over NULLable columns isn't cross-db at all
2037/// so we create a non unique index and programatically enforce uniqueness
2038 if ($result && $oldversion < 2007090600) {
2039
2040 /// Define index idnumber (unique) to be dropped form course_modules
2041 $table = new XMLDBTable('course_modules');
2042 $index = new XMLDBIndex('idnumber');
2043 $index->setAttributes(XMLDB_INDEX_UNIQUE, array('idnumber'));
2044
2045 /// Launch drop index idnumber
2046 $result = $result && drop_index($table, $index);
2047
2048 /// Define index idnumber-course (not unique) to be added to course_modules
2049 $table = new XMLDBTable('course_modules');
2050 $index = new XMLDBIndex('idnumber-course');
2051 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('idnumber', 'course'));
2052
2053 /// Launch add index idnumber-course
2054 $result = $result && add_index($table, $index);
2055
2056 /// Define index idnumber-courseid (not unique) to be added to grade_items
2057 $table = new XMLDBTable('grade_items');
2058 $index = new XMLDBIndex('idnumber-courseid');
2059 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('idnumber', 'courseid'));
2060
2061 /// Launch add index idnumber-courseid
2062 $result = $result && add_index($table, $index);
2063
8ddcdd86 2064 upgrade_main_savepoint($result, 2007090600);
4a039315 2065 }
c2efb501 2066
d5d2f8a6 2067/// Create the permanent context_temp table to be used by build_context_path()
2068 if ($result && $oldversion < 2007092001) {
2069
2070 /// Define table context_temp to be created
2071 $table = new XMLDBTable('context_temp');
2072
2073 /// Adding fields to table context_temp
2074 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
4a5d0a39 2075 $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
d5d2f8a6 2076 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
2077
2078 /// Adding keys to table context_temp
2079 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
2080
2081 /// Launch create table for context_temp
2082 $result = $result && create_table($table);
2083
b3847656 2084 /// make sure category depths, parents and paths are ok, categories from 1.5 may not be properly initialized (MDL-12585)
863850d2 2085 upgrade_fix_category_depths();
b3847656 2086
d5d2f8a6 2087 /// Recalculate depths, paths and so on
7d0c81b3 2088 if (!empty($CFG->rolesactive)) {
2089 cleanup_contexts();
8a4d32d8 2090 // make sure all course, category and user contexts exist - we need it for grade letter upgrade, etc.
2091 create_contexts(CONTEXT_COURSE, false, true);
2092 create_contexts(CONTEXT_USER, false, true);
2093 // we need all contexts path/depths filled properly
2094 build_context_path(true, true);
7d0c81b3 2095 load_all_capabilities();
8a4d32d8 2096
2097 } else {
2098 // upgrade from 1.6 - build all contexts
2099 create_contexts(null, true, true);
7d0c81b3 2100 }
8ddcdd86 2101
2102 upgrade_main_savepoint($result, 2007092001);
c24f4599 2103 }
2104
3f2b0c8a 2105 /**
2106 * Merging of grade_grades_text back into grade_grades
2107 */
2108 if ($result && $oldversion < 2007092002) {
2109
3f2b0c8a 2110 /// Define field feedback to be added to grade_grades
2111 $table = new XMLDBTable('grade_grades');
2112 $field = new XMLDBField('feedback');
4a5d0a39 2113 $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'excluded');
3f2b0c8a 2114
2115 if (!field_exists($table, $field)) {
2116 /// Launch add field feedback
2117 $result = $result && add_field($table, $field);
2118 }
2119
2120 /// Define field feedbackformat to be added to grade_grades
2121 $table = new XMLDBTable('grade_grades');
2122 $field = new XMLDBField('feedbackformat');
2123 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'feedback');
2124
2125 if (!field_exists($table, $field)) {
2126 /// Launch add field feedbackformat
2127 $result = $result && add_field($table, $field);
2128 }
2129
2130 /// Define field information to be added to grade_grades
2131 $table = new XMLDBTable('grade_grades');
2132 $field = new XMLDBField('information');
4a5d0a39 2133 $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'feedbackformat');
3f2b0c8a 2134
2135 if (!field_exists($table, $field)) {
2136 /// Launch add field information
2137 $result = $result && add_field($table, $field);
2138 }
2139
2140 /// Define field informationformat to be added to grade_grades
2141 $table = new XMLDBTable('grade_grades');
2142 $field = new XMLDBField('informationformat');
2143 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'information');
2144
2145 if (!field_exists($table, $field)) {
2146 /// Launch add field informationformat
2147 $result = $result && add_field($table, $field);
2148 }
2149
2150 /// Define field feedback to be added to grade_grades_history
2151 $table = new XMLDBTable('grade_grades_history');
2152 $field = new XMLDBField('feedback');
4a5d0a39 2153 $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'excluded');
3f2b0c8a 2154
2155 if (!field_exists($table, $field)) {
2156 /// Launch add field feedback
2157 $result = $result && add_field($table, $field);
2158 }
2159
2160 /// Define field feedbackformat to be added to grade_grades_history
2161 $table = new XMLDBTable('grade_grades_history');
2162 $field = new XMLDBField('feedbackformat');
2163 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'feedback');
2164
2165 if (!field_exists($table, $field)) {
2166 /// Launch add field feedbackformat
2167 $result = $result && add_field($table, $field);
2168 }
2169
2170 /// Define field information to be added to grade_grades_history
2171 $table = new XMLDBTable('grade_grades_history');
2172 $field = new XMLDBField('information');
4a5d0a39 2173 $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'feedbackformat');
3f2b0c8a 2174
2175 if (!field_exists($table, $field)) {
2176 /// Launch add field information
2177 $result = $result && add_field($table, $field);
2178 }
2179
2180 /// Define field informationformat to be added to grade_grades_history
2181 $table = new XMLDBTable('grade_grades_history');
2182 $field = new XMLDBField('informationformat');
2183 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'information');
2184
2185 if (!field_exists($table, $field)) {
2186 /// Launch add field informationformat
2187 $result = $result && add_field($table, $field);
2188 }
2189
2190 $table = new XMLDBTable('grade_grades_text');
2191 if ($result and table_exists($table)) {
2192 //migrade existing data into grade_grades table - this is slow but works for all dbs,
2193 //it will be executed on development sites only
2194 $fields = array('feedback', 'information');
2195 foreach ($fields as $field) {
2196 $sql = "UPDATE {$CFG->prefix}grade_grades
2197 SET $field = (
2198 SELECT $field
2199 FROM {$CFG->prefix}grade_grades_text ggt
2200 WHERE ggt.gradeid = {$CFG->prefix}grade_grades.id)";
2201 $result = execute_sql($sql) && $result;
2202 }
2203 $fields = array('feedbackformat', 'informationformat');
2204 foreach ($fields as $field) {
2205 $sql = "UPDATE {$CFG->prefix}grade_grades
2206 SET $field = COALESCE((
2207 SELECT $field
2208 FROM {$CFG->prefix}grade_grades_text ggt
2209 WHERE ggt.gradeid = {$CFG->prefix}grade_grades.id), 0)";
2210 $result = execute_sql($sql) && $result;
2211 }
2212
2213 if ($result) {
2214 $tables = array('grade_grades_text', 'grade_grades_text_history');
52cb2e47 2215
3f2b0c8a 2216 foreach ($tables as $table) {
2217 $table = new XMLDBTable($table);
2218 if (table_exists($table)) {
2219 drop_table($table);
2220 }
2221 }
2222 }
2223 }
8ddcdd86 2224
2225 upgrade_main_savepoint($result, 2007092002);
3f2b0c8a 2226 }
c2efb501 2227
d9266304 2228 if ($result && $oldversion < 2007092803) {
b39b58fe 2229
d9266304 2230/// Remove obsoleted unit tests tables - they will be recreated automatically
2231 $tables = array('grade_categories',
2232 'scale',
2233 'grade_items',
2234 'grade_calculations',
2235 'grade_grades',
2236 'grade_grades_raw',
2237 'grade_grades_final',
2238 'grade_grades_text',
2239 'grade_outcomes',
2240 'grade_outcomes_courses');
2241
2242 foreach ($tables as $tablename) {
2243 $table = new XMLDBTable('unittest_'.$tablename);
2244 if (table_exists($table)) {
2245 drop_table($table);
2246 }
2247 $table = new XMLDBTable('unittest_'.$tablename.'_history');
2248 if (table_exists($table)) {
2249 drop_table($table);
2250 }
2251 }
2252
2253 /// Define field display to be added to grade_items
2254 $table = new XMLDBTable('grade_items');
2255 $field = new XMLDBField('display');
2256 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0', 'sortorder');
2257
2258 /// Launch add field display
2259 if (!field_exists($table, $field)) {
2260 $result = $result && add_field($table, $field);
2261 } else {
2262 $result = $result && change_field_default($table, $field);
2263 }
2264
2265 /// Define field display to be added to grade_items_history
2266 $table = new XMLDBTable('grade_items_history');
2267 $field = new XMLDBField('display');
2268 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0', 'sortorder');
2269
2270 /// Launch add field display
2271 if (!field_exists($table, $field)) {
2272 $result = $result && add_field($table, $field);
2273 }
2274
2275
2276 /// Define field decimals to be added to grade_items
b39b58fe 2277 $table = new XMLDBTable('grade_items');
2278 $field = new XMLDBField('decimals');
2279 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null, 'display');
2280
d9266304 2281 /// Launch add field decimals
2282 if (!field_exists($table, $field)) {
2283 $result = $result && add_field($table, $field);
2284 } else {
2285 $result = $result && change_field_default($table, $field);
2286 $result = $result && change_field_notnull($table, $field);
2287 }
b39b58fe 2288
d9266304 2289 /// Define field decimals to be added to grade_items_history
2290 $table = new XMLDBTable('grade_items_history');
b39b58fe 2291 $field = new XMLDBField('decimals');
2292 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null, 'display');
2293
d9266304 2294 /// Launch add field decimals
2295 if (!field_exists($table, $field)) {
2296 $result = $result && add_field($table, $field);
2297 }
b39b58fe 2298
284abb09 2299
d9266304 2300 /// fix incorrect -1 default for grade_item->display
2301 execute_sql("UPDATE {$CFG->prefix}grade_items SET display=0 WHERE display=-1");
8ddcdd86 2302
2303 upgrade_main_savepoint($result, 2007092803);
5cf5e181 2304 }
2305
8a4d32d8 2306/// migrade grade letters - we can not do this in normal grades upgrade becuase we need all course contexts
5cf5e181 2307 if ($result && $oldversion < 2007092806) {
5cf5e181 2308
8a4d32d8 2309 $result = upgrade_18_letters();
284abb09 2310
5cf5e181 2311 /// Define index contextidlowerboundary (not unique) to be added to grade_letters
2312 $table = new XMLDBTable('grade_letters');
2313 $index = new XMLDBIndex('contextid-lowerboundary');
2314 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
2315
2316 /// Launch add index contextidlowerboundary
2317 if (!index_exists($table, $index)) {
2318 $result = $result && add_index($table, $index);
2319 }
8ddcdd86 2320
2321 upgrade_main_savepoint($result, 2007092806);
284abb09 2322 }
2323
e4a5c864 2324 if ($result && $oldversion < 2007100100) {
2325
e4a5c864 2326 /// Define table cache_flags to be created
2327 $table = new XMLDBTable('cache_flags');
2328
2329 /// Adding fields to table cache_flags
2330 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
2331 $table->addFieldInfo('flagtype', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
2332 $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
2333 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
2334 $table->addFieldInfo('value', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
2335 $table->addFieldInfo('expiry', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
2336
2337 /// Adding keys to table cache_flags
2338 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
2339
266f6b59 2340 /*
2341 * Note: mysql can not create indexes on text fields larger than 333 chars!
2342 */
2343
e4a5c864 2344 /// Adding indexes to table cache_flags
266f6b59 2345 $table->addIndexInfo('flagtype', XMLDB_INDEX_NOTUNIQUE, array('flagtype'));
2346 $table->addIndexInfo('name', XMLDB_INDEX_NOTUNIQUE, array('name'));
e4a5c864 2347
2348 /// Launch create table for cache_flags
266f6b59 2349 if (!table_exists($table)) {
2350 $result = $result && create_table($table);
c2efb501 2351 }
8ddcdd86 2352
2353 upgrade_main_savepoint($result, 2007100100);
c2efb501 2354 }
c2efb501 2355
c57be126 2356
38d507af 2357 if ($oldversion < 2007100300) {
c57be126 2358 /// MNET stuff for roaming theme
2359 /// Define field force_theme to be added to mnet_host
ac4e96fc 2360 $table = new XMLDBTable('mnet_host');
ac4e96fc 2361 $field = new XMLDBField('force_theme');
c57be126 2362 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'last_log_id');
ac4e96fc 2363
c57be126 2364 /// Launch add field force_theme
ac4e96fc 2365 $result = $result && add_field($table, $field);
2366
c57be126 2367 /// Define field theme to be added to mnet_host
2368 $table = new XMLDBTable('mnet_host');
ac4e96fc 2369 $field = new XMLDBField('theme');
2370 $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null, 'force_theme');
2371
c57be126 2372 /// Launch add field theme
ac4e96fc 2373 $result = $result && add_field($table, $field);
8ddcdd86 2374
2375 upgrade_main_savepoint($result, 2007100300);
ac4e96fc 2376 }
2377
266f6b59 2378 if ($result && $oldversion < 2007100301) {
2379
2380 /// Define table cache_flags to be created
2381 $table = new XMLDBTable('cache_flags');
2382 $index = new XMLDBIndex('typename');
2383 if (index_exists($table, $index)) {
2384 $result = $result && drop_index($table, $index);
2385 }
2386
2387 $table = new XMLDBTable('cache_flags');
2388 $index = new XMLDBIndex('flagtype');
2389 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('flagtype'));
2390 if (!index_exists($table, $index)) {
2391 $result = $result && add_index($table, $index);
2392 }
2393
2394 $table = new XMLDBTable('cache_flags');
2395 $index = new XMLDBIndex('name');
2396 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('name'));
2397 if (!index_exists($table, $index)) {
2398 $result = $result && add_index($table, $index);
2399 }
8ddcdd86 2400
2401 upgrade_main_savepoint($result, 2007100301);
266f6b59 2402 }
2403
c626c2f4 2404 if ($result && $oldversion < 2007100303) {
2405
2406 /// Changing nullability of field summary on table course to null
2407 $table = new XMLDBTable('course');
2408 $field = new XMLDBField('summary');
2409 $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'idnumber');
2410
2411 /// Launch change of nullability for field summary
2412 $result = $result && change_field_notnull($table, $field);
8ddcdd86 2413
2414 upgrade_main_savepoint($result, 2007100303);
c626c2f4 2415 }
266f6b59 2416
7d0c81b3 2417 if ($result && $oldversion < 2007100500) {
2418 /// for dev sites - it is ok to do this repeatedly
2419
2420 /// Changing nullability of field path on table context to null
2421 $table = new XMLDBTable('context');
2422 $field = new XMLDBField('path');
2423 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'instanceid');
2424
2425 /// Launch change of nullability for field path
2426 $result = $result && change_field_notnull($table, $field);
8ddcdd86 2427
2428 upgrade_main_savepoint($result, 2007100500);
7d0c81b3 2429 }
2430
8108909a 2431 if ($result && $oldversion < 2007100700) {
2432
2433 /// first drop existing tables - we do not need any data from there
2434 $table = new XMLDBTable('grade_import_values');
2435 if (table_exists($table)) {
2436 drop_table($table);
2437 }
2438
2439 $table = new XMLDBTable('grade_import_newitem');
2440 if (table_exists($table)) {
2441 drop_table($table);
2442 }
2443
2444 /// Define table grade_import_newitem to be created
2445 $table = new XMLDBTable('grade_import_newitem');
2446
2447 /// Adding fields to table grade_import_newitem
2448 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
4a5d0a39 2449 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
8108909a 2450 $table->addFieldInfo('importcode', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
2451 $table->addFieldInfo('importer', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
2452
2453 /// Adding keys to table grade_import_newitem
2454 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
2455 $table->addKeyInfo('importer', XMLDB_KEY_FOREIGN, array('importer'), 'user', array('id'));
2456
2457 /// Launch create table for grade_import_newitem
2458 $result = $result && create_table($table);
2459
2460
2461 /// Define table grade_import_values to be created
2462 $table = new XMLDBTable('grade_import_values');
2463
2464 /// Adding fields to table grade_import_values
2465 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
2466 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
2467 $table->addFieldInfo('newgradeitem', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
2468 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
2469 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
4a5d0a39 2470 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
8108909a 2471 $table->addFieldInfo('importcode', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
2472 $table->addFieldInfo('importer', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
2473
2474 /// Adding keys to table grade_import_values
2475 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
2476 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
2477 $table->addKeyInfo('newgradeitem', XMLDB_KEY_FOREIGN, array('newgradeitem'), 'grade_import_newitem', array('id'));
2478 $table->addKeyInfo('importer', XMLDB_KEY_FOREIGN, array('importer'), 'user', array('id'));
2479
2480 /// Launch create table for grade_import_values
2481 $result = $result && create_table($table);
2482
8ddcdd86 2483 upgrade_main_savepoint($result, 2007100700);
e0724506 2484 }
2485
eeccaea1 2486/// dropping context_rel table - not used anymore
a506e40c 2487 if ($result && $oldversion < 2007100800) {
266f6b59 2488
a506e40c 2489 /// Define table context_rel to be dropped
2490 $table = new XMLDBTable('context_rel');
2491
2492 /// Launch drop table for context_rel
eeccaea1 2493 if (table_exists($table)) {
2494 drop_table($table);
2495 }
8ddcdd86 2496
2497 upgrade_main_savepoint($result, 2007100800);
a506e40c 2498 }
266f6b59 2499
cef1ea8e 2500/// Truncate the text_cahe table and add new index
2501 if ($result && $oldversion < 2007100802) {
2502
2503 /// Truncate the cache_text table
2504 execute_sql("TRUNCATE TABLE {$CFG->prefix}cache_text", true);
2505
2506 /// Define index timemodified (not unique) to be added to cache_text
2507 $table = new XMLDBTable('cache_text');
2508 $index = new XMLDBIndex('timemodified');
2509 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
2510
2511 /// Launch add index timemodified
2512 $result = $result && add_index($table, $index);
8ddcdd86 2513
2514 upgrade_main_savepoint($result, 2007100802);
2515 }
2516
2517/// newtable for gradebook settings per course
2518 if ($result && $oldversion < 2007100803) {
2519
2520 /// Define table grade_settings to be created
2521 $table = new XMLDBTable('grade_settings');
2522
2523 /// Adding fields to table grade_settings
2524 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
2525 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
2526 $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
2527 $table->addFieldInfo('value', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
2528
2529 /// Adding keys to table grade_settings
2530 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
2531 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
2532
2533 /// Adding indexes to table grade_settings
2534 $table->addIndexInfo('courseid-name', XMLDB_INDEX_UNIQUE, array('courseid', 'name'));
2535
2536 /// Launch create table for grade_settings
2537 $result = $result && create_table($table);
2538
2539 upgrade_main_savepoint($result, 2007100803);
cef1ea8e 2540 }
2541
8600cada 2542/// cleanup in user_lastaccess
2543 if ($result && $oldversion < 2007100902) {
2544 $sql = "DELETE
2545 FROM {$CFG->prefix}user_lastaccess
2546 WHERE NOT EXISTS (SELECT 'x'
2547 FROM {$CFG->prefix}course c
2548 WHERE c.id = {$CFG->prefix}user_lastaccess.courseid)";
2549 execute_sql($sql);
8ddcdd86 2550
2551 upgrade_main_savepoint($result, 2007100902);
8600cada 2552 }
2553
eeccaea1 2554/// drop old gradebook tables
2555 if ($result && $oldversion < 2007100903) {
8600cada 2556 $tables = array('grade_category',
2557 'grade_item',
2558 'grade_letter',
2559 'grade_preferences',
2560 'grade_exceptions');
2561
2562 foreach ($tables as $table) {
2563 $table = new XMLDBTable($table);
2564 if (table_exists($table)) {
2565 drop_table($table);
2566 }
2567 }
8ddcdd86 2568
2569 upgrade_main_savepoint($result, 2007100903);
8600cada 2570 }
56a1a882 2571
2d4cf36b 2572 if ($result && $oldversion < 2007101500 && !file_exists($CFG->dataroot . '/user')) {
56a1a882 2573 // Get list of users by browsing moodledata/user
2574 $oldusersdir = $CFG->dataroot . '/users';
2575 $folders = get_directory_list($oldusersdir, '', false, true, false);
2576
2577 foreach ($folders as $userid) {
2578 $olddir = $oldusersdir . '/' . $userid;
fc278e84 2579 $files = get_directory_list($olddir);
2580
2581 if (empty($files)) {
2582 continue;
2583 }
56a1a882 2584
2585 // Create new user directory
2586 if (!$newdir = make_user_directory($userid)) {
8d08612b 2587 // some weird directory - do not stop the upgrade, just ignore it
2588 continue;
56a1a882 2589 }
eeccaea1 2590
56a1a882 2591 // Move contents of old directory to new one
2592 if (file_exists($olddir) && file_exists($newdir)) {
56a1a882 2593 foreach ($files as $file) {
2594 copy($olddir . '/' . $file, $newdir . '/' . $file);
2595 }
2596 } else {
2597 notify("Could not move the contents of $olddir into $newdir!");
2598 $result = false;
2599 break;
2600 }
2601 }
eeccaea1 2602
56a1a882 2603 // Leave a README in old users directory
2604 $readmefilename = $oldusersdir . '/README.txt';
2605 if ($handle = fopen($readmefilename, 'w+b')) {
2606 if (!fwrite($handle, get_string('olduserdirectory'))) {
2607 // Could not write to the readme file. No cause for huge concern
2608 notify("Could not write to the README.txt file in $readmefilename.");
2609 }
2610 fclose($handle);
2611 } else {
2612 // Could not create the readme file. No cause for huge concern
2613 notify("Could not create the README.txt file in $readmefilename.");
b3847656 2614 }
2615 }
2616
1dda50ea 2617 if ($result && $oldversion < 2007101502) {
2618
5e900da1 2619 /// try to remove duplicate entries
2620
f7bd8c75 2621 $SQL = "SELECT userid, itemid, COUNT(*)
5e900da1 2622 FROM {$CFG->prefix}grade_grades
2623 GROUP BY userid, itemid
2624 HAVING COUNT( * ) >1";
2625 // duplicates found
5bbf18cd 2626
2627 if ($rs = get_recordset_sql($SQL)) {
2628 if ($rs && $rs->RecordCount() > 0) {
2629 while ($dup = rs_fetch_next_record($rs)) {
2630 if ($thisdups = get_records_sql("SELECT id FROM {$CFG->prefix}grade_grades
2631 WHERE itemid = $dup->itemid AND userid = $dup->userid
2632 ORDER BY timemodified DESC")) {
2633
2634 $processed = 0; // keep the first one
2635 foreach ($thisdups as $thisdup) {
2636 if ($processed) {
2637 // remove the duplicates
2638 delete_records('grade_grades', 'id', $thisdup->id);
2639 }
2640 $processed++;
5e900da1 2641 }
5e900da1 2642 }
2643 }
5bbf18cd 2644 rs_close($rs);
5e900da1 2645 }
2646 }
2647
1dda50ea 2648 /// Define key userid-itemid (unique) to be added to grade_grades
2649 $table = new XMLDBTable('grade_grades');
2650 $key = new XMLDBKey('userid-itemid');
2651 $key->setAttributes(XMLDB_KEY_UNIQUE, array('userid', 'itemid'));
2652
2653 /// Launch add key userid-itemid
2654 $result = $result && add_key($table, $key);
2655
2656 /// Main savepoint reached
2657 upgrade_main_savepoint($result, 2007101502);
56a1a882 2658 }
8600cada 2659
e4065e84 2660 if ($result && $oldversion < 2007101503) {
5cf5145a 2661///TODO: move this to the end after we stop using 19 version
a5b08715 2662 // Update courses that used weekscss to weeks
2663 $result = $result && set_field('course', 'format', 'weeks', 'format', 'weekscss');
2664 }
2665
e7a89237 2666 if ($result && $oldversion < 2007101505) {
2667
2668 /// Changing precision of field dst_time on table timezone to (6)
2669 $table = new XMLDBTable('timezone');
2670 $field = new XMLDBField('dst_time');
2671 $field->setAttributes(XMLDB_TYPE_CHAR, '6', null, XMLDB_NOTNULL, null, null, null, '00:00', 'dst_skipweeks');
2672
2673 /// Launch change of precision for field dst_time
2674 $result = $result && change_field_precision($table, $field);
2675
2676 /// Changing precision of field std_time on table timezone to (6)
2677 $table = new XMLDBTable('timezone');
2678 $field = new XMLDBField('std_time');
2679 $field->setAttributes(XMLDB_TYPE_CHAR, '6', null, XMLDB_NOTNULL, null, null, null, '00:00', 'std_skipweeks');
2680
2681 /// Launch change of precision for field std_time
2682 $result = $result && change_field_precision($table, $field);
2683
2684 /// Main savepoint reached
2685 upgrade_main_savepoint($result, 2007101505);
2686 }
2687
c2faa1d8 2688 if ($result && $oldversion < 2007101506) {
2689
2690 /// CONTEXT_PERSONAL was never implemented - removing
2691 $sql = "DELETE
2692 FROM {$CFG->prefix}context
2693 WHERE contextlevel=20";
2694
2695 execute_sql($sql);
2696
2697 /// Main savepoint reached
2698 upgrade_main_savepoint($result, 2007101506);
2699 }
2700
dd97c328 2701 if ($result && $oldversion < 2007101507) {
2702 $db->debug = false;
2703 require_once($CFG->dirroot.'/course/lib.php');
2704 notify('Started rebuilding of course cache...', 'notifysuccess');
2705 rebuild_course_cache(); // Rebuild course cache - new group related fields there
2706 notify('...finished rebuilding of course cache.', 'notifysuccess');
2707 $db->debug = true;
2708 /// Main savepoint reached
2709 upgrade_main_savepoint($result, 2007101507);
2710 }
2711
d4d71354 2712 if ($result && $oldversion < 2007101508) {
2713 $db->debug = false;
2714 notify('Updating country list according to recent official ISO listing...', 'notifysuccess');
2715 // re-assign users to valid countries
2716 set_field('user', 'country', 'CD', 'country', 'ZR'); // Zaire is now Congo Democratique
2717 set_field('user', 'country', 'TL', 'country', 'TP'); // Timor has changed
2718 set_field('user', 'country', 'FR', 'country', 'FX'); // France metropolitaine doesn't exist
2719 set_field('user', 'country', 'RS', 'country', 'KO'); // Kosovo is part of Serbia, "under the auspices of the United Nations, pursuant to UN Security Council Resolution 1244 of 10 June 1999."
2720 set_field('user', 'country', 'GB', 'country', 'WA'); // Wales is part of UK (ie Great Britain)
2721 set_field('user', 'country', 'RS', 'country', 'CS'); // Re-assign Serbia-Montenegro to Serbia. This is arbitrary, but there is no way to make an automatic decision on this.
2722 notify('...update complete. Remember to update the language pack to get the most recent country names defitions and codes. This is specialy important for sites with users from Congo (now CD), Timor (now TL), Kosovo (now RS), Wales (now GB), Serbia (RS) and Montenegro (ME). Users based in Montenegro (ME) will need to manually update their profile.', 'notifysuccess');
2723 $db->debug = true;
2724 upgrade_main_savepoint($result, 2007101508);
2725 }
2726
e13f9c10 2727 if ($result && $oldversion < 2007101508.01) {
46d5b312 2728// add forgotten table
2729 /// Define table scale_history to be created
2730 $table = new XMLDBTable('scale_history');
2731
2732 /// Adding fields to table scale_history
2733 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
2734 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
2735 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
2736 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
2737 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
2738 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
2739 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
2740 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
2741 $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
2742 $table->addFieldInfo('scale', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
2743 $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
2744
2745 /// Adding keys to table scale_history
2746 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
2747 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'scale', array('id'));
2748 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
2749 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id'));
2750
2751 /// Adding indexes to table scale_history
2752 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
2753
2754 if ($result and !table_exists($table)) {
2755 /// Launch create table for scale_history
2756 $result = $result && create_table($table);
2757 }
2758
2759 /// Main savepoint reached
e13f9c10 2760 upgrade_main_savepoint($result, 2007101508.01);
46d5b312 2761 }
2762
dd97c328 2763
e13f9c10 2764 if ($result && $oldversion < 2007101508.02) {
61460dd6 2765 // upgade totals, no big deal if it fails
2766 require_once($CFG->libdir.'/statslib.php');
2767 stats_upgrade_totals();
2768
2769 if (isset($CFG->loglifetime) and $CFG->loglifetime == 30) {
2770 set_config('loglifetime', 35); // we need more than 31 days for monthly stats!
2771 }
2772
2773 notify('Upgrading log table indexes, this may take a long time, please be patient.', 'notifysuccess');
2774
2775 /// Define index time-course-module-action (not unique) to be dropped form log
2776 $table = new XMLDBTable('log');
2777 $index = new XMLDBIndex('time-course-module-action');
2778 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('time', 'course', 'module', 'action'));
2779
2780 /// Launch drop index time-course-module-action
2781 if (index_exists($table, $index)) {
2782 $result = drop_index($table, $index) && $result;
2783 }
2784
2785 /// Define index userid (not unique) to be dropped form log
2786 $table = new XMLDBTable('log');
2787 $index = new XMLDBIndex('userid');
2788 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('userid'));
2789
2790 /// Launch drop index userid
2791 if (index_exists($table, $index)) {
2792 $result = drop_index($table, $index) && $result;
2793 }
2794
2795 /// Define index info (not unique) to be dropped form log
2796 $table = new XMLDBTable('log');
2797 $index = new XMLDBIndex('info');
2798 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('info'));
2799
2800 /// Launch drop index info
2801 if (index_exists($table, $index)) {
2802 $result = drop_index($table, $index) && $result;
2803 }
2804
2805 /// Define index time (not unique) to be added to log
2806 $table = new XMLDBTable('log');
2807 $index = new XMLDBIndex('time');
2808 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('time'));
2809
2810 /// Launch add index time
2811 if (!index_exists($table, $index)) {
2812 $result = add_index($table, $index) && $result;
2813 }
2814
2815 /// Define index action (not unique) to be added to log
2816 $table = new XMLDBTable('log');
2817 $index = new XMLDBIndex('action');
2818 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('action'));
2819
2820 /// Launch add index action
2821 if (!index_exists($table, $index)) {
2822 $result = add_index($table, $index) && $result;
2823 }
2824
2825 /// Main savepoint reached
e13f9c10 2826 upgrade_main_savepoint($result, 2007101508.02);
61460dd6 2827 }
2828
de65f28a 2829 if ($result && $oldversion < 2007101508.03) {
2830
2831 /// Define index course-userid (not unique) to be dropped form log
2832 $table = new XMLDBTable('log');
2833 $index = new XMLDBIndex('course-userid');
2834 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'userid'));
2835
2836 /// Launch drop index course-userid
2837 if (index_exists($table, $index)) {
2838 $result = $result && drop_index($table, $index);
2839 }
2840
2841 /// Define index userid-course (not unique) to be added to log
2842 $table = new XMLDBTable('log');
2843 $index = new XMLDBIndex('userid-course');
2844 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('userid', 'course'));
2845
2846 /// Launch add index userid-course
2847 if (!index_exists($table, $index)) {
2848 $result = $result && add_index($table, $index);
2849 }
2850
2851 /// Main savepoint reached
2852 upgrade_main_savepoint($result, 2007101508.03);
2853 }
2854
0e9e5927 2855 if ($result && $oldversion < 2007101508.04) {
2856 set_field('tag_instance', 'itemtype', 'post', 'itemtype', 'blog');
2857 upgrade_main_savepoint($result, 2007101508.04);
2858 }
de65f28a 2859
da4aa3e4 2860 if ($result && $oldversion < 2007101508.05) {
2861
2862 /// Define index cmid (not unique) to be added to log
2863 $table = new XMLDBTable('log');
2864 $index = new XMLDBIndex('cmid');
2865 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('cmid'));
2866
2867 /// Launch add index cmid
2868 if (!index_exists($table, $index)) {
2869 $result = $result && add_index($table, $index);
2870 }
2871
2872 /// Main savepoint reached
2873 upgrade_main_savepoint($result, 2007101508.05);
2874 }
2875
e06d74d5 2876 if ($result && $oldversion < 2007101508.06) {
2877
2878 /// Define index groupid-courseid-visible-userid (not unique) to be added to event
2879 $table = new XMLDBTable('event');
2880 $index = new XMLDBIndex('groupid-courseid-visible-userid');
2881 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('groupid', 'courseid', 'visible', 'userid'));
2882
2883 /// Launch add index groupid-courseid-visible-userid
2884 if (!index_exists($table, $index)) {
2885 $result = $result && add_index($table, $index);
2886 }
2887
2888 /// Main savepoint reached
2889 upgrade_main_savepoint($result, 2007101508.06);
2890 }
2891
156df4ed 2892 if ($result && $oldversion < 2007101508.07) {
2893
2894 /// Define table webdav_locks to be created
2895 $table = new XMLDBTable('webdav_locks');
2896
2897 /// Adding fields to table webdav_locks
2898 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
2899 $table->addFieldInfo('token', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
2900 $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
2901 $table->addFieldInfo('expiry', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
2902 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
2903 $table->addFieldInfo('recursive', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
2904 $table->addFieldInfo('exclusivelock', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
2905 $table->addFieldInfo('created', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
2906 $table->addFieldInfo('modified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
2907 $table->addFieldInfo('owner', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
2908
2909 /// Adding keys to table webdav_locks
2910 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
2911 $table->addKeyInfo('token', XMLDB_KEY_UNIQUE, array('token'));
2912
2913 /// Adding indexes to table webdav_locks
2914 $table->addIndexInfo('path', XMLDB_INDEX_NOTUNIQUE, array('path'));
2915 $table->addIndexInfo('expiry', XMLDB_INDEX_NOTUNIQUE, array('expiry'));
2916
2917 /// Launch create table for webdav_locks
2918 $result = $result && create_table($table);
2919
2920 /// Main savepoint reached
2921 upgrade_main_savepoint($result, 2007101508.07);
2922 }
2923
87486420 2924 if ($result && $oldversion < 2007101508.08) { // MDL-13676
2925
2926 /// Define field name to be added to role_names
2927 $table = new XMLDBTable('role_names');
2928 $field = new XMLDBField('name');
2929 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'text');
2930
2931 /// Launch add field name
2932 $result = $result && add_field($table, $field);
2933
2934 /// Copy data from old field to new field
2935 $result = $result && execute_sql('UPDATE '.$CFG->prefix.'role_names SET name = text');
2936
2937 /// Define field text to be dropped from role_names
2938 $table = new XMLDBTable('role_names');
2939 $field = new XMLDBField('text');
2940
2941 /// Launch drop field text
2942 $result = $result && drop_field($table, $field);
2943
2944 /// Main savepoint reached
2945 upgrade_main_savepoint($result, 2007101508.08);
2946 }
156df4ed 2947
91f9a62c 2948 if ($result && $oldversion < 2007101509) {
2949 // force full regrading
2950 set_field('grade_items', 'needsupdate', 1, 'needsupdate', 0);
2951 }
da4aa3e4 2952
a1f27717 2953 if ($result && $oldversion < 2008030700) {
2954
2955 /// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters
2956 $table = new XMLDBTable('grade_letters');
2957 $index = new XMLDBIndex('contextid-lowerboundary');
2958 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
2959
2960 /// Launch drop index contextid-lowerboundary
2961 $result = $result && drop_index($table, $index);
2962
a1f27717 2963 /// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
2964 $table = new XMLDBTable('grade_letters');
2965 $index = new XMLDBIndex('contextid-lowerboundary-letter');
2966 $index->setAttributes(XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
2967
2968 /// Launch add index contextid-lowerboundary-letter
2969 $result = $result && add_index($table, $index);
2970
2971 /// Main savepoint reached
0f77b186 2972 upgrade_main_savepoint($result, 2008030700);
2973 }
a1f27717 2974
ac9b0805 2975 return $result;
4e423cbf 2976}
271e6dec 2977
2978
4e423cbf 2979?>