Some blank index.html files to prevent browsing
[moodle.git] / lib / db / mysql.php
CommitLineData
31f0900c 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// Versions are defined by /version.php
17//
18// This file is tailored to MySQL
19
e7311a0a 20function main_upgrade($oldversion=0) {
31f0900c 21
4d744a22 22 global $CFG, $THEME, $db;
7beb45d8 23
047d30d1 24 $result = true;
25
31f0900c 26 if ($oldversion == 0) {
27 execute_sql("
28 CREATE TABLE `config` (
29 `id` int(10) unsigned NOT NULL auto_increment,
30 `name` varchar(255) NOT NULL default '',
31 `value` varchar(255) NOT NULL default '',
32 PRIMARY KEY (`id`),
33 UNIQUE KEY `name` (`name`)
34 ) COMMENT='Moodle configuration variables';");
35 notify("Created a new table 'config' to hold configuration data");
36 }
37 if ($oldversion < 2002073100) {
38 execute_sql(" DELETE FROM `modules` WHERE `name` = 'chat' ");
39 }
40 if ($oldversion < 2002080200) {
41 execute_sql(" ALTER TABLE `modules` DROP `fullname` ");
42 execute_sql(" ALTER TABLE `modules` DROP `search` ");
43 }
44 if ($oldversion < 2002080300) {
45 execute_sql(" ALTER TABLE `log_display` CHANGE `table` `mtable` VARCHAR( 20 ) NOT NULL ");
46 execute_sql(" ALTER TABLE `user_teachers` CHANGE `authority` `authority` TINYINT( 3 ) DEFAULT '3' NOT NULL ");
47 }
48 if ($oldversion < 2002082100) {
49 execute_sql(" ALTER TABLE `course` CHANGE `guest` `guest` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL ");
50 }
51 if ($oldversion < 2002082101) {
52 execute_sql(" ALTER TABLE `user` ADD `maildisplay` TINYINT(2) UNSIGNED DEFAULT '2' NOT NULL AFTER `mailformat` ");
53 }
54 if ($oldversion < 2002090100) {
55 execute_sql(" ALTER TABLE `course_sections` CHANGE `summary` `summary` TEXT NOT NULL ");
56 }
57 if ($oldversion < 2002090701) {
58 execute_sql(" ALTER TABLE `user_teachers` CHANGE `authority` `authority` TINYINT( 10 ) DEFAULT '3' NOT NULL ");
59 execute_sql(" ALTER TABLE `user_teachers` ADD `role` VARCHAR(40) NOT NULL AFTER `authority` ");
60 }
61 if ($oldversion < 2002090800) {
62 execute_sql(" ALTER TABLE `course` ADD `teachers` VARCHAR( 100 ) DEFAULT 'Teachers' NOT NULL AFTER `teacher` ");
63 execute_sql(" ALTER TABLE `course` ADD `students` VARCHAR( 100 ) DEFAULT 'Students' NOT NULL AFTER `student` ");
64 }
65 if ($oldversion < 2002091000) {
66 execute_sql(" ALTER TABLE `user` CHANGE `personality` `secret` VARCHAR( 15 ) DEFAULT NULL ");
67 }
68 if ($oldversion < 2002091400) {
69 execute_sql(" ALTER TABLE `user` ADD `lang` VARCHAR( 3 ) DEFAULT 'en' NOT NULL AFTER `country` ");
70 }
71 if ($oldversion < 2002091900) {
72 notify("Most Moodle configuration variables have been moved to the database and can now be edited via the admin page.");
73 notify("Although it is not vital that you do so, you might want to edit <U>config.php</U> and remove all the unused settings (except the database, URL and directory definitions). See <U>config-dist.php</U> for an example of how your new slim config.php should look.");
74 }
75 if ($oldversion < 2002092000) {
76 execute_sql(" ALTER TABLE `user` CHANGE `lang` `lang` VARCHAR(5) DEFAULT 'en' NOT NULL ");
77 }
78 if ($oldversion < 2002092100) {
79 execute_sql(" ALTER TABLE `user` ADD `deleted` TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL AFTER `confirmed` ");
80 }
0095d5cd 81 if ($oldversion < 2002101001) {
82 execute_sql(" ALTER TABLE `user` ADD `htmleditor` TINYINT(1) UNSIGNED DEFAULT '1' NOT NULL AFTER `maildisplay` ");
83 }
2a439ba7 84 if ($oldversion < 2002101701) {
85 execute_sql(" ALTER TABLE `reading` RENAME `resource` "); // Small line with big consequences!
86 execute_sql(" DELETE FROM `log_display` WHERE module = 'reading'");
87 execute_sql(" INSERT INTO log_display VALUES ('resource', 'view', 'resource', 'name') ");
88 execute_sql(" UPDATE log SET module = 'resource' WHERE module = 'reading' ");
89 execute_sql(" UPDATE modules SET name = 'resource' WHERE name = 'reading' ");
90 }
31f0900c 91
7beb45d8 92 if ($oldversion < 2002102503) {
f82c2d42 93 execute_sql(" ALTER TABLE `course` ADD `modinfo` TEXT NOT NULL AFTER `format` ");
7beb45d8 94 require_once("$CFG->dirroot/mod/forum/lib.php");
95 require_once("$CFG->dirroot/course/lib.php");
96
97 if (! $module = get_record("modules", "name", "forum")) {
98 notify("Could not find forum module!!");
99 return false;
100 }
101
102 // First upgrade the site forums
103 if ($site = get_site()) {
104 print_heading("Making News forums editable for main site (moving to section 1)...");
105 if ($news = forum_get_course_forum($site->id, "news")) {
106 $mod->course = $site->id;
107 $mod->module = $module->id;
108 $mod->instance = $news->id;
109 $mod->section = 1;
110 if (! $mod->coursemodule = add_course_module($mod) ) {
111 notify("Could not add a new course module to the site");
112 return false;
113 }
114 if (! $sectionid = add_mod_to_section($mod) ) {
115 notify("Could not add the new course module to that section");
116 return false;
117 }
118 if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
119 notify("Could not update the course module with the correct section");
120 return false;
121 }
122 }
123 }
124
125
126 // Now upgrade the courses.
127 if ($courses = get_records_sql("SELECT * FROM course WHERE category > 0")) {
128 print_heading("Making News and Social forums editable for each course (moving to section 0)...");
129 foreach ($courses as $course) {
130 if ($course->format == "social") { // we won't touch them
131 continue;
132 }
133 if ($news = forum_get_course_forum($course->id, "news")) {
134 $mod->course = $course->id;
135 $mod->module = $module->id;
136 $mod->instance = $news->id;
137 $mod->section = 0;
138 if (! $mod->coursemodule = add_course_module($mod) ) {
139 notify("Could not add a new course module to the course '$course->fullname'");
140 return false;
141 }
142 if (! $sectionid = add_mod_to_section($mod) ) {
143 notify("Could not add the new course module to that section");
144 return false;
145 }
146 if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
147 notify("Could not update the course module with the correct section");
148 return false;
149 }
150 }
151 if ($social = forum_get_course_forum($course->id, "social")) {
152 $mod->course = $course->id;
153 $mod->module = $module->id;
154 $mod->instance = $social->id;
155 $mod->section = 0;
156 if (! $mod->coursemodule = add_course_module($mod) ) {
157 notify("Could not add a new course module to the course '$course->fullname'");
158 return false;
159 }
160 if (! $sectionid = add_mod_to_section($mod) ) {
161 notify("Could not add the new course module to that section");
162 return false;
163 }
164 if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) {
165 notify("Could not update the course module with the correct section");
166 return false;
167 }
168 }
169 }
170 }
171 }
172
d897cae4 173 if ($oldversion < 2002111003) {
174 execute_sql(" ALTER TABLE `course` ADD `modinfo` TEXT NOT NULL AFTER `format` ");
175 if ($courses = get_records_sql("SELECT * FROM course")) {
176 require_once("$CFG->dirroot/course/lib.php");
177 foreach ($courses as $course) {
178
179 $modinfo = serialize(get_array_of_activities($course->id));
180
181 if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
182 notify("Could not cache module information for course '$course->fullname'!");
183 }
184 }
185 }
186 }
187
3635d82f 188 if ($oldversion < 2002111100) {
189 print_simple_box_start("CENTER", "", "#FFCCCC");
190 echo "<FONT SIZE=+1>";
191 echo "<P>Changes have been made to all built-in themes, to add the new popup navigation menu.";
192 echo "<P>If you have customised themes, you will need to edit theme/xxxx/header.html as follows:";
193 echo "<UL><LI>Change anywhere it says <B>$"."button</B> to say <B>$"."menu</B>";
194 echo "<LI>Add <B>$"."button</B> elsewhere (eg at the end of the navigation bar)</UL>";
195 echo "<P>See the standard themes for examples, eg: theme/standard/header.html";
196 print_simple_box_end();
197 }
198
13beeacb 199 if ($oldversion < 2002111200) {
200 execute_sql(" ALTER TABLE `course` ADD `showrecent` TINYINT(5) UNSIGNED DEFAULT '1' NOT NULL AFTER `numsections` ");
201 }
202
f8ef7d66 203 if ($oldversion < 2002111400) {
204 // Rebuild all course caches, because some may not be done in new installs (eg site page)
205 if ($courses = get_records_sql("SELECT * FROM course")) {
206 require_once("$CFG->dirroot/course/lib.php");
207 foreach ($courses as $course) {
208
209 $modinfo = serialize(get_array_of_activities($course->id));
210
211 if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
212 notify("Could not cache module information for course '$course->fullname'!");
213 }
214 }
215 }
216 }
217
277d2d9f 218 if ($oldversion < 2002112000) {
219 set_config("guestloginbutton", 1);
220 }
221
ebc3bd2b 222 if ($oldversion < 2002122300) {
223 execute_sql("ALTER TABLE `log` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
224 execute_sql("ALTER TABLE `user_admins` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
225 execute_sql("ALTER TABLE `user_students` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
226 execute_sql("ALTER TABLE `user_teachers` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
227 execute_sql("ALTER TABLE `user_students` CHANGE `start` `timestart` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
228 execute_sql("ALTER TABLE `user_students` CHANGE `end` `timeend` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
229 }
230
9d378732 231 if ($oldversion < 2002122700) {
05a6c03e 232 if (! record_exists("log_display", "module", "user", "action", "view")) {
a3eea09c 233 execute_sql("INSERT INTO {$CFG->prefix}log_display VALUES ('user', 'view', 'user', 'CONCAT(firstname,' ',lastname)') ");
234 }
235 }
db70b54b 236 if ($oldversion < 2003010101) {
14e4a496 237 delete_records("log_display", "module", "user");
238 $new->module = "user";
239 $new->action = "view";
240 $new->mtable = "user";
db70b54b 241 $new->field = "CONCAT(firstname,\" \",lastname)";
14e4a496 242 insert_record("log_display", $new);
243
244 delete_records("log_display", "module", "course");
245 $new->module = "course";
246 $new->action = "view";
247 $new->mtable = "course";
248 $new->field = "fullname";
249 insert_record("log_display", $new);
250 $new->action = "update";
251 insert_record("log_display", $new);
db70b54b 252 $new->action = "enrol";
253 insert_record("log_display", $new);
14e4a496 254 }
d897cae4 255
811c88b3 256 if ($oldversion < 2003012200) {
718ad19f 257 // execute_sql(" ALTER TABLE `log_display` CHANGE `module` `module` VARCHAR( 20 ) NOT NULL ");
258 // Commented out - see below where it's done properly
811c88b3 259 }
260
2fdb54b8 261 if ($oldversion < 2003032500) {
262 modify_database("", "CREATE TABLE `prefix_user_coursecreators` (
263 `id` int(10) unsigned NOT NULL auto_increment,
264 `userid` int(10) unsigned NOT NULL default '0',
265 PRIMARY KEY (`id`),
266 UNIQUE KEY `id` (`id`)
267 ) TYPE=MyISAM COMMENT='One record per course creator';");
1924074c 268 }
264d4e0b 269 if ($oldversion < 2003032602) {
270 // Redoing it because of no prefix last time
271 execute_sql(" ALTER TABLE `{$CFG->prefix}log_display` CHANGE `module` `module` VARCHAR( 20 ) NOT NULL ");
272 // Add some indexes for speed
273 execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX(course) ");
274 execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX(userid) ");
275 }
1acfbce5 276
277 if ($oldversion < 2003041400) {
278 table_column("course_modules", "", "visible", "integer", "1", "unsigned", "1", "not null", "score");
279 }
1924074c 280
718ad19f 281 if ($oldversion < 2003042104) { // Try to update permissions of all files
282 if ($files = get_directory_list($CFG->dataroot)) {
283 echo "Attempting to update permissions for all files... ignore any errors.";
284 foreach ($files as $file) {
285 echo "$CFG->dataroot/$file<br>";
b369ff55 286 @chmod("$CFG->dataroot/$file", $CFG->directorypermissions);
718ad19f 287 }
288 }
289 }
290
13df5aee 291 if ($oldversion < 2003042400) {
292 // Rebuild all course caches, because of changes to do with visible variable
293 if ($courses = get_records_sql("SELECT * FROM {$CFG->prefix}course")) {
294 require_once("$CFG->dirroot/course/lib.php");
295 foreach ($courses as $course) {
296 $modinfo = serialize(get_array_of_activities($course->id));
297
298 if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
299 notify("Could not cache module information for course '$course->fullname'!");
300 }
301 }
302 }
303 }
304
047d30d1 305 if ($oldversion < 2003042500) {
306 // Convert all usernames to lowercase.
307 $users = get_records_sql("SELECT id, username FROM {$CFG->prefix}user");
308 $cerrors = "";
309 $rarray = array();
310
311 foreach ($users as $user) { // Check for possible conflicts
312 $lcname = trim(moodle_strtolower($user->username));
313 if (in_array($lcname, $rarray)) {
314 $cerrors .= $user->id."->".$lcname.'<br/>' ;
315 } else {
316 array_push($rarray,$lcname);
317 }
318 }
319
320 if ($cerrors != '') {
321 notify("Error: Cannot convert usernames to lowercase.
322 Following usernames would overlap (id->username):<br/> $cerrors .
323 Please resolve overlapping errors.");
324 $result = false;
325 }
326
327 $cerrors = "";
328 echo "Checking userdatabase:<br>";
329 foreach ($users as $user) {
330 $lcname = trim(moodle_strtolower($user->username));
331 if ($lcname != $user->username) {
332 $convert = set_field("user" , "username" , $lcname, "id", $user->id);
333 if (!$convert) {
334 if ($cerrors){
335 $cerrors .= ", ";
336 }
337 $cerrors .= $item;
338 } else {
339 echo ".";
340 }
341 }
342 }
343 if ($cerrors != '') {
344 notify("There were errors when converting following usernames to lowercase.
345 '$cerrors' . Sorry, but you will need to fix your database by hand.");
346 $result = false;
347 }
348 }
349
1ba39602 350 if ($oldversion < 2003042600) {
f9ce68ee 351 /// Some more indexes - we need all the help we can get on the logs
352 //execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX(module) ");
353 //execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX(action) ");
354 }
355
356 if ($oldversion < 2003042700) {
357 /// Changing to multiple indexes
358 execute_sql(" ALTER TABLE `{$CFG->prefix}log` DROP INDEX module ", false);
359 execute_sql(" ALTER TABLE `{$CFG->prefix}log` DROP INDEX action ", false);
360 execute_sql(" ALTER TABLE `{$CFG->prefix}log` DROP INDEX course ", false);
361 execute_sql(" ALTER TABLE `{$CFG->prefix}log` DROP INDEX userid ", false);
362 execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX coursemoduleaction (course,module,action) ");
363 execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX courseuserid (course,userid) ");
6459f225 364 }
365
b86fc0e2 366 if ($oldversion < 2003042801) {
367 execute_sql("CREATE TABLE `{$CFG->prefix}course_display` (
368 `id` int(10) unsigned NOT NULL auto_increment,
369 `course` int(10) unsigned NOT NULL default '0',
370 `userid` int(10) unsigned NOT NULL default '0',
371 `display` int(10) NOT NULL default '0',
372 PRIMARY KEY (`id`),
373 UNIQUE KEY `id` (`id`),
374 KEY `courseuserid` (course,userid)
375 ) TYPE=MyISAM COMMENT='Stores info about how to display the course'");
376 }
377
7d99d695 378 if ($oldversion < 2003050400) {
379 table_column("course_sections", "", "visible", "integer", "1", "unsigned", "1", "", "");
380 }
381
7e6b0b3b 382 if ($oldversion < 2003050900) {
383 table_column("modules", "", "visible", "integer", "1", "unsigned", "1", "", "");
384 }
385
5867bfb5 386 if ($oldversion < 2003050902) {
387 if (get_records("modules", "name", "pgassignment")) {
7adf6787 388 print_simple_box("Note: the pgassignment module has been removed (it will be replaced later by the workshop module). Go to the new 'Manage Modules' page and DELETE IT from your system", "center", "50%", "$THEME->cellheading", "20", "noticebox");
5867bfb5 389 }
390 }
391
7adf6787 392 if ($oldversion < 2003051600) {
393 print_simple_box("Thanks for upgrading!<p>There are many changes since the last release. Please read the release notes carefully. If you are using CUSTOM themes you will need to edit them. You will also need to check your site's config.php file.", "center", "50%", "$THEME->cellheading", "20", "noticebox");
394 }
395
7f2a3e67 396 if ($oldversion < 2003052300) {
397 table_column("user", "", "autosubscribe", "integer", "1", "unsigned", "1", "", "htmleditor");
398 }
399
a6d82c3f 400 if ($oldversion < 2003072100) {
401 table_column("course", "", "visible", "integer", "1", "unsigned", "1", "", "marker");
402 }
403
dd0bd508 404 if ($oldversion < 2003072101) {
405 table_column("course_sections", "sequence", "sequence", "text", "", "", "", "", "");
406 }
407
a8fa25d1 408 if ($oldversion < 2003072800) {
409 print_simple_box("The following database index improves performance, but can be quite large - if you are upgrading and you have problems with a limited quota you may want to delete this index later from the '{$CFG->prefix}log' table in your database", "center", "50%", "$THEME->cellheading", "20", "noticebox");
1dbb6e50 410 flush();
a8fa25d1 411 execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX timecoursemoduleaction (time,course,module,action) ");
412 execute_sql(" ALTER TABLE `{$CFG->prefix}user_students` ADD INDEX courseuserid (course,userid) ");
413 execute_sql(" ALTER TABLE `{$CFG->prefix}user_teachers` ADD INDEX courseuserid (course,userid) ");
414 }
415
c2cb4545 416 if ($oldversion < 2003072803) {
417 table_column("course_categories", "", "description", "text", "", "", "");
418 table_column("course_categories", "", "parent", "integer", "10", "unsigned");
419 table_column("course_categories", "", "sortorder", "integer", "10", "unsigned");
420 table_column("course_categories", "", "courseorder", "text", "", "", "");
421 table_column("course_categories", "", "visible", "integer", "1", "unsigned", "1");
422 table_column("course_categories", "", "timemodified", "integer", "10", "unsigned");
423 }
424
d2b6ba70 425 if ($oldversion < 2003080400) {
426 table_column("course_categories", "courseorder", "courseorder", "integer", "10", "unsigned");
427 table_column("course", "", "sortorder", "integer", "10", "unsigned", "0", "", "category");
428 }
429
430 if ($oldversion < 2003080700) {
431 notify("Cleaning up categories and course ordering...");
432 if ($categories = get_categories()) {
433 foreach ($categories as $category) {
434 fix_course_sortorder($category->id);
435 }
436 }
437 }
438
50b5487c 439 if ($oldversion < 2003081001) {
440 table_column("course", "format", "format", "varchar", "10", "", "topics");
441 }
442
02ebf404 443 if ($oldversion < 2003081500) {
5fcd1b52 444// print_simple_box("Some important changes have been made to how course creators work. Formerly, they could create new courses and assign teachers, and teachers could edit courses. Now, ordinary teachers can no longer edit courses - they <b>need to be a teacher of a course AND a course creator</b>. A new site-wide configuration variable allows you to choose whether to allow course creators to create new courses as well (by default this is off). <p>The following update will automatically convert all your existing teachers into course creators, to maintain backward compatibility. Make sure you look at your upgraded site carefully and understand these new changes.", "center", "50%", "$THEME->cellheading", "20", "noticebox");
02ebf404 445
5fcd1b52 446// $count = 0;
447// $errorcount = 0;
448// if ($teachers = get_records("user_teachers")) {
449// foreach ($teachers as $teacher) {
450// if (! record_exists("user_coursecreators", "userid", $teacher->userid)) {
451// $creator = NULL;
452// $creator->userid = $teacher->userid;
453// if (!insert_record("user_coursecreators", $creator)) {
454// $errorcount++;
455// } else {
456// $count++;
457// }
458// }
459// }
460// }
461// print_simple_box("$count teachers were upgraded to course creators (with $errorcount errors)", "center", "50%", "$THEME->cellheading", "20", "noticebox");
02ebf404 462
463 }
464
37eef3ed 465 if ($oldversion < 2003081501) {
466 execute_sql(" CREATE TABLE `{$CFG->prefix}scale` (
467 `id` int(10) unsigned NOT NULL auto_increment,
468 `courseid` int(10) unsigned NOT NULL default '0',
469 `userid` int(10) unsigned NOT NULL default '0',
470 `name` varchar(255) NOT NULL default '',
471 `scale` text NOT NULL,
472 `description` text NOT NULL,
473 `timemodified` int(10) unsigned NOT NULL default '0',
474 PRIMARY KEY (id)
475 ) TYPE=MyISAM COMMENT='Defines grading scales'");
37eef3ed 476
6f4f04df 477 }
11402bbd 478
479 if ($oldversion < 2003081503) {
6f4f04df 480 table_column("forum", "", "scale", "integer", "10", "unsigned", "0", "", "assessed");
11402bbd 481 get_scales_menu(0); // Just to force the default scale to be created
482 }
483
73047f2f 484 if ($oldversion < 2003081600) {
485 table_column("user_teachers", "", "editall", "integer", "1", "unsigned", "1", "", "role");
486 table_column("user_teachers", "", "timemodified", "integer", "10", "unsigned", "0", "", "editall");
487 }
11402bbd 488
9936fe81 489 if ($oldversion < 2003081900) {
490 table_column("course_categories", "courseorder", "coursecount", "integer", "10", "unsigned", "0");
491 }
492
fff79722 493 if ($oldversion < 2003082001) {
494 table_column("course", "", "showgrades", "integer", "2", "unsigned", "1", "", "format");
495 }
496
3052e775 497 if ($oldversion < 2003082101) {
498 execute_sql(" ALTER TABLE `{$CFG->prefix}course` ADD INDEX category (category) ");
499 }
d0117715 500 if ($oldversion < 2003082702) {
501 execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'user report', 'user', 'CONCAT(firstname,\" \",lastname)') ");
502 }
3052e775 503
aac94fd0 504 if ($oldversion < 2003091400) {
505 table_column("course_modules", "", "indent", "integer", "5", "unsigned", "0", "", "score");
506 }
507
4909e176 508 if ($oldversion < 2003092900) {
509 table_column("course", "", "maxbytes", "integer", "10", "unsigned", "0", "", "marker");
510 }
511
4d744a22 512 if ($oldversion < 2003102700) {
513 table_column("user_students", "", "timeaccess", "integer", "10", "unsigned", "0", "", "time");
514 table_column("user_teachers", "", "timeaccess", "integer", "10", "unsigned", "0", "", "timemodified");
515
4d744a22 516 $db->debug = false;
29b25b04 517 $CFG->debug = 0;
518 notify("Calculating access times. Please wait - this may take a long time on big sites...", "green");
519 flush();
520
521 if ($courses = get_records_select("course", "category > 0")) {
522 foreach ($courses as $course) {
523 notify("Processing $course->fullname ...", "green");
524 flush();
525 if ($users = get_records_select("user_teachers", "course = '$course->id'",
526 "id", "id, userid, timeaccess")) {
527 foreach ($users as $user) {
528 $loginfo = get_record_sql("SELECT id, time FROM {$CFG->prefix}log WHERE course = '$course->id' and userid = '$user->userid' ORDER by time DESC");
529 if (empty($loginfo->time)) {
530 $loginfo->time = 0;
531 }
532 execute_sql("UPDATE {$CFG->prefix}user_teachers SET timeaccess = '$loginfo->time'
533 WHERE userid = '$user->userid' AND course = '$course->id'", false);
534
535 }
536 }
537
538 if ($users = get_records_select("user_students", "course = '$course->id'",
539 "id", "id, userid, timeaccess")) {
540 foreach ($users as $user) {
541 $loginfo = get_record_sql("SELECT id, time FROM {$CFG->prefix}log
542 WHERE course = '$course->id' and userid = '$user->userid'
543 ORDER by time DESC");
544 if (empty($loginfo->time)) {
545 $loginfo->time = 0;
546 }
547 execute_sql("UPDATE {$CFG->prefix}user_students
548 SET timeaccess = '$loginfo->time'
549 WHERE userid = '$user->userid' AND course = '$course->id'", false);
550
551 }
552 }
553 }
4d744a22 554 }
29b25b04 555 notify("All courses complete.", "green");
4d744a22 556 $db->debug = true;
557 }
558
3f125001 559 if ($oldversion < 2003103100) {
560 table_column("course", "", "showreports", "integer", "4", "unsigned", "0", "", "maxbytes");
561 }
562
f374fb10 563 if ($oldversion < 2003121600) {
0da33e07 564 modify_database("", "CREATE TABLE `prefix_groups` (
f374fb10 565 `id` int(10) unsigned NOT NULL auto_increment,
566 `courseid` int(10) unsigned NOT NULL default '0',
567 `name` varchar(254) NOT NULL default '',
568 `description` text NOT NULL,
569 `lang` varchar(10) NOT NULL default 'en',
570 `picture` int(10) unsigned NOT NULL default '0',
571 `timecreated` int(10) unsigned NOT NULL default '0',
572 `timemodified` int(10) unsigned NOT NULL default '0',
573 PRIMARY KEY (`id`),
574 KEY `courseid` (`courseid`)
575 ) TYPE=MyISAM COMMENT='Each record is a group in a course.'; ");
576
0da33e07 577 modify_database("", "CREATE TABLE `prefix_groups_members` (
f374fb10 578 `id` int(10) unsigned NOT NULL auto_increment,
579 `groupid` int(10) unsigned NOT NULL default '0',
580 `userid` int(10) unsigned NOT NULL default '0',
581 `timeadded` int(10) unsigned NOT NULL default '0',
582 PRIMARY KEY (`id`),
583 KEY `groupid` (`groupid`)
584 ) TYPE=MyISAM COMMENT='Lists memberships of users in groups'; ");
585 }
586
587 if ($oldversion < 2003121800) {
588 table_column("course", "modinfo", "modinfo", "longtext", "", "", "");
589 }
590
591 if ($oldversion < 2003122600) {
592 table_column("course", "", "groupmode", "integer", "4", "unsigned", "0", "", "showreports");
593 table_column("course", "", "groupmodeforce", "integer", "4", "unsigned", "0", "", "groupmode");
594 }
595
ddc7afad 596 if ($oldversion < 2004010900) {
597 table_column("course_modules", "", "groupmode", "integer", "4", "unsigned", "0", "", "visible");
598 }
599
5fba04fb 600 if ($oldversion < 2004011700) {
601 modify_database("", "CREATE TABLE `prefix_event` (
602 `id` int(10) unsigned NOT NULL auto_increment,
603 `name` varchar(255) NOT NULL default '',
604 `description` text NOT NULL,
605 `courseid` int(10) unsigned NOT NULL default '0',
606 `groupid` int(10) unsigned NOT NULL default '0',
607 `userid` int(10) unsigned NOT NULL default '0',
608 `modulename` varchar(20) NOT NULL default '',
609 `instance` int(10) unsigned NOT NULL default '0',
610 `eventtype` varchar(20) NOT NULL default '',
611 `timestart` int(10) unsigned NOT NULL default '0',
612 `timeduration` int(10) unsigned NOT NULL default '0',
613 `timemodified` int(10) unsigned NOT NULL default '0',
614 PRIMARY KEY (`id`),
615 UNIQUE KEY `id` (`id`),
616 KEY `courseid` (`courseid`),
617 KEY `userid` (`userid`)
618 ) TYPE=MyISAM COMMENT='For everything with a time associated to it'; ");
619 }
620
70812e39 621 if ($oldversion < 2004012800) {
622 modify_database("", "CREATE TABLE `prefix_user_preferences` (
623 `id` int(10) unsigned NOT NULL auto_increment,
624 `userid` int(10) unsigned NOT NULL default '0',
625 `name` varchar(50) NOT NULL default '',
626 `value` varchar(255) NOT NULL default '',
627 PRIMARY KEY (`id`),
628 UNIQUE KEY `id` (`id`),
629 KEY `useridname` (userid,name)
630 ) TYPE=MyISAM COMMENT='Allows modules to store arbitrary user preferences'; ");
631 }
632
ba39fa10 633 if ($oldversion < 2004012900) {
634 table_column("config", "value", "value", "text", "", "", "");
635 }
70812e39 636
69d79bc3 637 if ($oldversion < 2004013101) {
638 table_column("log", "", "cmid", "integer", "10", "unsigned", "0", "", "module");
4da1a0a1 639 set_config("upgrade", "logs");
69d79bc3 640 }
641
b3153e4b 642 if ($oldversion < 2004020900) {
643 table_column("course", "", "lang", "varchar", "5", "", "", "", "groupmodeforce");
644 }
645
45121ffb 646 if ($oldversion < 2004020903) {
647 modify_database("", "CREATE TABLE `prefix_cache_text` (
d363047e 648 `id` int(10) unsigned NOT NULL auto_increment,
649 `md5key` varchar(32) NOT NULL default '',
650 `formattedtext` longtext NOT NULL,
651 `timemodified` int(10) unsigned NOT NULL default '0',
652 PRIMARY KEY (`id`),
653 KEY `md5key` (`md5key`)
654 ) TYPE=MyISAM COMMENT='For storing temporary copies of processed texts';");
655 }
656
d523d2ea 657 if ($oldversion < 2004021000) {
658 $textfilters = array();
659 for ($i=1; $i<=10; $i++) {
660 $variable = "textfilter$i";
661 if (!empty($CFG->$variable)) { /// No more filters
662 if (is_readable("$CFG->dirroot/".$CFG->$variable)) {
663 $textfilters[] = $CFG->$variable;
664 }
665 }
666 }
667 $textfilters = implode(',', $textfilters);
668 if (empty($textfilters)) {
669 $textfilters = 'mod/glossary/dynalink.php';
670 }
671 set_config('textfilters', $textfilters);
672 }
673
f1d604cb 674 if ($oldversion < 2004021201) {
675 modify_database("", "CREATE TABLE `prefix_cache_filters` (
676 `id` int(10) unsigned NOT NULL auto_increment,
677 `filter` varchar(32) NOT NULL default '',
678 `version` int(10) unsigned NOT NULL default '0',
679 `md5key` varchar(32) NOT NULL default '',
680 `rawtext` text NOT NULL,
681 `timemodified` int(10) unsigned NOT NULL default '0',
682 PRIMARY KEY (`id`),
683 KEY `filtermd5key` (filter,md5key)
684 ) TYPE=MyISAM COMMENT='For keeping information about cached data';");
685 }
686
3c0561cf 687 if ($oldversion < 2004021500) {
688 table_column("groups", "", "hidepicture", "integer", "2", "unsigned", "0", "", "picture");
689 }
9e353ce7 690
691 if ($oldversion < 2004021700) {
692 if (!empty($CFG->textfilters)) {
693 $CFG->textfilters = str_replace("tex_filter.php", "filter.php", $CFG->textfilters);
694 $CFG->textfilters = str_replace("multilang.php", "filter.php", $CFG->textfilters);
695 $CFG->textfilters = str_replace("censor.php", "filter.php", $CFG->textfilters);
696 $CFG->textfilters = str_replace("mediaplugin.php", "filter.php", $CFG->textfilters);
697 $CFG->textfilters = str_replace("algebra_filter.php", "filter.php", $CFG->textfilters);
828aeff2 698 $CFG->textfilters = str_replace("dynalink.php", "filter.php", $CFG->textfilters);
9e353ce7 699 set_config("textfilters", $CFG->textfilters);
700 }
701 }
d523d2ea 702
8199e3f0 703 if ($oldversion < 2004022000) {
704 table_column("user", "", "emailstop", "integer", "1", "unsigned", "0", "not null", "email");
705 }
706
828aeff2 707 if ($oldversion < 2004022200) { /// Final renaming I hope. :-)
708 if (!empty($CFG->textfilters)) {
709 $CFG->textfilters = str_replace("/filter.php", "", $CFG->textfilters);
a4dda51f 710 $CFG->textfilters = str_replace("mod/glossary/dynalink.php", "mod/glossary", $CFG->textfilters);
828aeff2 711 $textfilters = explode(',', $CFG->textfilters);
712 foreach ($textfilters as $key => $textfilter) {
713 $textfilters[$key] = trim($textfilter);
714 }
715 set_config("textfilters", implode(',',$textfilters));
716 }
717 }
718
b4443d8f 719 if ($oldversion < 2004030702) { /// Because of the renaming of Czech language pack
4bf58667 720 execute_sql("UPDATE {$CFG->prefix}user SET lang = 'cs' WHERE lang = 'cz'");
721 execute_sql("UPDATE {$CFG->prefix}course SET lang = 'cs' WHERE lang = 'cz'");
7277e306 722 }
723
047d30d1 724 return $result;
725
31f0900c 726}
727
728?>