A proper GUI for filters :-)
[moodle.git] / lib / db / mysql.php
blobbf1c5ac962999dbddddad1986f209b068136e7e2
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.
13 // If there's something it cannot do itself, it
14 // will tell you what you need to do.
16 // Versions are defined by /version.php
18 // This file is tailored to MySQL
20 function main_upgrade($oldversion=0) {
22 global $CFG, $THEME, $db;
24 $result = true;
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");
37 if ($oldversion < 2002073100) {
38 execute_sql(" DELETE FROM `modules` WHERE `name` = 'chat' ");
40 if ($oldversion < 2002080200) {
41 execute_sql(" ALTER TABLE `modules` DROP `fullname` ");
42 execute_sql(" ALTER TABLE `modules` DROP `search` ");
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 ");
48 if ($oldversion < 2002082100) {
49 execute_sql(" ALTER TABLE `course` CHANGE `guest` `guest` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL ");
51 if ($oldversion < 2002082101) {
52 execute_sql(" ALTER TABLE `user` ADD `maildisplay` TINYINT(2) UNSIGNED DEFAULT '2' NOT NULL AFTER `mailformat` ");
54 if ($oldversion < 2002090100) {
55 execute_sql(" ALTER TABLE `course_sections` CHANGE `summary` `summary` TEXT NOT NULL ");
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` ");
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` ");
65 if ($oldversion < 2002091000) {
66 execute_sql(" ALTER TABLE `user` CHANGE `personality` `secret` VARCHAR( 15 ) DEFAULT NULL ");
68 if ($oldversion < 2002091400) {
69 execute_sql(" ALTER TABLE `user` ADD `lang` VARCHAR( 3 ) DEFAULT 'en' NOT NULL AFTER `country` ");
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.");
75 if ($oldversion < 2002092000) {
76 execute_sql(" ALTER TABLE `user` CHANGE `lang` `lang` VARCHAR(5) DEFAULT 'en' NOT NULL ");
78 if ($oldversion < 2002092100) {
79 execute_sql(" ALTER TABLE `user` ADD `deleted` TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL AFTER `confirmed` ");
81 if ($oldversion < 2002101001) {
82 execute_sql(" ALTER TABLE `user` ADD `htmleditor` TINYINT(1) UNSIGNED DEFAULT '1' NOT NULL AFTER `maildisplay` ");
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' ");
92 if ($oldversion < 2002102503) {
93 execute_sql(" ALTER TABLE `course` ADD `modinfo` TEXT NOT NULL AFTER `format` ");
94 require_once("$CFG->dirroot/mod/forum/lib.php");
95 require_once("$CFG->dirroot/course/lib.php");
97 if (! $module = get_record("modules", "name", "forum")) {
98 notify("Could not find forum module!!");
99 return false;
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;
114 if (! $sectionid = add_mod_to_section($mod) ) {
115 notify("Could not add the new course module to that section");
116 return false;
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;
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;
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;
142 if (! $sectionid = add_mod_to_section($mod) ) {
143 notify("Could not add the new course module to that section");
144 return false;
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;
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;
160 if (! $sectionid = add_mod_to_section($mod) ) {
161 notify("Could not add the new course module to that section");
162 return false;
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;
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) {
179 $modinfo = serialize(get_array_of_activities($course->id));
181 if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
182 notify("Could not cache module information for course '$course->fullname'!");
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();
199 if ($oldversion < 2002111200) {
200 execute_sql(" ALTER TABLE `course` ADD `showrecent` TINYINT(5) UNSIGNED DEFAULT '1' NOT NULL AFTER `numsections` ");
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) {
209 $modinfo = serialize(get_array_of_activities($course->id));
211 if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
212 notify("Could not cache module information for course '$course->fullname'!");
218 if ($oldversion < 2002112000) {
219 set_config("guestloginbutton", 1);
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 ");
231 if ($oldversion < 2002122700) {
232 if (! record_exists("log_display", "module", "user", "action", "view")) {
233 execute_sql("INSERT INTO {$CFG->prefix}log_display VALUES ('user', 'view', 'user', 'CONCAT(firstname,' ',lastname)') ");
236 if ($oldversion < 2003010101) {
237 delete_records("log_display", "module", "user");
238 $new->module = "user";
239 $new->action = "view";
240 $new->mtable = "user";
241 $new->field = "CONCAT(firstname,\" \",lastname)";
242 insert_record("log_display", $new);
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);
252 $new->action = "enrol";
253 insert_record("log_display", $new);
256 if ($oldversion < 2003012200) {
257 // execute_sql(" ALTER TABLE `log_display` CHANGE `module` `module` VARCHAR( 20 ) NOT NULL ");
258 // Commented out - see below where it's done properly
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';");
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) ");
277 if ($oldversion < 2003041400) {
278 table_column("course_modules", "", "visible", "integer", "1", "unsigned", "1", "not null", "score");
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>";
286 @chmod("$CFG->dataroot/$file", $CFG->directorypermissions);
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));
298 if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
299 notify("Could not cache module information for course '$course->fullname'!");
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();
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);
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;
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 .= ", ";
337 $cerrors .= $item;
338 } else {
339 echo ".";
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;
350 if ($oldversion < 2003042600) {
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) ");
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) ");
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'");
378 if ($oldversion < 2003050400) {
379 table_column("course_sections", "", "visible", "integer", "1", "unsigned", "1", "", "");
382 if ($oldversion < 2003050900) {
383 table_column("modules", "", "visible", "integer", "1", "unsigned", "1", "", "");
386 if ($oldversion < 2003050902) {
387 if (get_records("modules", "name", "pgassignment")) {
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");
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");
396 if ($oldversion < 2003052300) {
397 table_column("user", "", "autosubscribe", "integer", "1", "unsigned", "1", "", "htmleditor");
400 if ($oldversion < 2003072100) {
401 table_column("course", "", "visible", "integer", "1", "unsigned", "1", "", "marker");
404 if ($oldversion < 2003072101) {
405 table_column("course_sections", "sequence", "sequence", "text", "", "", "", "", "");
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");
410 flush();
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) ");
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");
425 if ($oldversion < 2003080400) {
426 table_column("course_categories", "courseorder", "courseorder", "integer", "10", "unsigned");
427 table_column("course", "", "sortorder", "integer", "10", "unsigned", "0", "", "category");
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);
439 if ($oldversion < 2003081001) {
440 table_column("course", "format", "format", "varchar", "10", "", "topics");
443 if ($oldversion < 2003081500) {
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");
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");
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'");
479 if ($oldversion < 2003081503) {
480 table_column("forum", "", "scale", "integer", "10", "unsigned", "0", "", "assessed");
481 get_scales_menu(0); // Just to force the default scale to be created
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");
489 if ($oldversion < 2003081900) {
490 table_column("course_categories", "courseorder", "coursecount", "integer", "10", "unsigned", "0");
493 if ($oldversion < 2003082001) {
494 table_column("course", "", "showgrades", "integer", "2", "unsigned", "1", "", "format");
497 if ($oldversion < 2003082101) {
498 execute_sql(" ALTER TABLE `{$CFG->prefix}course` ADD INDEX category (category) ");
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)') ");
504 if ($oldversion < 2003091400) {
505 table_column("course_modules", "", "indent", "integer", "5", "unsigned", "0", "", "score");
508 if ($oldversion < 2003092900) {
509 table_column("course", "", "maxbytes", "integer", "10", "unsigned", "0", "", "marker");
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");
516 $db->debug = false;
517 $CFG->debug = 0;
518 notify("Calculating access times. Please wait - this may take a long time on big sites...", "green");
519 flush();
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;
532 execute_sql("UPDATE {$CFG->prefix}user_teachers SET timeaccess = '$loginfo->time'
533 WHERE userid = '$user->userid' AND course = '$course->id'", false);
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;
547 execute_sql("UPDATE {$CFG->prefix}user_students
548 SET timeaccess = '$loginfo->time'
549 WHERE userid = '$user->userid' AND course = '$course->id'", false);
555 notify("All courses complete.", "green");
556 $db->debug = true;
559 if ($oldversion < 2003103100) {
560 table_column("course", "", "showreports", "integer", "4", "unsigned", "0", "", "maxbytes");
563 if ($oldversion < 2003121600) {
564 modify_database("", "CREATE TABLE `prefix_groups` (
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.'; ");
577 modify_database("", "CREATE TABLE `prefix_groups_members` (
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'; ");
587 if ($oldversion < 2003121800) {
588 table_column("course", "modinfo", "modinfo", "longtext", "", "", "");
591 if ($oldversion < 2003122600) {
592 table_column("course", "", "groupmode", "integer", "4", "unsigned", "0", "", "showreports");
593 table_column("course", "", "groupmodeforce", "integer", "4", "unsigned", "0", "", "groupmode");
596 if ($oldversion < 2004010900) {
597 table_column("course_modules", "", "groupmode", "integer", "4", "unsigned", "0", "", "visible");
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'; ");
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'; ");
633 if ($oldversion < 2004012900) {
634 table_column("config", "value", "value", "text", "", "", "");
637 if ($oldversion < 2004013101) {
638 table_column("log", "", "cmid", "integer", "10", "unsigned", "0", "", "module");
639 set_config("upgrade", "logs");
642 if ($oldversion < 2004020900) {
643 table_column("course", "", "lang", "varchar", "5", "", "", "", "groupmodeforce");
646 if ($oldversion < 2004020903) {
647 modify_database("", "CREATE TABLE `prefix_cache_text` (
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';");
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;
667 $textfilters = implode(',', $textfilters);
668 if (empty($textfilters)) {
669 $textfilters = 'mod/glossary/dynalink.php';
671 set_config('textfilters', $textfilters);
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';");
687 if ($oldversion < 2004021500) {
688 table_column("groups", "", "hidepicture", "integer", "2", "unsigned", "0", "", "picture");
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);
698 $CFG->textfilters = str_replace("dynalink.php", "filter.php", $CFG->textfilters);
699 set_config("textfilters", $CFG->textfilters);
703 if ($oldversion < 2004022000) {
704 table_column("user", "", "emailstop", "integer", "1", "unsigned", "0", "not null", "email");
707 if ($oldversion < 2004022200) { /// Final renaming I hope. :-)
708 if (!empty($CFG->textfilters)) {
709 $CFG->textfilters = str_replace("/filter.php", "", $CFG->textfilters);
710 $textfilters = explode(',', $CFG->textfilters);
711 foreach ($textfilters as $key => $textfilter) {
712 $textfilters[$key] = trim($textfilter);
714 set_config("textfilters", implode(',',$textfilters));
718 return $result;