Deleting the Db migrate to UTF-8 button. It isn't there anymore.
[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 }
34 }
35
e27a9437 36 if ($oldversion < 2006100601) { /// Disable the exercise module because it's unmaintained
37 if ($module = get_record('modules', 'name', 'exercise')) {
38 if ($module->visible) {
39 // Hide/disable the module entry
271e6dec 40 set_field('modules', 'visible', '0', 'id', $module->id);
e27a9437 41 // Save existing visible state for all activities
42 set_field('course_modules', 'visibleold', '1', 'visible' ,'1', 'module', $module->id);
43 set_field('course_modules', 'visibleold', '0', 'visible' ,'0', 'module', $module->id);
44 // Hide all activities
45 set_field('course_modules', 'visible', '0', 'module', $module->id);
271e6dec 46
e27a9437 47 require_once($CFG->dirroot.'/course/lib.php');
48 rebuild_course_cache(); // Rebuld cache for all modules because they might have changed
49 }
50 }
51 }
52
171d8232 53 if ($oldversion < 2006101001) { /// Disable the LAMS module by default (if it is installed)
54 if (count_records('modules', 'name', 'lams') && !count_records('lams')) {
49e67510 55 set_field('modules', 'visible', 0, 'name', 'lams'); // Disable it by default
56 }
57 }
271e6dec 58
74807b43 59 if ($result && $oldversion < 2006102600) {
60
61 /// Define fields to be added to user_info_field
62 $table = new XMLDBTable('user_info_field');
63 $field = new XMLDBField('description');
64 $field->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null, 'categoryid');
65 $field1 = new XMLDBField('param1');
66 $field1->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null, 'defaultdata');
67 $field2 = new XMLDBField('param2');
68 $field2->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null, 'param1');
69 $field3 = new XMLDBField('param3');
70 $field3->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null, 'param2');
71 $field4 = new XMLDBField('param4');
72 $field4->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null, 'param3');
73 $field5 = new XMLDBField('param5');
74 $field5->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null, 'param4');
75
76 /// Launch add fields
77 $result = $result && add_field($table, $field);
78 $result = $result && add_field($table, $field1);
79 $result = $result && add_field($table, $field2);
80 $result = $result && add_field($table, $field3);
81 $result = $result && add_field($table, $field4);
82 $result = $result && add_field($table, $field5);
83 }
271e6dec 84
7d0e5a95 85 if ($result && $oldversion < 2006112000) {
86
87 /// Define field attachment to be added to post
88 $table = new XMLDBTable('post');
89 $field = new XMLDBField('attachment');
90 $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null, 'format');
91
92 /// Launch add field attachment
93 $result = $result && add_field($table, $field);
94 }
271e6dec 95
54dc87b8 96 if ($result && $oldversion < 2006112200) {
97
98 /// Define field imagealt to be added to user
99 $table = new XMLDBTable('user');
100 $field = new XMLDBField('imagealt');
101 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'trustbitmask');
102
103 /// Launch add field imagealt
104 $result = $result && add_field($table, $field);
271e6dec 105
54dc87b8 106 $table = new XMLDBTable('user');
107 $field = new XMLDBField('screenreader');
108 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', 'imagealt');
109
110 /// Launch add field screenreader
111 $result = $result && add_field($table, $field);
112 }
49e67510 113
7b678e0a 114 if ($oldversion < 2006120300) { /// Delete guest course section settings
115 // following code can be executed repeatedly, such as when upgrading from 1.7.x - it is ok
116 if ($guest = get_record('user', 'username', 'guest')) {
77b09448 117 execute_sql("DELETE FROM {$CFG->prefix}course_display where userid=$guest->id", true);
7b678e0a 118 }
119 }
120
9c0f063b 121 if ($oldversion < 2006120400) { /// Remove secureforms config setting
77b09448 122 execute_sql("DELETE FROM {$CFG->prefix}config where name='secureforms'", true);
9c0f063b 123 }
271e6dec 124
8c6c185a 125 if (!empty($CFG->rolesactive) && $oldversion < 2006120700) { // add moodle/user:viewdetails to all roles!
126 // note: use of assign_capability() is discouraged in upgrade script!
22ae509e 127 if ($roles = get_records('role')) {
128 $context = get_context_instance(CONTEXT_SYSTEM);
129 foreach ($roles as $roleid=>$role) {
130 assign_capability('moodle/user:viewdetails', CAP_ALLOW, $roleid, $context->id);
131 }
132 }
133 }
9c0f063b 134
5cd129c7 135 // Move the auth plugin settings into the config_plugin table
136 if ($oldversion < 2007010300) {
177df3c6 137 if ($CFG->auth == 'email') {
138 set_config('registerauth', 'email');
139 } else {
140 set_config('registerauth', '');
141 }
5cd129c7 142 $authplugins = get_list_of_plugins('auth');
143 foreach ($CFG as $k => $v) {
922c5b36 144 if (strpos($k, 'ldap_') === 0) {
145 //upgrade nonstandard ldap settings
146 $setting = substr($k, 5);
147 if (set_config($setting, $v, "auth/ldap")) {
148 delete_records('config', 'name', $k);
149 unset($CFG->{$k});
150 }
151 continue;
152 }
5cd129c7 153 if (strpos($k, 'auth_') !== 0) {
154 continue;
155 }
156 $authsetting = substr($k, 5);
157 foreach ($authplugins as $auth) {
158 if (strpos($authsetting, $auth) !== 0) {
159 continue;
160 }
161 $setting = substr($authsetting, strlen($auth));
162 if (set_config($setting, $v, "auth/$auth")) {
163 delete_records('config', 'name', $k);
164 unset($CFG->{$k});
165 }
166 break; // don't check the rest of the auth plugin names
167 }
168 }
169 }
170
171 if ($oldversion < 2007010301) {
172 //
173 // Core MNET tables
174 //
175 $table = new XMLDBTable('mnet_host');
176 $table->comment = 'Information about the local and remote hosts for RPC';
177 // fields
178 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
179 XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
180 $f->comment = 'Unique Host ID';
181 $f = $table->addFieldInfo('deleted', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
182 XMLDB_NOTNULL, null, null, null, 0);
183 $f = $table->addFieldInfo('wwwroot', XMLDB_TYPE_CHAR, '255', null,
a54d16ef 184 XMLDB_NOTNULL, null, null, null, null);
5cd129c7 185 $f = $table->addFieldInfo('ip_address', XMLDB_TYPE_CHAR, '39', null,
a54d16ef 186 XMLDB_NOTNULL, null, null, null, null);
5cd129c7 187 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '80', null,
a54d16ef 188 XMLDB_NOTNULL, null, null, null, null);
357f08fa 189 $f = $table->addFieldInfo('public_key', XMLDB_TYPE_TEXT, 'medium', null,
5cd129c7 190 XMLDB_NOTNULL, null, null, null, null);
191 $f = $table->addFieldInfo('public_key_expires', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
192 XMLDB_NOTNULL, null, null, null, 0);
193 $f = $table->addFieldInfo('transport', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED,
194 XMLDB_NOTNULL, null, null, null, 0);
195 $f = $table->addFieldInfo('portno', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED,
196 XMLDB_NOTNULL, null, null, null, 0);
197 $f = $table->addFieldInfo('last_connect_time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
198 XMLDB_NOTNULL, null, null, null, 0);
199 $f = $table->addFieldInfo('last_log_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
200 XMLDB_NOTNULL, null, null, null, 0);
271e6dec 201 // PK and indexes
5cd129c7 202 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
203 // Create the table
204 $result = $result && create_table($table);
205
206 $table = new XMLDBTable('mnet_host2service');
207 $table->comment = 'Information about the services for a given host';
208 // fields
209 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
210 XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
211 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
212 XMLDB_NOTNULL, NULL, null, null, 0);
213 $f = $table->addFieldInfo('serviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
214 XMLDB_NOTNULL, NULL, null, null, 0);
215 $f = $table->addFieldInfo('publish', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
216 XMLDB_NOTNULL, NULL, null, null, 0);
217 $f = $table->addFieldInfo('subscribe', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
218 XMLDB_NOTNULL, NULL, null, null, 0);
219 // PK and indexes
220 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
221 $table->addIndexInfo('hostid_serviceid', XMLDB_INDEX_UNIQUE, array('hostid', 'serviceid'));
222 // Create the table
223 $result = $result && create_table($table);
224
225 $table = new XMLDBTable('mnet_log');
226 $table->comment = 'Store session data from users migrating to other sites';
227 // fields
228 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
229 XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
230 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
231 XMLDB_NOTNULL, NULL, null, null, 0);
232 $f = $table->addFieldInfo('remoteid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
233 XMLDB_NOTNULL, NULL, null, null, 0);
234 $f = $table->addFieldInfo('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
235 XMLDB_NOTNULL, NULL, null, null, 0);
236 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
237 XMLDB_NOTNULL, NULL, null, null, 0);
238 $f = $table->addFieldInfo('ip', XMLDB_TYPE_CHAR, '15', null,
239 XMLDB_NOTNULL, NULL, null, null, null);
240 $f = $table->addFieldInfo('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
241 XMLDB_NOTNULL, NULL, null, null, 0);
242 $f = $table->addFieldInfo('coursename', XMLDB_TYPE_CHAR, '40', null,
243 XMLDB_NOTNULL, NULL, null, null, null);
244 $f = $table->addFieldInfo('module', XMLDB_TYPE_CHAR, '20', null,
245 XMLDB_NOTNULL, NULL, null, null, null);
246 $f = $table->addFieldInfo('cmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
247 XMLDB_NOTNULL, NULL, null, null, 0);
248 $f = $table->addFieldInfo('action', XMLDB_TYPE_CHAR, '40', null,
249 XMLDB_NOTNULL, NULL, null, null, null);
250 $f = $table->addFieldInfo('url', XMLDB_TYPE_CHAR, '100', null,
251 XMLDB_NOTNULL, NULL, null, null, null);
252 $f = $table->addFieldInfo('info', XMLDB_TYPE_CHAR, '255', null,
253 XMLDB_NOTNULL, NULL, null, null, null);
254 // PK and indexes
255 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
256 $table->addIndexInfo('host_user_course', XMLDB_INDEX_NOTUNIQUE, array('hostid', 'userid', 'course'));
257 // Create the table
258 $result = $result && create_table($table);
259
260
261 $table = new XMLDBTable('mnet_rpc');
262 $table->comment = 'Functions or methods that we may publish or subscribe to';
263 // fields
264 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
265 XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
266 $f = $table->addFieldInfo('function_name', XMLDB_TYPE_CHAR, '40', null,
267 XMLDB_NOTNULL, NULL, null, null, null);
268 $f = $table->addFieldInfo('xmlrpc_path', XMLDB_TYPE_CHAR, '80', null,
269 XMLDB_NOTNULL, NULL, null, null, null);
270 $f = $table->addFieldInfo('parent_type', XMLDB_TYPE_CHAR, '6', null,
271 XMLDB_NOTNULL, NULL, null, null, null);
272 $f = $table->addFieldInfo('parent', XMLDB_TYPE_CHAR, '20', null,
273 XMLDB_NOTNULL, NULL, null, null, null);
274 $f = $table->addFieldInfo('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
275 XMLDB_NOTNULL, NULL, null, null, 0);
276 $f = $table->addFieldInfo('help', XMLDB_TYPE_TEXT, 'medium', null,
277 XMLDB_NOTNULL, NULL, null, null, null);
278 $f = $table->addFieldInfo('profile', XMLDB_TYPE_TEXT, 'medium', null,
279 XMLDB_NOTNULL, NULL, null, null, null);
280 // PK and indexes
281 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
282 $table->addIndexInfo('enabled_xpath', XMLDB_INDEX_NOTUNIQUE, array('enabled', 'xmlrpc_path'));
283 // Create the table
284 $result = $result && create_table($table);
285
286 $table = new XMLDBTable('mnet_service');
287 $table->comment = 'A service is a group of functions';
288 // fields
289 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
290 XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
291 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '40', null,
292 XMLDB_NOTNULL, NULL, null, null, null);
293 $f = $table->addFieldInfo('description', XMLDB_TYPE_CHAR, '40', null,
294 XMLDB_NOTNULL, NULL, null, null, null);
295 $f = $table->addFieldInfo('apiversion', XMLDB_TYPE_CHAR, '10', null,
296 XMLDB_NOTNULL, NULL, null, null, null);
297 $f = $table->addFieldInfo('offer', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
298 XMLDB_NOTNULL, NULL, null, null, 0);
299 // PK and indexes
300 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
301 // Create the table
302 $result = $result && create_table($table);
303
304 $table = new XMLDBTable('mnet_service2rpc');
357f08fa 305 $table->comment = 'Group functions or methods under a service';
5cd129c7 306 // fields
307 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
308 XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
309 $f = $table->addFieldInfo('serviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
310 XMLDB_NOTNULL, NULL, null, null, 0);
311 $f = $table->addFieldInfo('rpcid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
312 XMLDB_NOTNULL, NULL, null, null, 0);
313 // PK and indexes
314 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
315 $table->addIndexInfo('unique', XMLDB_INDEX_UNIQUE, array('rpcid', 'serviceid'));
316 // Create the table
317 $result = $result && create_table($table);
318
319 //
271e6dec 320 // Prime MNET configuration entries -- will be needed later by auth/mnet
5cd129c7 321 //
322 include_once $CFG->dirroot . '/mnet/lib.php';
323 $env = new mnet_environment();
324 $env->init();
325 unset($env);
326
271e6dec 327 // add mnethostid to user-
5cd129c7 328 $table = new XMLDBTable('user');
329 $field = new XMLDBField('mnethostid');
330 $field->setType(XMLDB_TYPE_INTEGER);
331 $field->setLength(10);
332 $field->setNotNull(true);
333 $field->setSequence(null);
334 $field->setEnum(null);
335 $field->setDefault('0');
336 $field->setPrevious("deleted");
337 $field->setNext("username");
338 $result = $result && add_field($table, $field);
339
340 // The default mnethostid is zero... we need to update this for all
341 // users of the local IdP service.
271e6dec 342 set_field('user',
343 'mnethostid', $CFG->mnet_localhost_id,
5cd129c7 344 'mnethostid', '0');
345
346
347 $index = new XMLDBIndex('username');
348 $index->setUnique(true);
349 $index->setFields(array('username'));
350 drop_index($table, $index);
351 $index->setFields(array('mnethostid', 'username'));
b7791fab 352 if (!add_index($table, $index)) {
68879a58 353 notify(get_string('duplicate_usernames', 'mnet', 'http://docs.moodle.org/en/DuplicateUsernames'));
354 }
5cd129c7 355
271e6dec 356 unset($table, $field, $index);
5cd129c7 357
358 /**
359 ** auth/mnet tables
360 **/
361 $table = new XMLDBTable('mnet_session');
362 $table->comment='Store session data from users migrating to other sites';
363 // fields
364 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
365 XMLDB_NOTNULL,XMLDB_SEQUENCE, null, null, null);
366 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
367 XMLDB_NOTNULL, NULL, null, null, 0);
368 $f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR, '100', null,
369 XMLDB_NOTNULL, NULL, null, null, null);
370 $f = $table->addFieldInfo('token', XMLDB_TYPE_CHAR, '40', null,
371 XMLDB_NOTNULL, NULL, null, null, null);
372 $f = $table->addFieldInfo('mnethostid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
373 XMLDB_NOTNULL, NULL, null, null, 0);
374 $f = $table->addFieldInfo('useragent', XMLDB_TYPE_CHAR, '40', null,
375 XMLDB_NOTNULL, NULL, null, null, null);
376 $f = $table->addFieldInfo('confirm_timeout', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
377 XMLDB_NOTNULL, NULL, null, null, 0);
378 $f = $table->addFieldInfo('session_id', XMLDB_TYPE_CHAR, '40', null,
379 XMLDB_NOTNULL, NULL, null, null, null);
380 $f = $table->addFieldInfo('expires', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
381 XMLDB_NOTNULL, NULL, null, null, 0);
382 // PK and indexes
383 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
357f08fa 384 $table->addIndexInfo('token', XMLDB_INDEX_UNIQUE, array('token'));
5cd129c7 385 // Create the table
386 $result = $result && create_table($table);
387
388
389 $table = new XMLDBTable('mnet_sso_access_control');
390 $table->comment = 'Users by host permitted (or not) to login from a remote provider';
391 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
392 XMLDB_NOTNULL,XMLDB_SEQUENCE, null, null, null);
393 $f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR, '100', null,
394 XMLDB_NOTNULL, NULL, null, null, null);
395 $f = $table->addFieldInfo('mnet_host_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
396 XMLDB_NOTNULL, NULL, null, null, 0);
397 $f = $table->addFieldInfo('access', XMLDB_TYPE_CHAR, '20', null,
398 XMLDB_NOTNULL, NULL, null, null, 'allow');
399 // PK and indexes
400 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
401 $table->addIndexInfo('mnethostid_username', XMLDB_INDEX_UNIQUE, array('mnet_host_id', 'username'));
402 // Create the table
403 $result = $result && create_table($table);
404
8a45fcdf 405 if (empty($USER->mnet_host_id)) {
cac88d40 406 $USER->mnet_host_id = $CFG->mnet_localhost_id; // Something for the current user to prevent warnings
8a45fcdf 407 }
408
5cd129c7 409 /**
410 ** enrol/mnet tables
411 **/
412 $table = new XMLDBTable('mnet_enrol_course');
413 $table->comment = 'Information about courses on remote hosts';
414 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
415 XMLDB_NOTNULL,XMLDB_SEQUENCE, null, null, null);
416 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
417 XMLDB_NOTNULL, NULL, null, null, 0);
418 $f = $table->addFieldInfo('remoteid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
419 XMLDB_NOTNULL, NULL, null, null, 0);
420 $f = $table->addFieldInfo('cat_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
421 XMLDB_NOTNULL, NULL, null, null, 0);
422 $f = $table->addFieldInfo('cat_name', XMLDB_TYPE_CHAR, '255', null,
423 XMLDB_NOTNULL, NULL, null, null, null);
424 $f = $table->addFieldInfo('cat_description', XMLDB_TYPE_TEXT, 'medium', null,
425 XMLDB_NOTNULL, NULL, null, null, null);
426 $f = $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED,
427 XMLDB_NOTNULL, NULL, null, null, 0);
428 $f = $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '254', null,
a54d16ef 429 XMLDB_NOTNULL, NULL, null, null, null);
5cd129c7 430 $f = $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '15', null,
431 XMLDB_NOTNULL, NULL, null, null, null);
432 $f = $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '100', null,
433 XMLDB_NOTNULL, NULL, null, null, null);
434 $f = $table->addFieldInfo('summary', XMLDB_TYPE_TEXT, 'medium', null,
435 XMLDB_NOTNULL, NULL, null, null, null);
436 $f = $table->addFieldInfo('startdate', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
437 XMLDB_NOTNULL, NULL, null, null, 0);
438 $f = $table->addFieldInfo('cost', XMLDB_TYPE_CHAR, '10', null,
439 XMLDB_NOTNULL, NULL, null, null, null);
440 $f = $table->addFieldInfo('currency', XMLDB_TYPE_CHAR, '3', null,
441 XMLDB_NOTNULL, NULL, null, null, null);
442 $f = $table->addFieldInfo('defaultroleid', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED,
443 XMLDB_NOTNULL, NULL, null, null, 0);
444 $f = $table->addFieldInfo('defaultrolename', XMLDB_TYPE_CHAR, '255', null,
445 XMLDB_NOTNULL, NULL, null, null, null);
446 // PK and indexes
447 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
448 $table->addIndexInfo('hostid_remoteid', XMLDB_INDEX_UNIQUE, array('hostid', 'remoteid'));
449 // Create the table
450 $result = $result && create_table($table);
451
452
453 $table = new XMLDBTable('mnet_enrol_assignments');
454
455 $table->comment = 'Information about enrolments on courses on remote hosts';
456 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
457 XMLDB_NOTNULL,XMLDB_SEQUENCE, null, null, null);
458 $f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
459 XMLDB_NOTNULL, NULL, null, null, 0);
460 $f = $table->addFieldInfo('hostid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
271e6dec 461 XMLDB_NOTNULL, NULL, null, null, 0);
5cd129c7 462 $f = $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
463 XMLDB_NOTNULL, NULL, null, null, 0);
464 $f = $table->addFieldInfo('rolename', XMLDB_TYPE_CHAR, '255', null,
465 XMLDB_NOTNULL, NULL, null, null, null);
466 $f = $table->addFieldInfo('enroltime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
467 XMLDB_NOTNULL, NULL, null, null, 0);
468 $f = $table->addFieldInfo('enroltype', XMLDB_TYPE_CHAR, '20', null,
469 XMLDB_NOTNULL, NULL, null, null, null);
470
471 // PK and indexes
472 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
473 $table->addIndexInfo('hostid_courseid', XMLDB_INDEX_NOTUNIQUE, array('hostid', 'courseid'));
357f08fa 474 $table->addIndexInfo('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
5cd129c7 475 // Create the table
476 $result = $result && create_table($table);
477
478 }
479
dedda83d 480 if ($result && $oldversion < 2007010404) {
481
482 /// Define field shortname to be added to user_info_field
483 $table = new XMLDBTable('user_info_field');
484 $field = new XMLDBField('shortname');
485 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, 'shortname', 'id');
486
487 /// Launch add field shortname
488 $result = $result && add_field($table, $field);
489
490 /// Changing type of field name on table user_info_field to text
491 $table = new XMLDBTable('user_info_field');
492 $field = new XMLDBField('name');
493 $field->setAttributes(XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null, null, null, 'shortname');
494
495 /// Launch change of type for field name
496 $result = $result && change_field_type($table, $field);
497
498 /// For existing fields use 'name' as the 'shortname' entry
4218c9b2 499 if ($fields = get_records_select('user_info_field', '', '', 'id, name')) {
dedda83d 500 foreach ($fields as $field) {
501 $field->shortname = clean_param($field->name, PARAM_ALPHANUM);
502 $result && update_record('user_info_field', $field);
503 }
504 }
505 }
506
0db6adc9 507 if ($result && $oldversion < 2007011200) {
508
509 /// Define table context_rel to be created
510 $table = new XMLDBTable('context_rel');
511
512 /// Adding fields to table context_rel
abd30252 513 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
514 $table->addFieldInfo('c1', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
515 $table->addFieldInfo('c2', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
0db6adc9 516
517 /// Adding keys to table context_rel
518 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
519 $table->addKeyInfo('c1', XMLDB_KEY_FOREIGN, array('c1'), 'context', array('id'));
520 $table->addKeyInfo('c2', XMLDB_KEY_FOREIGN, array('c2'), 'context', array('id'));
521 $table->addKeyInfo('c1c2', XMLDB_KEY_UNIQUE, array('c1', 'c2'));
522
523 /// Launch create table for context_rel
524 $result = $result && create_table($table);
271e6dec 525
0db6adc9 526 /// code here to fill the context_rel table
527 /// use get record set to iterate slower
5f382224 528 /// /deprecated and gone / build_context_rel();
0db6adc9 529 }
bb931a61 530
531 if ($result && $oldversion < 2007011501) {
271e6dec 532 if (!empty($CFG->enablerecordcache) && empty($CFG->rcache) &&
bb931a61 533 // Note: won't force-load these settings into CFG
534 // we don't need or want cache during the upgrade itself
535 empty($CFG->cachetype) && empty($CFG->intcachemax)) {
536 set_config('cachetype', 'internal');
537 set_config('rcache', true);
538 set_config('intcachemax', $CFG->enablerecordcache);
539 unset_config('enablerecordcache');
540 unset($CFG->enablerecordcache);
541 }
542 }
543
9fc57f4c 544 if ($result && $oldversion < 2007012100) {
545 /// Some old PG servers have user->firstname & user->lastname with 30cc. They must be 100cc.
546 /// Fixing that conditionally. MDL-7110
547 if ($CFG->dbfamily == 'postgres') {
548 /// Get Metadata from user table
549 $cols = array_change_key_case($db->MetaColumns($CFG->prefix . 'user'), CASE_LOWER);
550
551 /// Process user->firstname if needed
552 if ($col = $cols['firstname']) {
553 if ($col->max_length < 100) {
554 /// Changing precision of field firstname on table user to (100)
555 $table = new XMLDBTable('user');
556 $field = new XMLDBField('firstname');
557 $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null, 'idnumber');
558
559 /// Launch change of precision for field firstname
560 $result = $result && change_field_precision($table, $field);
561 }
562 }
563
564 /// Process user->lastname if needed
565 if ($col = $cols['lastname']) {
566 if ($col->max_length < 100) {
567 /// Changing precision of field lastname on table user to (100)
568 $table = new XMLDBTable('user');
569 $field = new XMLDBField('lastname');
570 $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null, 'firstname');
571
572 /// Launch change of precision for field lastname
573 $result = $result && change_field_precision($table, $field);
574 }
575 }
576 }
577 }
578
deb12ef4 579 if ($result && $oldversion < 2007012101) {
580
581 /// Changing precision of field lang on table course to (30)
582 $table = new XMLDBTable('course');
583 $field = new XMLDBField('lang');
584 $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null, 'groupmodeforce');
585
586 /// Launch change of precision for field course->lang
587 $result = $result && change_field_precision($table, $field);
588
589 /// Changing precision of field lang on table user to (30)
590 $table = new XMLDBTable('user');
591 $field = new XMLDBField('lang');
592 $field->setAttributes(XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'en', 'country');
593
594 /// Launch change of precision for field user->lang
595 $result = $result && change_field_precision($table, $field);
596 }
597
cdf22329 598 if ($result && $oldversion < 2007012400) {
599
600 /// Rename field access on table mnet_sso_access_control to accessctrl
601 $table = new XMLDBTable('mnet_sso_access_control');
602 $field = new XMLDBField('access');
fdaacd8b 603 $field->setAttributes(XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, 'allow', 'mnet_host_id');
cdf22329 604
605 /// Launch rename field accessctrl
606 $result = $result && rename_field($table, $field, 'accessctrl');
607 }
608
e8e0bb2d 609 if ($result && $oldversion < 2007012500) {
77b09448 610 execute_sql("DELETE FROM {$CFG->prefix}user WHERE username='changeme'", true);
e8e0bb2d 611 }
612
8dadea88 613 if ($result && $oldversion < 2007020400) {
614 /// Only for MySQL and PG, declare the user->ajax field as not null. MDL-8421.
615 if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') {
616 /// Changing nullability of field ajax on table user to not null
617 $table = new XMLDBTable('user');
618 $field = new XMLDBField('ajax');
619 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'htmleditor');
620
621 /// Launch change of nullability for field ajax
622 $result = $result && change_field_notnull($table, $field);
623 }
624 }
625
ee266f33 626 if (!empty($CFG->rolesactive) && $result && $oldversion < 2007021401) {
efe12f6c 627 /// create default logged in user role if not present - upgrade rom 1.7.x
c7888a90 628 if (empty($CFG->defaultuserroleid) or empty($CFG->guestroleid) or $CFG->defaultuserroleid == $CFG->guestroleid) {
efe12f6c 629 if (!get_records('role', 'shortname', 'user')) {
630 $userroleid = create_role(addslashes(get_string('authenticateduser')), 'user',
631 addslashes(get_string('authenticateduserdescription')), 'moodle/legacy:user');
632 if ($userroleid) {
633 reset_role_capabilities($userroleid);
634 set_config('defaultuserroleid', $userroleid);
635 }
636 }
637 }
638 }
639
77d08333 640 if ($result && $oldversion < 2007021501) {
641 /// delete removed setting from config
642 unset_config('tabselectedtofront');
643 }
644
b318ecfd 645
646 if ($result && $oldversion < 2007032200) {
647
648 /// Define table role_sortorder to be created
649 $table = new XMLDBTable('role_sortorder');
650
651 /// Adding fields to table role_sortorder
abd30252 652 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
b318ecfd 653 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
654 $table->addFieldInfo('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
655 $table->addFieldInfo('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
656 $table->addFieldInfo('sortoder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
657
658 /// Adding keys to table role_sortorder
659 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
660 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
661 $table->addKeyInfo('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id'));
662 $table->addKeyInfo('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
663
664 /// Adding indexes to table role_sortorder
665 $table->addIndexInfo('userid-roleid-contextid', XMLDB_INDEX_UNIQUE, array('userid', 'roleid', 'contextid'));
666
667 /// Launch create table for role_sortorder
668 $result = $result && create_table($table);
669 }
670
07076b70 671
672 /// code to change lenghen tag field to 255, MDL-9095
673 if ($result && $oldversion < 2007040400) {
674
675 /// Define index text (not unique) to be dropped form tags
676 $table = new XMLDBTable('tags');
677 $index = new XMLDBIndex('text');
678 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('text'));
679
680 /// Launch drop index text
681 $result = $result && drop_index($table, $index);
271e6dec 682
07076b70 683 $field = new XMLDBField('text');
684 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'userid');
685
686 /// Launch change of type for field text
687 $result = $result && change_field_type($table, $field);
271e6dec 688
07076b70 689 $index = new XMLDBIndex('text');
690 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('text'));
691
692 /// Launch add index text
271e6dec 693 $result = $result && add_index($table, $index);
07076b70 694 }
271e6dec 695
177d4abf 696 if ($result && $oldversion < 2007041100) {
697
698 /// Define field idnumber to be added to course_modules
699 $table = new XMLDBTable('course_modules');
700 $field = new XMLDBField('idnumber');
701 $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null, 'section');
271e6dec 702
177d4abf 703 /// Launch add field idnumber
704 $result = $result && add_field($table, $field);
271e6dec 705
177d4abf 706 /// Define index idnumber (unique) to be added to course_modules
707 $table = new XMLDBTable('course_modules');
708 $index = new XMLDBIndex('idnumber');
709 $index->setAttributes(XMLDB_INDEX_UNIQUE, array('idnumber'));
710
711 /// Launch add index idnumber
712 $result = $result && add_index($table, $index);
713
714 }
715
334415e9 716 /* Changes to the custom profile menu type - store values rather than indices.
717 We could do all this with one tricky SQL statement but it's a one-off so no
718 harm in using PHP loops */
719 if ($result && $oldversion < 2007041600) {
271e6dec 720
334415e9 721 /// Get the menu fields
722 if ($fields = get_records('user_info_field', 'datatype', 'menu')) {
723 foreach ($fields as $field) {
724
725 /// Get user data for the menu field
726 if ($data = get_records('user_info_data', 'fieldid', $field->id)) {
727
728 /// Get the menu options
729 $options = explode("\n", $this->field->param1);
730 foreach ($data as $d) {
731 $key = array_search($d->data, $options);
271e6dec 732
334415e9 733 /// If the data is an integer and is not one of the options,
734 /// set the respective option value
735 if (is_int($d->data) and (($key === NULL) or ($key === false)) and isset($options[$d->data])) {
736 $d->data = $options[$d->data];
737 $result = $result && update_record('user_info_data', $d);
738 }
739 }
740 }
741 }
742 }
271e6dec 743
334415e9 744 }
271e6dec 745
5cb564aa 746 /// adding new gradebook tables
ec36253d 747 if ($result && $oldversion < 2007041800) {
748
749 /// Define table events_handlers to be created
750 $table = new XMLDBTable('events_handlers');
751
752 /// Adding fields to table events_handlers
197ba19c 753 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
5cb564aa 754 $table->addFieldInfo('eventname', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null);
755 $table->addFieldInfo('handlermodule', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null);
ec36253d 756 $table->addFieldInfo('handlerfile', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
757 $table->addFieldInfo('handlerfunction', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
758
759 /// Adding keys to table events_handlers
760 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
761
762 /// Adding indexes to table events_handlers
5cb564aa 763 $table->addIndexInfo('eventname-handlermodule', XMLDB_INDEX_UNIQUE, array('eventname', 'handlermodule'));
ec36253d 764
765 /// Launch create table for events_handlers
766 $result = $result && create_table($table);
271e6dec 767
ec36253d 768 /// Define table events_queue to be created
769 $table = new XMLDBTable('events_queue');
770
771 /// Adding fields to table events_queue
197ba19c 772 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
ec36253d 773 $table->addFieldInfo('eventdata', XMLDB_TYPE_TEXT, 'big', null, XMLDB_NOTNULL, null, null, null, null);
774 $table->addFieldInfo('schedule', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
775 $table->addFieldInfo('stackdump', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
776 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
777 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
778
779 /// Adding keys to table events_queue
780 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
781 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
334415e9 782
ec36253d 783 /// Launch create table for events_queue
784 $result = $result && create_table($table);
271e6dec 785
ec36253d 786 /// Define table events_queue_handlers to be created
787 $table = new XMLDBTable('events_queue_handlers');
788
789 /// Adding fields to table events_queue_handlers
197ba19c 790 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
ec36253d 791 $table->addFieldInfo('queuedeventid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
792 $table->addFieldInfo('handlerid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
793 $table->addFieldInfo('status', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
794 $table->addFieldInfo('errormessage', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
795 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
796
797 /// Adding keys to table events_queue_handlers
798 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
799 $table->addKeyInfo('queuedeventid', XMLDB_KEY_FOREIGN, array('queuedeventid'), 'events_queue', array('id'));
800 $table->addKeyInfo('handlerid', XMLDB_KEY_FOREIGN, array('handlerid'), 'events_handlers', array('id'));
801
802 /// Launch create table for events_queue_handlers
803 $result = $result && create_table($table);
804
805 }
9d2cddf1 806
896f1e03 807 if ($result && $oldversion < 2007043001) {
808
896f1e03 809 /// Define field schedule to be added to events_handlers
810 $table = new XMLDBTable('events_handlers');
811 $field = new XMLDBField('schedule');
812 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'handlerfunction');
813
814 /// Launch add field schedule
815 $result = $result && add_field($table, $field);
271e6dec 816
896f1e03 817 /// Define field status to be added to events_handlers
818 $table = new XMLDBTable('events_handlers');
819 $field = new XMLDBField('status');
820 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'schedule');
821
822 /// Launch add field status
823 $result = $result && add_field($table, $field);
824 }
825
ec75a182 826 if ($result && $oldversion < 2007050201) {
827
828 /// Define field theme to be added to course_categories
829 $table = new XMLDBTable('course_categories');
830 $field = new XMLDBField('theme');
831 $field->setAttributes(XMLDB_TYPE_CHAR, '50', null, null, null, null, null, null, 'path');
832
833 /// Launch add field theme
834 $result = $result && add_field($table, $field);
835 }
9aaa214e 836
837 if ($result && $oldversion < 2007051100) {
838
839 /// Define field forceunique to be added to user_info_field
840 $table = new XMLDBTable('user_info_field');
841 $field = new XMLDBField('forceunique');
842 $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'visible');
843
844 /// Launch add field forceunique
845 $result = $result && add_field($table, $field);
846
847 /// Define field signup to be added to user_info_field
848 $table = new XMLDBTable('user_info_field');
849 $field = new XMLDBField('signup');
850 $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'forceunique');
851
852 /// Launch add field signup
853 $result = $result && add_field($table, $field);
854 }
93759def 855
8c6c185a 856 if (!empty($CFG->rolesactive) && $result && $oldversion < 2007051801) {
857 // Get the role id of the "Auth. User" role and check if the default role id is different
858 // note: use of assign_capability() is discouraged in upgrade script!
282c1695 859 $userrole = get_record( 'role', 'shortname', 'user' );
860 $defaultroleid = $CFG->defaultuserroleid;
861
862 if( $defaultroleid != $userrole->id ) {
863 // Add in the new moodle/my:manageblocks capibility to the default user role
864 $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
865 assign_capability('moodle/my:manageblocks',CAP_ALLOW,$defaultroleid,$context->id);
866 }
867 }
868
d46306de 869 if ($result && $oldversion < 2007052200) {
870
871 /// Define field schedule to be dropped from events_queue
872 $table = new XMLDBTable('events_queue');
873 $field = new XMLDBField('schedule');
874
875 /// Launch drop field stackdump
876 $result = $result && drop_field($table, $field);
877 }
878
ec4560cc 879 if ($result && $oldversion < 2007052300) {
880 require_once($CFG->dirroot . '/question/upgrade.php');
881 $result = $result && question_remove_rqp_qtype();
882 }
883
1b63e573 884 if ($result && $oldversion < 2007060500) {
885
886 /// Define field usermodified to be added to post
887 $table = new XMLDBTable('post');
888 $field = new XMLDBField('usermodified');
889 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'created');
890
891 /// Launch add field usermodified
892 $result = $result && add_field($table, $field);
271e6dec 893
1b63e573 894 /// Define key usermodified (foreign) to be added to post
895 $table = new XMLDBTable('post');
896 $key = new XMLDBKey('usermodified');
897 $key->setAttributes(XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
898
899 /// Launch add key usermodified
900 $result = $result && add_key($table, $key);
901 }
ac9b0805 902
42ff9ce6 903 if ($result && $oldversion < 2007070603) {
904 // Small update of guest user to be 100% sure it has the correct mnethostid (MDL-10375)
905 set_field('user', 'mnethostid', $CFG->mnet_localhost_id, 'username', 'guest');
906 }
907
908 if ($result && $oldversion < 2007071400) {
909 /**
910 ** mnet application table
911 **/
912 $table = new XMLDBTable('mnet_application');
913 $table->comment = 'Information about applications on remote hosts';
914 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
915 XMLDB_NOTNULL,XMLDB_SEQUENCE, null, null, null);
916 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '50', null,
917 XMLDB_NOTNULL, NULL, null, null, null);
918 $f = $table->addFieldInfo('display_name', XMLDB_TYPE_CHAR, '50', null,
919 XMLDB_NOTNULL, NULL, null, null, null);
920 $f = $table->addFieldInfo('xmlrpc_server_url', XMLDB_TYPE_CHAR, '255', null,
921 XMLDB_NOTNULL, NULL, null, null, null);
922 $f = $table->addFieldInfo('sso_land_url', XMLDB_TYPE_CHAR, '255', null,
923 XMLDB_NOTNULL, NULL, null, null, null);
924
925 // PK and indexes
926 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
927 // Create the table
928 $result = $result && create_table($table);
929
930 // Insert initial applications (moodle and mahara)
931 $application = new stdClass();
932 $application->name = 'moodle';
933 $application->display_name = 'Moodle';
934 $application->xmlrpc_server_url = '/mnet/xmlrpc/server.php';
935 $application->sso_land_url = '/auth/mnet/land.php';
936 if ($result) {
937 $newid = insert_record('mnet_application', $application, false);
938 }
939
940 $application = new stdClass();
941 $application->name = 'mahara';
942 $application->display_name = 'Mahara';
943 $application->xmlrpc_server_url = '/api/xmlrpc/server.php';
944 $application->sso_land_url = '/auth/xmlrpc/land.php';
945 $result = $result && insert_record('mnet_application', $application, false);
271e6dec 946
42ff9ce6 947 // New mnet_host->applicationid field
948 $table = new XMLDBTable('mnet_host');
949 $field = new XMLDBField('applicationid');
950 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, $newid , 'last_log_id');
951
952 $result = $result && add_field($table, $field);
953
954 /// Define key applicationid (foreign) to be added to mnet_host
955 $table = new XMLDBTable('mnet_host');
956 $key = new XMLDBKey('applicationid');
957 $key->setAttributes(XMLDB_KEY_FOREIGN, array('applicationid'), 'mnet_application', array('id'));
958
959 /// Launch add key applicationid
960 $result = $result && add_key($table, $key);
578075c6 961
42ff9ce6 962 }
963
964 if ($result && $oldversion < 2007071607) {
965 require_once($CFG->dirroot . '/question/upgrade.php');
966 $result = $result && question_remove_rqp_qtype_config_string();
967 }
968
42ff9ce6 969 if ($result && $oldversion < 2007072200) {
42ff9ce6 970
971/// Remove all grade tables used in development phases - we need new empty tables for final gradebook upgrade
972 $tables = array('grade_categories',
973 'grade_items',
974 'grade_calculations',
975 'grade_grades',
976 'grade_grades_raw',
977 'grade_grades_final',
978 'grade_grades_text',
979 'grade_outcomes',
980 'grade_outcomes_courses',
981 'grade_history',
982 'grade_import_newitem',
983 'grade_import_values');
578075c6 984
b3ac6c3e 985 foreach ($tables as $table) {
986 $table = new XMLDBTable($table);
987 if (table_exists($table)) {
988 drop_table($table);
989 }
578075c6 990 }
578075c6 991
42ff9ce6 992 $tables = array('grade_categories_history',
993 'grade_items_history',
994 'grade_grades_history',
995 'grade_grades_text_history',
996 'grade_scale_history',
997 'grade_outcomes_history');
998
999 foreach ($tables as $table) {
1000 $table = new XMLDBTable($table);
1001 if (table_exists($table)) {
1002 drop_table($table);
1003 }
1004 }
1005
1006
1007 /// Define table grade_outcomes to be created
1008 $table = new XMLDBTable('grade_outcomes');
1009
1010 /// Adding fields to table grade_outcomes
1011 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1012 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1013 $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1014 $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
1015 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
678a79ca 1016 $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
42ff9ce6 1017 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1018 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1019 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1020
1021 /// Adding keys to table grade_outcomes
1022 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1023 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1024 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
1025 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
1026
1027 /// Launch create table for grade_outcomes
1028 $result = $result && create_table($table);
1029
1030
42ff9ce6 1031 /// Define table grade_categories to be created
1032 $table = new XMLDBTable('grade_categories');
1033
1034 /// Adding fields to table grade_categories
1035 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1036 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1037 $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1038 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1039 $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1040 $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1041 $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1042 $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1043 $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
c2efb501 1044 $table->addFieldInfo('aggregateonlygraded', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
29d509f5 1045 $table->addFieldInfo('aggregateoutcomes', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
c2efb501 1046 $table->addFieldInfo('aggregatesubcats', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
42ff9ce6 1047 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1048 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1049
1050 /// Adding keys to table grade_categories
1051 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1052 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1053 $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id'));
1054
1055 /// Launch create table for grade_categories
1056 $result = $result && create_table($table);
1057
61c33818 1058
b3ac6c3e 1059 /// Define table grade_items to be created
1060 $table = new XMLDBTable('grade_items');
61c33818 1061
b3ac6c3e 1062 /// Adding fields to table grade_items
197ba19c 1063 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
b3ac6c3e 1064 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1065 $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1066 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1067 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
1068 $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
1069 $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1070 $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1071 $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1072 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1073 $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1074 $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '1');
1075 $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');
1076 $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1077 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
abd30252 1078 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
b3ac6c3e 1079 $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1080 $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '1.0');
1081 $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
cea2542b 1082 $table->addFieldInfo('aggregationcoef', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
b3ac6c3e 1083 $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1084 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1085 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1086 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
b3ac6c3e 1087 $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1088 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1089 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
61c33818 1090
b3ac6c3e 1091 /// Adding keys to table grade_items
1092 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1093 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1094 $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN, array('categoryid'), 'grade_categories', array('id'));
1095 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
1096 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id'));
61c33818 1097
173403cf 1098 /// Adding indexes to table grade_grades
6c9f6725 1099 $table->addIndexInfo('locked-locktime', XMLDB_INDEX_NOTUNIQUE, array('locked', 'locktime'));
90274c73 1100 $table->addIndexInfo('itemtype-needsupdate', XMLDB_INDEX_NOTUNIQUE, array('itemtype', 'needsupdate'));
1101 $table->addIndexInfo('gradetype', XMLDB_INDEX_NOTUNIQUE, array('gradetype'));
173403cf 1102
b3ac6c3e 1103 /// Launch create table for grade_items
1104 $result = $result && create_table($table);
f92dcad8 1105
f92dcad8 1106
b3ac6c3e 1107 /// Define table grade_grades to be created
1108 $table = new XMLDBTable('grade_grades');
f92dcad8 1109
b3ac6c3e 1110 /// Adding fields to table grade_grades
197ba19c 1111 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
b3ac6c3e 1112 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1113 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1114 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
1115 $table->addFieldInfo('rawgrademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');
1116 $table->addFieldInfo('rawgrademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1117 $table->addFieldInfo('rawscaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1118 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1119 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
1120 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1121 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1122 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1123 $table->addFieldInfo('exported', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
98353ff1 1124 $table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
23207a1a 1125 $table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
b3ac6c3e 1126 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1127 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
f92dcad8 1128
b3ac6c3e 1129 /// Adding keys to table grade_grades
1130 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1131 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
1132 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1133 $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN, array('rawscaleid'), 'scale', array('id'));
1134 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
f92dcad8 1135
173403cf 1136 /// Adding indexes to table grade_grades
6c9f6725 1137 $table->addIndexInfo('locked-locktime', XMLDB_INDEX_NOTUNIQUE, array('locked', 'locktime'));
173403cf 1138
b3ac6c3e 1139 /// Launch create table for grade_grades
1140 $result = $result && create_table($table);
f92dcad8 1141
61c33818 1142
b3ac6c3e 1143 /// Define table grade_grades_text to be created
1144 $table = new XMLDBTable('grade_grades_text');
61c33818 1145
b3ac6c3e 1146 /// Adding fields to table grade_grades_text
197ba19c 1147 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
b3ac6c3e 1148 $table->addFieldInfo('gradeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1149 $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1150 $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1151 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1152 $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1153 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1154 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
1155 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
1156
1157 /// Adding keys to table grade_grades_text
1158 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
f13002d5 1159 $table->addKeyInfo('gradeid', XMLDB_KEY_FOREIGN, array('gradeid'), 'grade_grades', array('id'));
b3ac6c3e 1160 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
1161
1162 /// Launch create table for grade_grades_text
1163 $result = $result && create_table($table);
1164
1165
42ff9ce6 1166 /// Define table grade_outcomes_history to be created
1167 $table = new XMLDBTable('grade_outcomes_history');
b3ac6c3e 1168
42ff9ce6 1169 /// Adding fields to table grade_outcomes_history
197ba19c 1170 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
abd30252 1171 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1172 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
42ff9ce6 1173 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1174 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1175 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
b3ac6c3e 1176 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1177 $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1178 $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
1179 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
678a79ca 1180 $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
b3ac6c3e 1181
42ff9ce6 1182 /// Adding keys to table grade_outcomes_history
b3ac6c3e 1183 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
42ff9ce6 1184 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_outcomes', array('id'));
b3ac6c3e 1185 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1186 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
42ff9ce6 1187 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id'));
b3ac6c3e 1188
42ff9ce6 1189 /// Adding indexes to table grade_outcomes_history
1190 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
b3ac6c3e 1191
42ff9ce6 1192 /// Launch create table for grade_outcomes_history
1193 $result = $result && create_table($table);
61c33818 1194
f13002d5 1195
42ff9ce6 1196 /// Define table grade_categories_history to be created
1197 $table = new XMLDBTable('grade_categories_history');
f13002d5 1198
42ff9ce6 1199 /// Adding fields to table grade_categories_history
1200 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
abd30252 1201 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1202 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
42ff9ce6 1203 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1204 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1205 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1206 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1207 $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1208 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1209 $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1210 $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1211 $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1212 $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1213 $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
c2efb501 1214 $table->addFieldInfo('aggregateonlygraded', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
29d509f5 1215 $table->addFieldInfo('aggregateoutcomes', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
c2efb501 1216 $table->addFieldInfo('aggregatesubcats', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
4a129c47 1217
42ff9ce6 1218 /// Adding keys to table grade_categories_history
1219 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1220 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_categories', array('id'));
1221 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1222 $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id'));
1223 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id'));
aaff71da 1224
42ff9ce6 1225 /// Adding indexes to table grade_categories_history
1226 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
aaff71da 1227
42ff9ce6 1228 /// Launch create table for grade_categories_history
1229 $result = $result && create_table($table);
aaff71da 1230
1231
1232 /// Define table grade_items_history to be created
1233 $table = new XMLDBTable('grade_items_history');
1234
1235 /// Adding fields to table grade_items_history
197ba19c 1236 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
abd30252 1237 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1238 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
aaff71da 1239 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1240 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
42ff9ce6 1241 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
aaff71da 1242 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1243 $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1244 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1245 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
1246 $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
1247 $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1248 $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1249 $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1250 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1251 $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1252 $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '1');
1253 $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');
1254 $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1255 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
abd30252 1256 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
aaff71da 1257 $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1258 $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '1.0');
1259 $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
cea2542b 1260 $table->addFieldInfo('aggregationcoef', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
aaff71da 1261 $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1262 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1263 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1264 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1265 $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1266
1267 /// Adding keys to table grade_items_history
1268 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1269 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_items', array('id'));
1270 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1271 $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN, array('categoryid'), 'grade_categories', array('id'));
1272 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
1273 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id'));
42ff9ce6 1274 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id'));
aaff71da 1275
1276 /// Adding indexes to table grade_items_history
1277 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
1278
1279 /// Launch create table for grade_items_history
1280 $result = $result && create_table($table);
1281
1282
aaff71da 1283 /// Define table grade_grades_history to be created
1284 $table = new XMLDBTable('grade_grades_history');
1285
1286 /// Adding fields to table grade_grades_history
197ba19c 1287 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
abd30252 1288 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1289 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
aaff71da 1290 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1291 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
42ff9ce6 1292 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
aaff71da 1293 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1294 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1295 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
1296 $table->addFieldInfo('rawgrademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');
1297 $table->addFieldInfo('rawgrademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1298 $table->addFieldInfo('rawscaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1299 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1300 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
1301 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1302 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1303 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1304 $table->addFieldInfo('exported', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
98353ff1 1305 $table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
23207a1a 1306 $table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
aaff71da 1307
1308 /// Adding keys to table grade_grades_history
1309 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1310 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_grades', array('id'));
1311 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
1312 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1313 $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN, array('rawscaleid'), 'scale', array('id'));
1314 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
42ff9ce6 1315 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id'));
aaff71da 1316
1317 /// Adding indexes to table grade_grades_history
1318 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
1319
1320 /// Launch create table for grade_grades_history
1321 $result = $result && create_table($table);
1322
1323
1324 /// Define table grade_grades_text_history to be created
1325 $table = new XMLDBTable('grade_grades_text_history');
1326
1327 /// Adding fields to table grade_grades_text_history
197ba19c 1328 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
abd30252 1329 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1330 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
aaff71da 1331 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1332 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
42ff9ce6 1333 $table->addFieldInfo('loggeduser', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
aaff71da 1334 $table->addFieldInfo('gradeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1335 $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1336 $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1337 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1338 $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1339 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1340
1341 /// Adding keys to table grade_grades_text_history
1342 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1343 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_grades_text', array('id'));
1344 $table->addKeyInfo('gradeid', XMLDB_KEY_FOREIGN, array('gradeid'), 'grade_grades', array('id'));
1345 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
42ff9ce6 1346 $table->addKeyInfo('loggeduser', XMLDB_KEY_FOREIGN, array('loggeduser'), 'user', array('id'));
aaff71da 1347
1348 /// Adding indexes to table grade_grades_text_history
1349 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
1350
1351 /// Launch create table for grade_grades_text_history
1352 $result = $result && create_table($table);
1353
1354
76a50d17 1355 /// Define table grade_import_newitem to be created
1356 $table = new XMLDBTable('grade_import_newitem');
1357
1358 /// Adding fields to table grade_import_newitem
1359 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1360 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1361 $table->addFieldInfo('import_code', XMLDB_TYPE_INTEGER, '12', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1362
1363 /// Adding keys to table grade_import_newitem
1364 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1365
1366 /// Launch create table for grade_import_newitem
1367 $result = $result && create_table($table);
1368
42ff9ce6 1369
76a50d17 1370 /// Define table grade_import_values to be created
1371 $table = new XMLDBTable('grade_import_values');
1372
1373 /// Adding fields to table grade_import_values
1374 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1375 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1376 $table->addFieldInfo('newgradeitem', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1377 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1378 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1379 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1380 $table->addFieldInfo('import_code', XMLDB_TYPE_INTEGER, '12', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1381
1382 /// Adding keys to table grade_import_values
1383 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1384 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
1385 $table->addKeyInfo('newgradeitem', XMLDB_KEY_FOREIGN, array('newgradeitem'), 'grade_import_newitem', array('id'));
1386
1387 /// Launch create table for grade_import_values
1388 $result = $result && create_table($table);
efe256e4 1389
42ff9ce6 1390 /// upgrade the old 1.8 gradebook - migrade data into new grade tables
1391 if ($result) {
1392 require_once($CFG->libdir.'/db/upgradelib.php');
1393 if ($rs = get_recordset('course')) {
1394 if ($rs->RecordCount() > 0) {
1395 while ($course = rs_fetch_next_record($rs)) {
1396 // this function uses SQL only, it must not be changed after 1.9 goes stable!!
1397 if (!upgrade_18_gradebook($course->id)) {
1398 $result = false;
1399 break;
1400 }
1401 }
1402 }
1403 rs_close($rs);
1404 }
cea2542b 1405 }
cea2542b 1406 }
1407
b264019b 1408 if ($result && $oldversion < 2007072400) {
1409 /// Dropping one DEFAULT in a TEXT column. It's was only one remaining
1410 /// since Moodle 1.7, so new servers won't have those anymore.
1411
1412 /// Changing the default of field sessdata on table sessions2 to drop it
1413 $table = new XMLDBTable('sessions2');
1414 $field = new XMLDBField('sessdata');
1415 $field->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, null, 'modified');
1416
1417 /// Launch change of default for field sessdata
1418 $result = $result && change_field_default($table, $field);
1419 }
1420
521d54ec 1421
1422 if ($result && $oldversion < 2007073100) {
271e6dec 1423 /// Define table grade_outcomes_courses to be created
1424 $table = new XMLDBTable('grade_outcomes_courses');
1425
1426 /// Adding fields to table grade_outcomes_courses
abd30252 1427 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
271e6dec 1428 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1429 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1430
1431 /// Adding keys to table grade_outcomes_courses
1432 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1433 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1434 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id'));
f37cc4bb 1435 $table->addKeyInfo('courseid-outcomeid', XMLDB_KEY_UNIQUE, array('courseid', 'outcomeid'));
271e6dec 1436 /// Launch create table for grade_outcomes_courses
e480c18c 1437 $result = $result && create_table($table);
1438
e99c48d8 1439 }
173a9d21 1440
79642064 1441
1442 if ($result && $oldversion < 2007073101) { // Add new tag tables
1443
1444 /// Define table tag to be created
1445 $table = new XMLDBTable('tag');
1446
1447 /// Adding fields to table tag
1448 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1449 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null, null, null);
1450 $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1451 $table->addFieldInfo('tagtype', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1452 $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null);
1453 $table->addFieldInfo('descriptionformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, null, null, null);
1454 $table->addFieldInfo('flag', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '0');
1455 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1456
1457 /// Adding keys to table tag
1458 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1459
1460 /// Adding indexes to table tag
1461 $table->addIndexInfo('name', XMLDB_INDEX_UNIQUE, array('name'));
1462
1463 /// Launch create table for tag
1464 $result = $result && create_table($table);
1465
1466
1467
1468 /// Define table tag_correlation to be created
1469 $table = new XMLDBTable('tag_correlation');
1470
1471 /// Adding fields to table tag_correlation
1472 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1473 $table->addFieldInfo('tagid', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null, null, null);
1474 $table->addFieldInfo('correlatedtags', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
1475
1476 /// Adding keys to table tag_correlation
1477 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1478
1479 /// Adding indexes to table tag_correlation
1480 $table->addIndexInfo('tagid', XMLDB_INDEX_UNIQUE, array('tagid'));
1481
1482 /// Launch create table for tag_correlation
1483 $result = $result && create_table($table);
1484
1485
1486
1487 /// Define table tag_instance to be created
1488 $table = new XMLDBTable('tag_instance');
1489
1490 /// Adding fields to table tag_instance
1491 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1492 $table->addFieldInfo('tagid', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null, null, null);
1493 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1494 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null, null, null);
1495
1496 /// Adding keys to table tag_instance
1497 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1498
1499 /// Adding indexes to table tag_instance
1500 $table->addIndexInfo('tagiditem', XMLDB_INDEX_NOTUNIQUE, array('tagid', 'itemtype', 'itemid'));
1501
1502 /// Launch create table for tag_instance
1503 $result = $result && create_table($table);
1504
1505 }
1506
1507
705789bd 1508 if ($result && $oldversion < 2007073103) {
1509
1510 /// Define field rawname to be added to tag
1511 $table = new XMLDBTable('tag');
1512 $field = new XMLDBField('rawname');
1513 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'name');
1514
1515 /// Launch add field rawname
1516 $result = $result && add_field($table, $field);
1517 }
1518
678a79ca 1519 if ($result && $oldversion < 2007073105) {
1520
1521 /// Define field description to be added to grade_outcomes
1522 $table = new XMLDBTable('grade_outcomes');
1523 $field = new XMLDBField('description');
1524 if (!field_exists($table, $field)) {
1525 $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'scaleid');
1526 /// Launch add field description
1527 $result = $result && add_field($table, $field);
1528 }
1529
1530 $table = new XMLDBTable('grade_outcomes_history');
1531 $field = new XMLDBField('description');
1532 if (!field_exists($table, $field)) {
1533 $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'scaleid');
1534 /// Launch add field description
1535 $result = $result && add_field($table, $field);
1536 }
678a79ca 1537 }
271e6dec 1538
1f496ded 1539 // adding unique contraint on (courseid,shortname) of an outcome
1540 if ($result && $oldversion < 2007080100) {
1541
1542 /// Define key courseid-shortname (unique) to be added to grade_outcomes
1543 $table = new XMLDBTable('grade_outcomes');
1544 $key = new XMLDBKey('courseid-shortname');
1545 $key->setAttributes(XMLDB_KEY_UNIQUE, array('courseid', 'shortname'));
705789bd 1546
1f496ded 1547 /// Launch add key courseid-shortname
1548 $result = $result && add_key($table, $key);
1549 }
705789bd 1550
9610a4fa 1551 if ($result && $oldversion < 2007080101) {
1552 if ($firstadmin = get_admin()) { // the person currently used for support emails
1553 set_config('supportname', s(fullname($firstadmin))); // New settings same as old
1554 set_config('supportemail', s($firstadmin->email));
1555 }
1556 }
271e6dec 1557
c345bb58 1558 /// MDL-10679, context_rel clean up
1559 if ($result && $oldversion < 2007080200) {
1560 delete_records('context_rel');
dd14fecf 1561 /// /deprecated and gone / build_context_rel();
c345bb58 1562 }
9610a4fa 1563
1a85d89a 1564 if ($result && $oldversion < 2007080202) {
32ef9149 1565
1566 /// Define index tagiditem (not unique) to be dropped form tag_instance
1567 $table = new XMLDBTable('tag_instance');
1568 $index = new XMLDBIndex('tagiditem');
1a85d89a 1569 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('tagid', 'itemtype', 'itemid'));
32ef9149 1570
1571 /// Launch drop index tagiditem
1572 drop_index($table, $index);
1573
1574 /// Define index tagiditem (unique) to be added to tag_instance
1a85d89a 1575 $table = new XMLDBTable('tag_instance');
1576 $index = new XMLDBIndex('tagiditem');
32ef9149 1577 $index->setAttributes(XMLDB_INDEX_UNIQUE, array('tagid', 'itemtype', 'itemid'));
1578
1579 /// Launch add index tagiditem
1580 $result = $result && add_index($table, $index);
1581
1582 }
1583
29d509f5 1584 if ($result && $oldversion < 2007080300) {
1585
1586 /// Define field aggregateoutcomes to be added to grade_categories
1587 $table = new XMLDBTable('grade_categories');
1588 $field = new XMLDBField('aggregateoutcomes');
1589 if (!field_exists($table, $field)) {
1590 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'droplow');
1591
1592 /// Launch add field aggregateoutcomes
1593 $result = $result && add_field($table, $field);
1594 }
1595
1596 /// Define field aggregateoutcomes to be added to grade_categories
1597 $table = new XMLDBTable('grade_categories_history');
1598 $field = new XMLDBField('aggregateoutcomes');
1599 if (!field_exists($table, $field)) {
1600 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'droplow');
1601
1602 /// Launch add field aggregateoutcomes
1603 $result = $result && add_field($table, $field);
1604 }
1605 }
32ef9149 1606
341426f0 1607 if ($result && $oldversion < 2007080800) { /// Normalize course->shortname MDL-10026
1608
1609 /// Changing precision of field shortname on table course to (100)
1610 $table = new XMLDBTable('course');
1611 $field = new XMLDBField('shortname');
1612 $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null, 'fullname');
1613
1614 /// Launch change of precision for field shortname
1615 $result = $result && change_field_precision($table, $field);
1616 }
1617
c7c57cfb 1618 if ($result && $oldversion < 2007080900) {
1619 /// Add context.path & index
1620 $table = new XMLDBTable('context');
1621 $field = new XMLDBField('path');
efd261ce 1622 $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'instanceid');
c7c57cfb 1623 $result = $result && add_field($table, $field);
1624 $table = new XMLDBTable('context');
1625 $index = new XMLDBIndex('path');
1626 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('path'));
1627 $result = $result && add_index($table, $index);
1628
1629 /// Add context.depth
1630 $table = new XMLDBTable('context');
1631 $field = new XMLDBField('depth');
1632 $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'path');
1633 $result = $result && add_field($table, $field);
1634 }
1635
6c9f6725 1636 if ($result && $oldversion < 2007080903) {
173403cf 1637 /// Define index
1638 $table = new XMLDBTable('grade_grades');
6c9f6725 1639 $index = new XMLDBIndex('locked-locktime');
1640 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('locked', 'locktime'));
173403cf 1641
1642 if (!index_exists($table, $index)) {
1643 /// Launch add index
1644 $result = $result && add_index($table, $index);
1645 }
1646
1647 /// Define index
1648 $table = new XMLDBTable('grade_items');
6c9f6725 1649 $index = new XMLDBIndex('locked-locktime');
1650 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('locked', 'locktime'));
173403cf 1651
1652 if (!index_exists($table, $index)) {
1653 /// Launch add index
1654 $result = $result && add_index($table, $index);
1655 }
1656
90274c73 1657 /// Define index itemtype-needsupdate (not unique) to be added to grade_items
1658 $table = new XMLDBTable('grade_items');
1659 $index = new XMLDBIndex('itemtype-needsupdate');
1660 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('itemtype', 'needsupdate'));
1661 if (!index_exists($table, $index)) {
1662 /// Launch add index itemtype-needsupdate
1663 $result = $result && add_index($table, $index);
1664 }
1665
173403cf 1666 /// Define index
1667 $table = new XMLDBTable('grade_items');
90274c73 1668 $index = new XMLDBIndex('gradetype');
1669 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('gradetype'));
173403cf 1670
1671 if (!index_exists($table, $index)) {
1672 /// Launch add index
1673 $result = $result && add_index($table, $index);
1674 }
1675
173403cf 1676 }
1677
2524b0f2 1678 if ($result && $oldversion < 2007081000) {
1679 require_once($CFG->dirroot . '/question/upgrade.php');
1680 $result = $result && question_upgrade_context_etc();
1681 }
1682
1683 if ($result && $oldversion < 2007081302) {
1684 require_once($CFG->libdir.'/db/upgradelib.php');
1685
1686 if (table_exists(new XMLDBTable('groups_groupings'))) {
1687 /// IF 'groups_groupings' table exists, this is for 1.8.* only.
1688 $result = $result && upgrade_18_groups();
1689
1690 } else {
1691 /// ELSE, 1.7.*/1.6.*/1.5.* - create 'groupings' and 'groupings_groups' + rename password to enrolmentkey
1692 $result = $result && upgrade_17_groups();
1693 }
1694
1695 /// For both 1.8.* and 1.7.*/1.6.*..
1696
1697 // delete not used fields
1698 $table = new XMLDBTable('groups');
1699 $field = new XMLDBField('theme');
1700 if (field_exists($table, $field)) {
1701 drop_field($table, $field);
1702 }
1703 $table = new XMLDBTable('groups');
1704 $field = new XMLDBField('lang');
1705 if (field_exists($table, $field)) {
1706 drop_field($table, $field);
1707 }
1708
1709 /// Add groupingid field/f.key to 'course' table.
1710 $table = new XMLDBTable('course');
1711 $field = new XMLDBField('defaultgroupingid');
1712 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', $prev='groupmodeforce');
1713 $result = $result && add_field($table, $field);
1714
1715
1716 /// Add grouping ID, grouponly field/f.key to 'course_modules' table.
1717 $table = new XMLDBTable('course_modules');
1718 $field = new XMLDBField('groupingid');
1719 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', $prev='groupmode');
1720 $result = $result && add_field($table, $field);
1721
1722 $table = new XMLDBTable('course_modules');
1723 $field = new XMLDBField('groupmembersonly');
1724 $field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', $prev='groupingid');
1725 $result = $result && add_field($table, $field);
1726
1727 $table = new XMLDBTable('course_modules');
1728 $key = new XMLDBKey('groupingid');
1729 $key->setAttributes(XMLDB_KEY_FOREIGN, array('groupingid'), 'groupings', array('id'));
1730 $result = $result && add_key($table, $key);
1731
1732 }
1733
1acd661d 1734 if ($result && $oldversion < 2007082300) {
1735
1736 /// Define field ordering to be added to tag_instance table
1737 $table = new XMLDBTable('tag_instance');
1738 $field = new XMLDBField('ordering');
e480c18c 1739
1acd661d 1740 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'itemid');
1741
1742 /// Launch add field rawname
1743 $result = $result && add_field($table, $field);
e480c18c 1744 }
2524b0f2 1745
a4232e95 1746 if ($result && $oldversion < 2007082700) {
1747
1748 /// Define field timemodified to be added to tag_instance
1749 $table = new XMLDBTable('tag_instance');
1750 $field = new XMLDBField('timemodified');
1751 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'ordering');
1752
1753 /// Launch add field timemodified
1754 $result = $result && add_field($table, $field);
1755 }
e480c18c 1756
bd1f4559 1757 /// migrate all tags table to tag
1758 if ($result && $oldversion < 2007082701) {
e480c18c 1759 require_once($CFG->dirroot.'/tag/lib.php');
bd1f4559 1760 $tagrefs = array(); // $tagrefs[$oldtagid] = $newtagid
1761 if ($tags = get_records('tags')) {
1762 foreach ($tags as $oldtag) {
1763 // if this tag does not exist in tag table yet
1764 if (!$newtag = get_record('tag', 'name', tag_normalize($oldtag->text))) {
c2efb501 1765 $itag = new object();
bd1f4559 1766 $itag->name = tag_normalize($oldtag->text);
1767 $itag->rawname = tag_normalize($oldtag->text, false);
1768
1769 if ($oldtag->type == 'official') {
1770 $itag->tagtype = $oldtag->type;
1771 } else {
1772 $itag->tagtype = 'default';
1773 }
1774 $itag->userid = $oldtag->userid;
1775 $itag->timemodified = time();
a4232e95 1776
bd1f4559 1777 if ($idx = insert_record('tag', $itag)) {
1778 $tagrefs[$oldtag->id] = $idx;
1779 }
1780 // if this tag is already used by tag table
1781 } else {
1782 $tagrefs[$oldtag->id] = $newtag->id;
1783 }
1784 }
1785 }
e480c18c 1786
bd1f4559 1787 // fetch all the tag instances and migrate them as well
1788 if ($blogtags = get_records('blog_tag_instance')) {
1789 foreach ($blogtags as $blogtag) {
1790 if (!empty($tagrefs[$blogtag->tagid])) {
1791 tag_an_item('blog', $blogtag->entryid, $tagrefs[$blogtag->tagid]);
1792 }
1793 }
1794 }
1795
1796 $table = new XMLDBTable('tags');
1797 drop_table($table);
1798 $table = new XMLDBTable('blog_tag_instance');
1799 drop_table($table);
1800 }
e480c18c 1801
c4956945 1802 /// MDL-11015, MDL-11016
1803 if ($result && $oldversion < 2007082800) {
1804
1805 /// Changing type of field userid on table tag to int
1806 $table = new XMLDBTable('tag');
1807 $field = new XMLDBField('userid');
1808 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');
1809
1810 /// Launch change of type for field userid
1811 $result = $result && change_field_type($table, $field);
e480c18c 1812
c4956945 1813 /// Changing type of field descriptionformat on table tag to int
1814 $table = new XMLDBTable('tag');
1815 $field = new XMLDBField('descriptionformat');
1816 $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'description');
1817
1818 /// Launch change of type for field descriptionformat
1819 $result = $result && change_field_type($table, $field);
e480c18c 1820
c4956945 1821 /// Define key userid (foreign) to be added to tag
1822 $table = new XMLDBTable('tag');
1823 $key = new XMLDBKey('userid');
1824 $key->setAttributes(XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1825
1826 /// Launch add key userid
1827 $result = $result && add_key($table, $key);
e480c18c 1828
c4956945 1829 /// Define index tagiditem (unique) to be dropped form tag_instance
1830 $table = new XMLDBTable('tag_instance');
1831 $index = new XMLDBIndex('tagiditem');
1832 $index->setAttributes(XMLDB_INDEX_UNIQUE, array('tagid', 'itemtype', 'itemid'));
1833
1834 /// Launch drop index tagiditem
1835 $result = $result && drop_index($table, $index);
e480c18c 1836
c4956945 1837 /// Changing type of field tagid on table tag_instance to int
1838 $table = new XMLDBTable('tag_instance');
1839 $field = new XMLDBField('tagid');
1840 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');
1841
1842 /// Launch change of type for field tagid
1843 $result = $result && change_field_type($table, $field);
e480c18c 1844
c4956945 1845 /// Define key tagid (foreign) to be added to tag_instance
1846 $table = new XMLDBTable('tag_instance');
1847 $key = new XMLDBKey('tagid');
1848 $key->setAttributes(XMLDB_KEY_FOREIGN, array('tagid'), 'tag', array('id'));
1849
1850 /// Launch add key tagid
e480c18c 1851 $result = $result && add_key($table, $key);
c4956945 1852
1853 /// Changing sign of field itemid on table tag_instance to unsigned
1854 $table = new XMLDBTable('tag_instance');
1855 $field = new XMLDBField('itemid');
1856 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'itemtype');
1857
1858 /// Launch change of sign for field itemid
1859 $result = $result && change_field_unsigned($table, $field);
e480c18c 1860
c4956945 1861 /// Changing sign of field ordering on table tag_instance to unsigned
1862 $table = new XMLDBTable('tag_instance');
1863 $field = new XMLDBField('ordering');
1864 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'itemid');
1865
1866 /// Launch change of sign for field ordering
e480c18c 1867 $result = $result && change_field_unsigned($table, $field);
1868
c4956945 1869 /// Define index itemtype-itemid-tagid (unique) to be added to tag_instance
1870 $table = new XMLDBTable('tag_instance');
1871 $index = new XMLDBIndex('itemtype-itemid-tagid');
1872 $index->setAttributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));
1873
1874 /// Launch add index itemtype-itemid-tagid
1875 $result = $result && add_index($table, $index);
e480c18c 1876
c4956945 1877 /// Define index tagid (unique) to be dropped form tag_correlation
1878 $table = new XMLDBTable('tag_correlation');
1879 $index = new XMLDBIndex('tagid');
1880 $index->setAttributes(XMLDB_INDEX_UNIQUE, array('tagid'));
1881
1882 /// Launch drop index tagid
e480c18c 1883 $result = $result && drop_index($table, $index);
1884
c4956945 1885 /// Changing type of field tagid on table tag_correlation to int
1886 $table = new XMLDBTable('tag_correlation');
1887 $field = new XMLDBField('tagid');
1888 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');
1889
1890 /// Launch change of type for field tagid
1891 $result = $result && change_field_type($table, $field);
e480c18c 1892
1893
c4956945 1894 /// Define key tagid (foreign) to be added to tag_correlation
1895 $table = new XMLDBTable('tag_correlation');
1896 $key = new XMLDBKey('tagid');
1897 $key->setAttributes(XMLDB_KEY_FOREIGN, array('tagid'), 'tag', array('id'));
1898
1899 /// Launch add key tagid
1900 $result = $result && add_key($table, $key);
e480c18c 1901
1902 }
61c6071f 1903
1904
1905 if ($result && $oldversion < 2007082801) {
1906
1907 /// Define table user_private_key to be created
1908 $table = new XMLDBTable('user_private_key');
1909
1910 /// Adding fields to table user_private_key
1911 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1912 $table->addFieldInfo('script', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null, null, null);
1913 $table->addFieldInfo('value', XMLDB_TYPE_CHAR, '128', null, XMLDB_NOTNULL, null, null, null, null);
1914 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1915 $table->addFieldInfo('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1916 $table->addFieldInfo('iprestriction', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1917 $table->addFieldInfo('validuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1918 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1919
1920 /// Adding keys to table user_private_key
1921 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1922 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1923
1924 /// Adding indexes to table user_private_key
1925 $table->addIndexInfo('script-value', XMLDB_INDEX_NOTUNIQUE, array('script', 'value'));
1926
1927 /// Launch create table for user_private_key
1928 $result = $result && create_table($table);
1929 }
1930
4149e289 1931/// Going to modify the applicationid from int(1) to int(10). Dropping and
1932/// re-creating the associated keys/indexes is mandatory to be cross-db. MDL-11042
1933 if ($result && $oldversion < 2007082803) {
1934
1935 /// Define key applicationid (foreign) to be dropped form mnet_host
1936 $table = new XMLDBTable('mnet_host');
1937 $key = new XMLDBKey('applicationid');
1938 $key->setAttributes(XMLDB_KEY_FOREIGN, array('applicationid'), 'mnet_application', array('id'));
1939
1940 /// Launch drop key applicationid
1941 $result = $result && drop_key($table, $key);
1942
1943 /// Changing type of field applicationid on table mnet_host to int
1944 $field = new XMLDBField('applicationid');
1945 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'last_log_id');
1946
1947 /// Launch change of type for field applicationid
1948 $result = $result && change_field_type($table, $field);
1949
1950 /// Define key applicationid (foreign) to be added to mnet_host
1951 $key = new XMLDBKey('applicationid');
1952 $key->setAttributes(XMLDB_KEY_FOREIGN, array('applicationid'), 'mnet_application', array('id'));
1953
1954 /// Launch add key applicationid
1955 $result = $result && add_key($table, $key);
1956
1957 }
1958
c2efb501 1959 if ($result && $oldversion < 2007090503) {
1960/// Remove obsoleted unit tests tables - they will be recreated automatically
1961 $tables = array('grade_categories',
1962 'scale',
1963 'grade_items',
1964 'grade_calculations',
1965 'grade_grades',
1966 'grade_grades_raw',
1967 'grade_grades_final',
1968 'grade_grades_text',
1969 'grade_outcomes',
1970 'grade_outcomes_courses');
1971
1972 foreach ($tables as $tablename) {
1973 $table = new XMLDBTable('unittest_'.$tablename);
1974 if (table_exists($table)) {
1975 drop_table($table);
1976 }
1977 $table = new XMLDBTable('unittest_'.$tablename.'_history');
1978 if (table_exists($table)) {
1979 drop_table($table);
1980 }
1981 }
1982
1983
1984 /// Define field aggregatesubcats to be added to grade_categories
1985 $table = new XMLDBTable('grade_categories');
1986 $field = new XMLDBField('aggregatesubcats');
1987 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'aggregateoutcomes');
1988
1989 if (!field_exists($table, $field)) {
1990 /// Launch add field aggregateonlygraded
1991 $result = $result && add_field($table, $field);
1992 }
1993
1994 /// Define field aggregateonlygraded to be added to grade_categories
1995 $table = new XMLDBTable('grade_categories');
1996 $field = new XMLDBField('aggregateonlygraded');
1997 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'droplow');
1998
1999 if (!field_exists($table, $field)) {
2000 /// Launch add field aggregateonlygraded
2001 $result = $result && add_field($table, $field);
2002 }
2003
2004 /// Define field aggregatesubcats to be added to grade_categories_history
2005 $table = new XMLDBTable('grade_categories_history');
2006 $field = new XMLDBField('aggregatesubcats');
2007 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'aggregateoutcomes');
2008
2009 if (!field_exists($table, $field)) {
2010 /// Launch add field aggregateonlygraded
2011 $result = $result && add_field($table, $field);
2012 }
2013
2014 /// Define field aggregateonlygraded to be added to grade_categories_history
2015 $table = new XMLDBTable('grade_categories_history');
2016 $field = new XMLDBField('aggregateonlygraded');
2017 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'droplow');
2018
2019 if (!field_exists($table, $field)) {
2020 /// Launch add field aggregateonlygraded
2021 $result = $result && add_field($table, $field);
2022 }
2023
2024 /// upgrade path in grade_categrories table - now using slash on both ends
2025 $concat = sql_concat('path', "'/'");
2026 $sql = "UPDATE {$CFG->prefix}grade_categories SET path = $concat WHERE path NOT LIKE '/%/'";
2027 execute_sql($sql, true);
2028
2029 /// convert old aggregation constants if needed
2030 for ($i=0; $i<=12; $i=$i+2) {
2031 $j = $i+1;
2032 $sql = "UPDATE {$CFG->prefix}grade_categories SET aggregation = $i, aggregateonlygraded = 1 WHERE aggregation = $j";
2033 execute_sql($sql, true);
2034 }
2035 }
2036
4a039315 2037/// To have UNIQUE indexes over NULLable columns isn't cross-db at all
2038/// so we create a non unique index and programatically enforce uniqueness
2039 if ($result && $oldversion < 2007090600) {
2040
2041 /// Define index idnumber (unique) to be dropped form course_modules
2042 $table = new XMLDBTable('course_modules');
2043 $index = new XMLDBIndex('idnumber');
2044 $index->setAttributes(XMLDB_INDEX_UNIQUE, array('idnumber'));
2045
2046 /// Launch drop index idnumber
2047 $result = $result && drop_index($table, $index);
2048
2049 /// Define index idnumber-course (not unique) to be added to course_modules
2050 $table = new XMLDBTable('course_modules');
2051 $index = new XMLDBIndex('idnumber-course');
2052 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('idnumber', 'course'));
2053
2054 /// Launch add index idnumber-course
2055 $result = $result && add_index($table, $index);
2056
2057 /// Define index idnumber-courseid (not unique) to be added to grade_items
2058 $table = new XMLDBTable('grade_items');
2059 $index = new XMLDBIndex('idnumber-courseid');
2060 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('idnumber', 'courseid'));
2061
2062 /// Launch add index idnumber-courseid
2063 $result = $result && add_index($table, $index);
2064
2065 }
c2efb501 2066
e480c18c 2067 if ($result && $oldversion < 2007091800) {
2068
2069 /// Define field display to be added to grade_items
2070 $table = new XMLDBTable('grade_items');
2071 $field = new XMLDBField('display');
2072 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '-1', 'sortorder');
2073
2074 /// Launch add field display
2075 $result = $result && add_field($table, $field);
2076 }
2077
2078 if ($result && $oldversion < 2007091800) {
2079
2080 /// Define table grade_letters to be created
2081 $table = new XMLDBTable('grade_letters');
2082
2083 /// Adding fields to table grade_letters
2084 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
2085 $table->addFieldInfo('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
2086 $table->addFieldInfo('lowerboundary', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, null);
2087 $table->addFieldInfo('letter', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
2088
2089 /// Adding keys to table grade_letters
2090 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
2091
2092 /// Launch create table for grade_letters
2093 $result = $result && create_table($table);
2094 }
2095
d5d2f8a6 2096
2097/// Create the permanent context_temp table to be used by build_context_path()
2098 if ($result && $oldversion < 2007092001) {
2099
2100 /// Define table context_temp to be created
2101 $table = new XMLDBTable('context_temp');
2102
2103 /// Adding fields to table context_temp
2104 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
2105 $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
2106 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
2107
2108 /// Adding keys to table context_temp
2109 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
2110
2111 /// Launch create table for context_temp
2112 $result = $result && create_table($table);
2113
2114 /// Recalculate depths, paths and so on
c24f4599 2115 cleanup_contexts();
2116 build_context_path(true);
2117 load_all_capabilities();
2118 }
2119
c2efb501 2120
2121/*
2122 /// drop old gradebook tables
2123 if ($result && $oldversion < xxxxxxxx) {
2124 $tables = array('grade_category',
2125 'grade_item',
2126 'grade_letter',
2127 'grade_preferences',
2128 'grade_exceptions');
2129
2130 foreach ($tables as $table) {
2131 $table = new XMLDBTable($table);
2132 if (table_exists($table)) {
2133 drop_table($table);
2134 }
2135 }
2136 }
2137*/
2138
ac9b0805 2139 return $result;
4e423cbf 2140}
271e6dec 2141
2142
4e423cbf 2143?>