MDL-10343 - abort early when can't create temporary tables when syning users
[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
40 set_field('modules', 'visible', '0', 'id', $module->id);
41 // Save existing visible state for all activities
42 set_field('course_modules', 'visibleold', '1', 'visible' ,'1', 'module', $module->id);
43 set_field('course_modules', 'visibleold', '0', 'visible' ,'0', 'module', $module->id);
44 // Hide all activities
45 set_field('course_modules', 'visible', '0', 'module', $module->id);
46
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 }
74807b43 58
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 }
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 }
54dc87b8 95
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);
105
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 }
22ae509e 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);
201 // PK and indexes
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 //
320 // Prime MNET configuration entries -- will be needed later by auth/mnet
321 //
322 include_once $CFG->dirroot . '/mnet/lib.php';
323 $env = new mnet_environment();
324 $env->init();
325 unset($env);
326
327 // add mnethostid to user-
328 $table = new XMLDBTable('user');
329 $field = new XMLDBField('mnethostid');
330 $field->setType(XMLDB_TYPE_INTEGER);
331 $field->setLength(10);
332 $field->setNotNull(true);
333 $field->setSequence(null);
334 $field->setEnum(null);
335 $field->setDefault('0');
336 $field->setPrevious("deleted");
337 $field->setNext("username");
338 $result = $result && add_field($table, $field);
339
340 // The default mnethostid is zero... we need to update this for all
341 // users of the local IdP service.
342 set_field('user',
343 'mnethostid', $CFG->mnet_localhost_id,
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
356 unset($table, $field, $index);
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,
461 XMLDB_NOTNULL, NULL, null, null, 0);
462 $f = $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
463 XMLDB_NOTNULL, NULL, null, null, 0);
464 $f = $table->addFieldInfo('rolename', XMLDB_TYPE_CHAR, '255', null,
465 XMLDB_NOTNULL, NULL, null, null, null);
466 $f = $table->addFieldInfo('enroltime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
467 XMLDB_NOTNULL, NULL, null, null, 0);
468 $f = $table->addFieldInfo('enroltype', XMLDB_TYPE_CHAR, '20', null,
469 XMLDB_NOTNULL, NULL, null, null, null);
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
513 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
514 $table->addFieldInfo('c1', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
515 $table->addFieldInfo('c2', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
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);
525
526 /// code here to fill the context_rel table
527 /// use get record set to iterate slower
528 build_context_rel();
529 }
bb931a61 530
531 if ($result && $oldversion < 2007011501) {
532 if (!empty($CFG->enablerecordcache) && empty($CFG->rcache) &&
533 // Note: won't force-load these settings into CFG
534 // we don't need or want cache during the upgrade itself
535 empty($CFG->cachetype) && empty($CFG->intcachemax)) {
536 set_config('cachetype', 'internal');
537 set_config('rcache', true);
538 set_config('intcachemax', $CFG->enablerecordcache);
539 unset_config('enablerecordcache');
540 unset($CFG->enablerecordcache);
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
652 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
653 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
654 $table->addFieldInfo('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
655 $table->addFieldInfo('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
656 $table->addFieldInfo('sortoder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
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);
682
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);
688
689 $index = new XMLDBIndex('text');
690 $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('text'));
691
692 /// Launch add index text
693 $result = $result && add_index($table, $index);
694 }
177d4abf 695
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');
702
703 /// Launch add field idnumber
704 $result = $result && add_field($table, $field);
705
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) {
720
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);
732
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 }
743
744 }
ec36253d 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);
767
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);
785
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);
816
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
856 if ($result && $oldversion < 2007051101) {
68d20234 857 if (empty($CFG->enablegroupings) and !empty($CFG->group_version)) {
93759def 858 // delete all groupings - they do not work yet :-(
859 // while keeping all existing groups
860 require_once("$CFG->dirroot/group/db/upgrade.php");
861 undo_groupings();
862 }
863 }
864
8c6c185a 865 if (!empty($CFG->rolesactive) && $result && $oldversion < 2007051801) {
866 // Get the role id of the "Auth. User" role and check if the default role id is different
867 // note: use of assign_capability() is discouraged in upgrade script!
282c1695 868 $userrole = get_record( 'role', 'shortname', 'user' );
869 $defaultroleid = $CFG->defaultuserroleid;
870
871 if( $defaultroleid != $userrole->id ) {
872 // Add in the new moodle/my:manageblocks capibility to the default user role
873 $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
874 assign_capability('moodle/my:manageblocks',CAP_ALLOW,$defaultroleid,$context->id);
875 }
876 }
877
d46306de 878 if ($result && $oldversion < 2007052200) {
879
880 /// Define field schedule to be dropped from events_queue
881 $table = new XMLDBTable('events_queue');
882 $field = new XMLDBField('schedule');
883
884 /// Launch drop field stackdump
885 $result = $result && drop_field($table, $field);
886 }
887
ec4560cc 888 if ($result && $oldversion < 2007052300) {
889 require_once($CFG->dirroot . '/question/upgrade.php');
890 $result = $result && question_remove_rqp_qtype();
891 }
892
1b63e573 893 if ($result && $oldversion < 2007060500) {
894
895 /// Define field usermodified to be added to post
896 $table = new XMLDBTable('post');
897 $field = new XMLDBField('usermodified');
898 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'created');
899
900 /// Launch add field usermodified
901 $result = $result && add_field($table, $field);
902
903 /// Define key usermodified (foreign) to be added to post
904 $table = new XMLDBTable('post');
905 $key = new XMLDBKey('usermodified');
906 $key->setAttributes(XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
907
908 /// Launch add key usermodified
909 $result = $result && add_key($table, $key);
910 }
ac9b0805 911
b3ac6c3e 912/// clenaup and recreate tables for course grade
f13002d5 913 if ($result && $oldversion < 2007063000) {
578075c6 914
b3ac6c3e 915 /// Remove the all grade tables - we need empty db for course grade to work properly
916 $tables = array('grade_categories',
917 'grade_items',
918 'grade_calculations',
919 'grade_grades',
920 'grade_grades_raw',
921 'grade_grades_final',
922 'grade_grades_text',
923 'grade_outcomes',
924 'grade_history');
578075c6 925
b3ac6c3e 926 foreach ($tables as $table) {
927 $table = new XMLDBTable($table);
928 if (table_exists($table)) {
929 drop_table($table);
930 }
578075c6 931 }
578075c6 932
61c33818 933
b3ac6c3e 934 /// Define table grade_items to be created
935 $table = new XMLDBTable('grade_items');
61c33818 936
b3ac6c3e 937 /// Adding fields to table grade_items
197ba19c 938 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
b3ac6c3e 939 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
940 $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
941 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
942 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
943 $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
944 $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
945 $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
946 $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
947 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
948 $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
949 $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '1');
950 $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');
951 $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
952 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
953 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
954 $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
955 $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '1.0');
956 $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
cea2542b 957 $table->addFieldInfo('aggregationcoef', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
b3ac6c3e 958 $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
959 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
960 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
961 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
b3ac6c3e 962 $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
963 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
964 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
61c33818 965
b3ac6c3e 966 /// Adding keys to table grade_items
967 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
968 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
969 $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN, array('categoryid'), 'grade_categories', array('id'));
970 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
971 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id'));
61c33818 972
b3ac6c3e 973 /// Launch create table for grade_items
974 $result = $result && create_table($table);
f92dcad8 975
f92dcad8 976
b3ac6c3e 977 /// Define table grade_categories to be created
978 $table = new XMLDBTable('grade_categories');
f92dcad8 979
b3ac6c3e 980 /// Adding fields to table grade_categories
197ba19c 981 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
b3ac6c3e 982 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
983 $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
984 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
985 $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
986 $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
987 $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
988 $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
989 $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
990 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
991 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
f92dcad8 992
b3ac6c3e 993 /// Adding keys to table grade_categories
994 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
995 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
996 $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id'));
f92dcad8 997
b3ac6c3e 998 /// Launch create table for grade_categories
999 $result = $result && create_table($table);
f92dcad8 1000
f92dcad8 1001
b3ac6c3e 1002 /// Define table grade_grades to be created
1003 $table = new XMLDBTable('grade_grades');
f92dcad8 1004
b3ac6c3e 1005 /// Adding fields to table grade_grades
197ba19c 1006 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
b3ac6c3e 1007 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1008 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1009 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
1010 $table->addFieldInfo('rawgrademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');
1011 $table->addFieldInfo('rawgrademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1012 $table->addFieldInfo('rawscaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1013 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1014 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
1015 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1016 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1017 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1018 $table->addFieldInfo('exported', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
98353ff1 1019 $table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
23207a1a 1020 $table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
b3ac6c3e 1021 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1022 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
f92dcad8 1023
b3ac6c3e 1024 /// Adding keys to table grade_grades
1025 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1026 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
1027 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1028 $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN, array('rawscaleid'), 'scale', array('id'));
1029 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
f92dcad8 1030
b3ac6c3e 1031 /// Launch create table for grade_grades
1032 $result = $result && create_table($table);
f92dcad8 1033
61c33818 1034
b3ac6c3e 1035 /// Define table grade_grades_text to be created
1036 $table = new XMLDBTable('grade_grades_text');
61c33818 1037
b3ac6c3e 1038 /// Adding fields to table grade_grades_text
197ba19c 1039 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
b3ac6c3e 1040 $table->addFieldInfo('gradeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1041 $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1042 $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1043 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1044 $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1045 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1046 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
1047 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
1048
1049 /// Adding keys to table grade_grades_text
1050 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
f13002d5 1051 $table->addKeyInfo('gradeid', XMLDB_KEY_FOREIGN, array('gradeid'), 'grade_grades', array('id'));
b3ac6c3e 1052 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
1053
1054 /// Launch create table for grade_grades_text
1055 $result = $result && create_table($table);
1056
1057
1058 /// Define table grade_outcomes to be created
1059 $table = new XMLDBTable('grade_outcomes');
1060
1061 /// Adding fields to table grade_outcomes
197ba19c 1062 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
b3ac6c3e 1063 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1064 $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1065 $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
1066 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1067 $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1068 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1069 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1070
1071 /// Adding keys to table grade_outcomes
1072 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1073 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1074 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
1075 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
1076
1077 /// Launch create table for grade_outcomes
1078 $result = $result && create_table($table);
1079
61c33818 1080 }
1081
f13002d5 1082 // add foreign key that was forgotten in last commit
1083 if ($result && $oldversion < 2007063001) {
1084
1085 /// Define key gradeid (foreign) to be added to grade_grades_text
1086 $table = new XMLDBTable('grade_grades_text');
1087 $key = new XMLDBKey('gradeid');
1088 $key->setAttributes(XMLDB_KEY_FOREIGN, array('gradeid'), 'grade_grades', array('id'));
1089
1090 /// Launch add key gradeid
1091 add_key($table, $key);
1092 }
4a129c47 1093
aaff71da 1094 if ($result && $oldversion < 2007070602) {
aaff71da 1095
1096 /// drop old grade history table
1097 $table = new XMLDBTable('grade_history');
1098 if (table_exists($table)) {
1099 drop_table($table);
1100 }
1101
1102 /// drop old deleted field
1103 $table = new XMLDBTable('grade_items');
1104 $field = new XMLDBField('deleted');
1105 if (field_exists($table, $field)) {
1106 drop_field($table, $field);
1107 }
1108
1109
1110 /// Define table grade_items_history to be created
1111 $table = new XMLDBTable('grade_items_history');
1112
1113 /// Adding fields to table grade_items_history
197ba19c 1114 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
aaff71da 1115 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1116 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
1117 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1118 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1119 $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1120 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1121 $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1122 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1123 $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);
1124 $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);
1125 $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1126 $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1127 $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1128 $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1129 $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1130 $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '1');
1131 $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');
1132 $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1133 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1134 $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);
1135 $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1136 $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '1.0');
1137 $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
cea2542b 1138 $table->addFieldInfo('aggregationcoef', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
aaff71da 1139 $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1140 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1141 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1142 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1143 $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1144
1145 /// Adding keys to table grade_items_history
1146 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1147 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_items', array('id'));
1148 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1149 $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN, array('categoryid'), 'grade_categories', array('id'));
1150 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
1151 $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id'));
bc7afe29 1152 $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN, array('userlogged'), 'user', array('id'));
aaff71da 1153
1154 /// Adding indexes to table grade_items_history
1155 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
1156
1157 /// Launch create table for grade_items_history
1158 $result = $result && create_table($table);
1159
1160
1161 /// Define table grade_categories_history to be created
1162 $table = new XMLDBTable('grade_categories_history');
1163
1164 /// Adding fields to table grade_categories_history
197ba19c 1165 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
aaff71da 1166 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1167 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
1168 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1169 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1170 $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1171 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1172 $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1173 $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1174 $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1175 $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1176 $table->addFieldInfo('aggregation', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1177 $table->addFieldInfo('keephigh', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1178 $table->addFieldInfo('droplow', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1179
1180 /// Adding keys to table grade_categories_history
1181 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1182 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_categories', array('id'));
1183 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1184 $table->addKeyInfo('parent', XMLDB_KEY_FOREIGN, array('parent'), 'grade_categories', array('id'));
bc7afe29 1185 $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN, array('userlogged'), 'user', array('id'));
aaff71da 1186
1187 /// Adding indexes to table grade_categories_history
1188 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
1189
1190 /// Launch create table for grade_categories_history
1191 $result = $result && create_table($table);
1192
1193
1194 /// Define table grade_grades_history to be created
1195 $table = new XMLDBTable('grade_grades_history');
1196
1197 /// Adding fields to table grade_grades_history
197ba19c 1198 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
aaff71da 1199 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1200 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
1201 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1202 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1203 $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1204 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1205 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1206 $table->addFieldInfo('rawgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
1207 $table->addFieldInfo('rawgrademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');
1208 $table->addFieldInfo('rawgrademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1209 $table->addFieldInfo('rawscaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1210 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1211 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, null, null);
1212 $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1213 $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1214 $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1215 $table->addFieldInfo('exported', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
98353ff1 1216 $table->addFieldInfo('overridden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
23207a1a 1217 $table->addFieldInfo('excluded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
aaff71da 1218
1219 /// Adding keys to table grade_grades_history
1220 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1221 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_grades', array('id'));
1222 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
1223 $table->addKeyInfo('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
1224 $table->addKeyInfo('rawscaleid', XMLDB_KEY_FOREIGN, array('rawscaleid'), 'scale', array('id'));
1225 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
1226 $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN, array('userlogged'), 'user', array('id'));
1227
1228 /// Adding indexes to table grade_grades_history
1229 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
1230
1231 /// Launch create table for grade_grades_history
1232 $result = $result && create_table($table);
1233
1234
1235 /// Define table grade_grades_text_history to be created
1236 $table = new XMLDBTable('grade_grades_text_history');
1237
1238 /// Adding fields to table grade_grades_text_history
197ba19c 1239 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
aaff71da 1240 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1241 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
1242 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1243 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1244 $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1245 $table->addFieldInfo('gradeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1246 $table->addFieldInfo('information', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1247 $table->addFieldInfo('informationformat', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1248 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1249 $table->addFieldInfo('feedbackformat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1250 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1251
1252 /// Adding keys to table grade_grades_text_history
1253 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1254 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_grades_text', array('id'));
1255 $table->addKeyInfo('gradeid', XMLDB_KEY_FOREIGN, array('gradeid'), 'grade_grades', array('id'));
1256 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
1257 $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN, array('userlogged'), 'user', array('id'));
1258
1259 /// Adding indexes to table grade_grades_text_history
1260 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
1261
1262 /// Launch create table for grade_grades_text_history
1263 $result = $result && create_table($table);
1264
1265
1266 /// Define table grade_outcomes_history to be created
1267 $table = new XMLDBTable('grade_outcomes_history');
1268
1269 /// Adding fields to table grade_outcomes_history
197ba19c 1270 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
aaff71da 1271 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1272 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
1273 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1274 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1275 $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1276 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1277 $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1278 $table->addFieldInfo('fullname', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
1279 $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1280 $table->addFieldInfo('usermodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1281
1282 /// Adding keys to table grade_outcomes_history
1283 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1284 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'grade_outcomes', array('id'));
1285 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1286 $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));
1287 $table->addKeyInfo('usermodified', XMLDB_KEY_FOREIGN, array('usermodified'), 'user', array('id'));
1288 $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN, array('userlogged'), 'user', array('id'));
1289
1290 /// Adding indexes to table grade_outcomes_history
1291 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
1292
1293 /// Launch create table for grade_outcomes_history
1294 $result = $result && create_table($table);
1295
1296
1297 /// Define table scale_history to be created
1298 $table = new XMLDBTable('scale_history');
1299
1300 /// Adding fields to table scale_history
1301 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1302 $table->addFieldInfo('action', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');
1303 $table->addFieldInfo('oldid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
1304 $table->addFieldInfo('source', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
1305 $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1306 $table->addFieldInfo('userlogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1307 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1308 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
1309 $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1310 $table->addFieldInfo('scale', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
1311 $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
1312
1313 /// Adding keys to table scale_history
1314 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1315 $table->addKeyInfo('oldid', XMLDB_KEY_FOREIGN, array('oldid'), 'scales', array('id'));
1316 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1317 $table->addKeyInfo('userlogged', XMLDB_KEY_FOREIGN, array('userlogged'), 'user', array('id'));
1318
1319 /// Adding indexes to table scale_history
1320 $table->addIndexInfo('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
1321
1322 /// Launch create table for scale_history
1323 $result = $result && create_table($table);
1324
1325 }
1326
08103c93
ML
1327 if ($result && $oldversion < 2007070603) {
1328 // Small update of guest user to be 100% sure it has the correct mnethostid (MDL-10375)
1329 set_field('user', 'mnethostid', $CFG->mnet_localhost_id, 'username', 'guest');
1330 }
aaff71da 1331
bc7afe29 1332 if ($result && $oldversion < 2007070900) {
1333 // fix loggeduser foreign key
1334 $tables = array('grade_categories_history',
1335 'scale_history',
1336 'grade_items_history',
1337 'grade_grades_history',
1338 'grade_grades_text_history',
1339 'grade_outcomes_history');
1340
1341 foreach ($tables as $table) {
1342 $table = new XMLDBTable($table);
1343 $key = new XMLDBKey('userlogged');
1344 $key->setAttributes(XMLDB_KEY_FOREIGN, array('userlogged'), 'user', array('id'));
1345 add_key($table, $key);
1346 }
1347 }
1348
98353ff1 1349 if ($result && $oldversion < 2007071000) {
98353ff1 1350
1351 /// Define field overridden to be added to grade_grades
1352 $table = new XMLDBTable('grade_grades');
1353 $field = new XMLDBField('overridden');
1354 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'exported');
1355
1356 /// Launch add field overridden
1357 if (!field_exists($table, $field)) {
1358 $result = $result && add_field($table, $field);
1359 }
1360
1361 /// Define field overridden to be added to grade_grades_history
1362 $table = new XMLDBTable('grade_grades_history');
1363 $field = new XMLDBField('overridden');
1364 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'exported');
1365
1366 /// Launch add field overridden
1367 if (!field_exists($table, $field)) {
1368 $result = $result && add_field($table, $field);
1369 }
1370
1371 }
25202581 1372
1373 if ($result && $oldversion < 2007071400) {
25202581 1374 /**
1375 ** mnet application table
1376 **/
1377 $table = new XMLDBTable('mnet_application');
1378 $table->comment = 'Information about applications on remote hosts';
1379 $f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false,
1380 XMLDB_NOTNULL,XMLDB_SEQUENCE, null, null, null);
1381 $f = $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '50', null,
1382 XMLDB_NOTNULL, NULL, null, null, null);
1383 $f = $table->addFieldInfo('display_name', XMLDB_TYPE_CHAR, '50', null,
1384 XMLDB_NOTNULL, NULL, null, null, null);
1385 $f = $table->addFieldInfo('xmlrpc_server_url', XMLDB_TYPE_CHAR, '255', null,
1386 XMLDB_NOTNULL, NULL, null, null, null);
1387 $f = $table->addFieldInfo('sso_land_url', XMLDB_TYPE_CHAR, '255', null,
1388 XMLDB_NOTNULL, NULL, null, null, null);
1389
1390 // PK and indexes
1391 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1392 // Create the table
1393 $result = $result && create_table($table);
1394
3fd7eae4 1395 // Insert initial applications (moodle and mahara)
25202581 1396 $application = new stdClass();
1397 $application->name = 'moodle';
1398 $application->display_name = 'Moodle';
1399 $application->xmlrpc_server_url = '/mnet/xmlrpc/server.php';
1400 $application->sso_land_url = '/auth/mnet/land.php';
1401 if ($result) {
1402 $newid = insert_record('mnet_application', $application, false);
25202581 1403 }
1404
1405 $application = new stdClass();
1406 $application->name = 'mahara';
1407 $application->display_name = 'Mahara';
1408 $application->xmlrpc_server_url = '/api/xmlrpc/server.php';
1409 $application->sso_land_url = '/auth/xmlrpc/land.php';
1410 $result = $result && insert_record('mnet_application', $application, false);
1411
3fd7eae4 1412 // New mnet_host->applicationid field
1413 $table = new XMLDBTable('mnet_host');
1414 $field = new XMLDBField('applicationid');
1415 $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, $newid , 'last_log_id');
25202581 1416
3fd7eae4 1417 $result = $result && add_field($table, $field);
25202581 1418
3fd7eae4 1419 /// Define key applicationid (foreign) to be added to mnet_host
1420 $table = new XMLDBTable('mnet_host');
1421 $key = new XMLDBKey('applicationid');
1422 $key->setAttributes(XMLDB_KEY_FOREIGN, array('applicationid'), 'mnet_application', array('id'));
1423
1424 /// Launch add key applicationid
1425 $result = $result && add_key($table, $key);
1426
1427 }
76a50d17 1428
1429 if ($result && $oldversion < 2007071501) {
1430 /// Drop old grade import tables - there are no data, it is for temporary storage only
1431 $table = new XMLDBTable('grade_import_newitem');
1432 if (table_exists($table)) {
1433 drop_table($table);
1434 }
1435 $table = new XMLDBTable('grade_import_values');
1436 if (table_exists($table)) {
1437 drop_table($table);
1438 }
1439
1440
1441 /// Define table grade_import_newitem to be created
1442 $table = new XMLDBTable('grade_import_newitem');
1443
1444 /// Adding fields to table grade_import_newitem
1445 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1446 $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
1447 $table->addFieldInfo('import_code', XMLDB_TYPE_INTEGER, '12', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1448
1449 /// Adding keys to table grade_import_newitem
1450 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1451
1452 /// Launch create table for grade_import_newitem
1453 $result = $result && create_table($table);
1454
1455 /// Define table grade_import_values to be created
1456 $table = new XMLDBTable('grade_import_values');
1457
1458 /// Adding fields to table grade_import_values
1459 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1460 $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1461 $table->addFieldInfo('newgradeitem', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
1462 $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1463 $table->addFieldInfo('finalgrade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');
1464 $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
1465 $table->addFieldInfo('import_code', XMLDB_TYPE_INTEGER, '12', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1466
1467 /// Adding keys to table grade_import_values
1468 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1469 $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
1470 $table->addKeyInfo('newgradeitem', XMLDB_KEY_FOREIGN, array('newgradeitem'), 'grade_import_newitem', array('id'));
1471
1472 /// Launch create table for grade_import_values
1473 $result = $result && create_table($table);
1474 }
25202581 1475
efe256e4 1476 if ($result && $oldversion < 2007071607) {
1477 require_once($CFG->dirroot . '/question/upgrade.php');
1478 $result = $result && question_remove_rqp_qtype_config_string();
1479 }
1480
cea2542b 1481 if ($result && $oldversion < 2007071700) {
1482
1483 /// Define field aggregationcoef to be added to grade_items
1484 $table = new XMLDBTable('grade_items');
1485 $field = new XMLDBField('aggregationcoef');
1486 $field->setAttributes(XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0', 'plusfactor');
1487
1488 /// Launch add field aggregationcoef
1489
1490 /// Launch add field overridden
1491 if (!field_exists($table, $field)) {
1492 $result = $result && add_field($table, $field);
1493 }
1494
1495 /// Define field aggregationcoef to be added to grade_items
1496 $table = new XMLDBTable('grade_items_history');
1497 $field = new XMLDBField('aggregationcoef');
1498 $field->setAttributes(XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0', 'plusfactor');
1499
1500 /// Launch add field aggregationcoef
1501
1502 /// Launch add field overridden
1503 if (!field_exists($table, $field)) {
1504 $result = $result && add_field($table, $field);
1505 }
1506
1507 }
1508
2717b645 1509 if ($result && $oldversion < 2007071900) {
1510
1511 /// Define table grade_outcomes_courses to be created
1512 $table = new XMLDBTable('grade_outcomes_courses');
1513
1514 /// Adding fields to table grade_outcomes_courses
1515 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
1516 $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1517 $table->addFieldInfo('outcomesid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
1518
1519 /// Adding keys to table grade_outcomes_courses
1520 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
1521 $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1522 $table->addKeyInfo('outcomesid', XMLDB_KEY_FOREIGN, array('outcomesid'), 'grade_outcomes', array('id'));
1523
1524 /// Launch create table for grade_outcomes_courses
1525 $result = $result && create_table($table);
1526 }
1527
23207a1a 1528 if ($result && $oldversion < 2007072100) {
1529 /// Remove obsoleted unit tests tables - they will be recreated automatically
1530 $tables = array('grade_categories',
1531 'scale',
1532 'grade_items',
1533 'grade_calculations',
1534 'grade_grades',
1535 'grade_grades_raw',
1536 'grade_grades_final',
1537 'grade_grades_text',
1538 'grade_outcomes',
1539 'grade_history');
1540
1541 foreach ($tables as $table) {
1542 $table = new XMLDBTable('unittest_'.$table);
1543 if (table_exists($table)) {
1544 drop_table($table);
1545 }
1546 }
1547
1548 /// Define field excluded to be added to grade_grades
1549 $table = new XMLDBTable('grade_grades');
1550 $field = new XMLDBField('excluded');
1551 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'overridden');
1552
1553 /// Launch add field excluded
1554 if (!field_exists($table, $field)) {
1555 $result = $result && add_field($table, $field);
1556 }
1557
1558 /// Define field excluded to be added to grade_grades
1559 $table = new XMLDBTable('grade_grades_history');
1560 $field = new XMLDBField('excluded');
1561 $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'overridden');
1562
1563 /// Launch add field excluded
1564 if (!field_exists($table, $field)) {
1565 $result = $result && add_field($table, $field);
1566 }
1567 }
1568
ac9b0805 1569 return $result;
4e423cbf 1570}
4e423cbf 1571?>