3 // This file keeps track of upgrades to Moodle.
5 // Sometimes, changes between versions involve
6 // alterations to database structures and other
7 // major things that may break installations.
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;
26 if ($oldversion == 0) {
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 '',
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!!");
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
;
110 if (! $mod->coursemodule
= add_course_module($mod) ) {
111 notify("Could not add a new course module to the site");
114 if (! $sectionid = add_mod_to_section($mod) ) {
115 notify("Could not add the new course module to that section");
118 if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule
)) {
119 notify("Could not update the course module with the correct section");
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
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
;
138 if (! $mod->coursemodule
= add_course_module($mod) ) {
139 notify("Could not add a new course module to the course '$course->fullname'");
142 if (! $sectionid = add_mod_to_section($mod) ) {
143 notify("Could not add the new course module to that section");
146 if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule
)) {
147 notify("Could not update the course module with the correct section");
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
;
156 if (! $mod->coursemodule
= add_course_module($mod) ) {
157 notify("Could not add a new course module to the course '$course->fullname'");
160 if (! $sectionid = add_mod_to_section($mod) ) {
161 notify("Could not add the new course module to that section");
164 if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule
)) {
165 notify("Could not update the course module with the correct section");
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',
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");
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/>' ;
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.");
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
);
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.");
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',
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");
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 fix_course_sortorder();
435 if ($oldversion < 2003081001) {
436 table_column("course", "format", "format", "varchar", "10", "", "topics");
439 if ($oldversion < 2003081500) {
440 // 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");
444 // if ($teachers = get_records("user_teachers")) {
445 // foreach ($teachers as $teacher) {
446 // if (! record_exists("user_coursecreators", "userid", $teacher->userid)) {
448 // $creator->userid = $teacher->userid;
449 // if (!insert_record("user_coursecreators", $creator)) {
457 // print_simple_box("$count teachers were upgraded to course creators (with $errorcount errors)", "center", "50%", "$THEME->cellheading", "20", "noticebox");
461 if ($oldversion < 2003081501) {
462 execute_sql(" CREATE TABLE `{$CFG->prefix}scale` (
463 `id` int(10) unsigned NOT NULL auto_increment,
464 `courseid` int(10) unsigned NOT NULL default '0',
465 `userid` int(10) unsigned NOT NULL default '0',
466 `name` varchar(255) NOT NULL default '',
467 `scale` text NOT NULL,
468 `description` text NOT NULL,
469 `timemodified` int(10) unsigned NOT NULL default '0',
471 ) TYPE=MyISAM COMMENT='Defines grading scales'");
475 if ($oldversion < 2003081503) {
476 table_column("forum", "", "scale", "integer", "10", "unsigned", "0", "", "assessed");
477 get_scales_menu(0); // Just to force the default scale to be created
480 if ($oldversion < 2003081600) {
481 table_column("user_teachers", "", "editall", "integer", "1", "unsigned", "1", "", "role");
482 table_column("user_teachers", "", "timemodified", "integer", "10", "unsigned", "0", "", "editall");
485 if ($oldversion < 2003081900) {
486 table_column("course_categories", "courseorder", "coursecount", "integer", "10", "unsigned", "0");
489 if ($oldversion < 2003082001) {
490 table_column("course", "", "showgrades", "integer", "2", "unsigned", "1", "", "format");
493 if ($oldversion < 2003082101) {
494 execute_sql(" ALTER TABLE `{$CFG->prefix}course` ADD INDEX category (category) ");
496 if ($oldversion < 2003082702) {
497 execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('course', 'user report', 'user', 'CONCAT(firstname,\" \",lastname)') ");
500 if ($oldversion < 2003091400) {
501 table_column("course_modules", "", "indent", "integer", "5", "unsigned", "0", "", "score");
504 if ($oldversion < 2003092900) {
505 table_column("course", "", "maxbytes", "integer", "10", "unsigned", "0", "", "marker");
508 if ($oldversion < 2003102700) {
509 table_column("user_students", "", "timeaccess", "integer", "10", "unsigned", "0", "", "time");
510 table_column("user_teachers", "", "timeaccess", "integer", "10", "unsigned", "0", "", "timemodified");
514 notify("Calculating access times. Please wait - this may take a long time on big sites...", "green");
517 if ($courses = get_records_select("course", "category > 0")) {
518 foreach ($courses as $course) {
519 notify("Processing $course->fullname ...", "green");
521 if ($users = get_records_select("user_teachers", "course = '$course->id'",
522 "id", "id, userid, timeaccess")) {
523 foreach ($users as $user) {
524 $loginfo = get_record_sql("SELECT id, time FROM {$CFG->prefix}log WHERE course = '$course->id' and userid = '$user->userid' ORDER by time DESC");
525 if (empty($loginfo->time
)) {
528 execute_sql("UPDATE {$CFG->prefix}user_teachers SET timeaccess = '$loginfo->time'
529 WHERE userid = '$user->userid' AND course = '$course->id'", false);
534 if ($users = get_records_select("user_students", "course = '$course->id'",
535 "id", "id, userid, timeaccess")) {
536 foreach ($users as $user) {
537 $loginfo = get_record_sql("SELECT id, time FROM {$CFG->prefix}log
538 WHERE course = '$course->id' and userid = '$user->userid'
539 ORDER by time DESC");
540 if (empty($loginfo->time
)) {
543 execute_sql("UPDATE {$CFG->prefix}user_students
544 SET timeaccess = '$loginfo->time'
545 WHERE userid = '$user->userid' AND course = '$course->id'", false);
551 notify("All courses complete.", "green");
555 if ($oldversion < 2003103100) {
556 table_column("course", "", "showreports", "integer", "4", "unsigned", "0", "", "maxbytes");
559 if ($oldversion < 2003121600) {
560 modify_database("", "CREATE TABLE `prefix_groups` (
561 `id` int(10) unsigned NOT NULL auto_increment,
562 `courseid` int(10) unsigned NOT NULL default '0',
563 `name` varchar(254) NOT NULL default '',
564 `description` text NOT NULL,
565 `lang` varchar(10) NOT NULL default 'en',
566 `picture` int(10) unsigned NOT NULL default '0',
567 `timecreated` int(10) unsigned NOT NULL default '0',
568 `timemodified` int(10) unsigned NOT NULL default '0',
570 KEY `courseid` (`courseid`)
571 ) TYPE=MyISAM COMMENT='Each record is a group in a course.'; ");
573 modify_database("", "CREATE TABLE `prefix_groups_members` (
574 `id` int(10) unsigned NOT NULL auto_increment,
575 `groupid` int(10) unsigned NOT NULL default '0',
576 `userid` int(10) unsigned NOT NULL default '0',
577 `timeadded` int(10) unsigned NOT NULL default '0',
579 KEY `groupid` (`groupid`)
580 ) TYPE=MyISAM COMMENT='Lists memberships of users in groups'; ");
583 if ($oldversion < 2003121800) {
584 table_column("course", "modinfo", "modinfo", "longtext", "", "", "");
587 if ($oldversion < 2003122600) {
588 table_column("course", "", "groupmode", "integer", "4", "unsigned", "0", "", "showreports");
589 table_column("course", "", "groupmodeforce", "integer", "4", "unsigned", "0", "", "groupmode");
592 if ($oldversion < 2004010900) {
593 table_column("course_modules", "", "groupmode", "integer", "4", "unsigned", "0", "", "visible");
596 if ($oldversion < 2004011700) {
597 modify_database("", "CREATE TABLE `prefix_event` (
598 `id` int(10) unsigned NOT NULL auto_increment,
599 `name` varchar(255) NOT NULL default '',
600 `description` text NOT NULL,
601 `courseid` int(10) unsigned NOT NULL default '0',
602 `groupid` int(10) unsigned NOT NULL default '0',
603 `userid` int(10) unsigned NOT NULL default '0',
604 `modulename` varchar(20) NOT NULL default '',
605 `instance` int(10) unsigned NOT NULL default '0',
606 `eventtype` varchar(20) NOT NULL default '',
607 `timestart` int(10) unsigned NOT NULL default '0',
608 `timeduration` int(10) unsigned NOT NULL default '0',
609 `timemodified` int(10) unsigned NOT NULL default '0',
611 UNIQUE KEY `id` (`id`),
612 KEY `courseid` (`courseid`),
613 KEY `userid` (`userid`)
614 ) TYPE=MyISAM COMMENT='For everything with a time associated to it'; ");
617 if ($oldversion < 2004012800) {
618 modify_database("", "CREATE TABLE `prefix_user_preferences` (
619 `id` int(10) unsigned NOT NULL auto_increment,
620 `userid` int(10) unsigned NOT NULL default '0',
621 `name` varchar(50) NOT NULL default '',
622 `value` varchar(255) NOT NULL default '',
624 UNIQUE KEY `id` (`id`),
625 KEY `useridname` (userid,name)
626 ) TYPE=MyISAM COMMENT='Allows modules to store arbitrary user preferences'; ");
629 if ($oldversion < 2004012900) {
630 table_column("config", "value", "value", "text", "", "", "");
633 if ($oldversion < 2004013101) {
634 table_column("log", "", "cmid", "integer", "10", "unsigned", "0", "", "module");
635 set_config("upgrade", "logs");
638 if ($oldversion < 2004020900) {
639 table_column("course", "", "lang", "varchar", "5", "", "", "", "groupmodeforce");
642 if ($oldversion < 2004020903) {
643 modify_database("", "CREATE TABLE `prefix_cache_text` (
644 `id` int(10) unsigned NOT NULL auto_increment,
645 `md5key` varchar(32) NOT NULL default '',
646 `formattedtext` longtext NOT NULL,
647 `timemodified` int(10) unsigned NOT NULL default '0',
649 KEY `md5key` (`md5key`)
650 ) TYPE=MyISAM COMMENT='For storing temporary copies of processed texts';");
653 if ($oldversion < 2004021000) {
654 $textfilters = array();
655 for ($i=1; $i<=10; $i++
) {
656 $variable = "textfilter$i";
657 if (!empty($CFG->$variable)) { /// No more filters
658 if (is_readable("$CFG->dirroot/".$CFG->$variable)) {
659 $textfilters[] = $CFG->$variable;
663 $textfilters = implode(',', $textfilters);
664 if (empty($textfilters)) {
665 $textfilters = 'mod/glossary/dynalink.php';
667 set_config('textfilters', $textfilters);
670 if ($oldversion < 2004021201) {
671 modify_database("", "CREATE TABLE `prefix_cache_filters` (
672 `id` int(10) unsigned NOT NULL auto_increment,
673 `filter` varchar(32) NOT NULL default '',
674 `version` int(10) unsigned NOT NULL default '0',
675 `md5key` varchar(32) NOT NULL default '',
676 `rawtext` text NOT NULL,
677 `timemodified` int(10) unsigned NOT NULL default '0',
679 KEY `filtermd5key` (filter,md5key)
680 ) TYPE=MyISAM COMMENT='For keeping information about cached data';");
683 if ($oldversion < 2004021500) {
684 table_column("groups", "", "hidepicture", "integer", "2", "unsigned", "0", "", "picture");
687 if ($oldversion < 2004021700) {
688 if (!empty($CFG->textfilters
)) {
689 $CFG->textfilters
= str_replace("tex_filter.php", "filter.php", $CFG->textfilters
);
690 $CFG->textfilters
= str_replace("multilang.php", "filter.php", $CFG->textfilters
);
691 $CFG->textfilters
= str_replace("censor.php", "filter.php", $CFG->textfilters
);
692 $CFG->textfilters
= str_replace("mediaplugin.php", "filter.php", $CFG->textfilters
);
693 $CFG->textfilters
= str_replace("algebra_filter.php", "filter.php", $CFG->textfilters
);
694 $CFG->textfilters
= str_replace("dynalink.php", "filter.php", $CFG->textfilters
);
695 set_config("textfilters", $CFG->textfilters
);
699 if ($oldversion < 2004022000) {
700 table_column("user", "", "emailstop", "integer", "1", "unsigned", "0", "not null", "email");
703 if ($oldversion < 2004022200) { /// Final renaming I hope. :-)
704 if (!empty($CFG->textfilters
)) {
705 $CFG->textfilters
= str_replace("/filter.php", "", $CFG->textfilters
);
706 $CFG->textfilters
= str_replace("mod/glossary/dynalink.php", "mod/glossary", $CFG->textfilters
);
707 $textfilters = explode(',', $CFG->textfilters
);
708 foreach ($textfilters as $key => $textfilter) {
709 $textfilters[$key] = trim($textfilter);
711 set_config("textfilters", implode(',',$textfilters));
715 if ($oldversion < 2004030702) { /// Because of the renaming of Czech language pack
716 execute_sql("UPDATE {$CFG->prefix}user SET lang = 'cs' WHERE lang = 'cz'");
717 execute_sql("UPDATE {$CFG->prefix}course SET lang = 'cs' WHERE lang = 'cz'");
720 if ($oldversion < 2004041800) { /// Integrate Block System from contrib
721 table_column("course", "", "blockinfo", "varchar", "255", "", "", "not null", "modinfo");
724 if ($oldversion < 2004042600) { /// Rebuild course caches for resource icons
725 include_once("$CFG->dirroot/course/lib.php");
726 rebuild_course_cache();
729 if ($oldversion < 2004042700) { /// Increase size of lang fields
730 table_column("user", "lang", "lang", "varchar", "10", "", "en");
731 table_column("groups", "lang", "lang", "varchar", "10", "", "");
732 table_column("course", "lang", "lang", "varchar", "10", "", "");
735 if ($oldversion < 2004042701) { /// Add hiddentopics field to control hidden topics behaviour
736 table_column("course", "", "hiddentopics", "integer", "1", "unsigned", "0", "not null", "visible");
739 if ($oldversion < 2004042702) { /// add a format field for the description
740 table_column("event", "", "format", "integer", "4", "unsigned", "0", "not null", "description");
743 if ($oldversion < 2004042900) {
744 execute_sql(" ALTER TABLE `{$CFG->prefix}course` DROP `showrecent` ");
747 if ($oldversion < 2004043001) { /// Change hiddentopics to hiddensections
748 table_column("course", "hiddentopics", "hiddensections", "integer", "2", "unsigned", "0", "not null");
751 if ($oldversion < 2004050400) { /// add a visible field for events
752 table_column("event", "", "visible", "tinyint", "1", "", "1", "not null", "timeduration");
753 if ($events = get_records('event')) {
754 foreach($events as $event) {
755 if ($moduleid = get_field('modules', 'id', 'name', $event->modulename
)) {
756 if (get_field('course_modules', 'visible', 'module', $moduleid, 'instance', $event->instance
) == 0) {
757 set_field('event', 'visible', 0, 'id', $event->id
);
764 if ($oldversion < 2004052800) { /// First version tagged "1.4 development", version.php 1.227
765 set_config('siteblocksadded', true); /// This will be used later by the block upgrade
768 if ($oldversion < 2004053000) { /// set defaults for site course
770 set_field('course', 'numsections', 0, 'id', $site->id
);
771 set_field('course', 'groupmodeforce', 1, 'id', $site->id
);
772 set_field('course', 'teacher', get_string('administrator'), 'id', $site->id
);
773 set_field('course', 'teachers', get_string('administrators'), 'id', $site->id
);
774 set_field('course', 'student', get_string('user'), 'id', $site->id
);
775 set_field('course', 'students', get_string('users'), 'id', $site->id
);
778 if ($oldversion < 2004060100) {
779 set_config('digestmailtime', 0);
780 table_column('user', "", 'maildigest', 'tinyint', '1', '', '0', 'not null', 'mailformat');
783 if ($oldversion < 2004062400) {
784 table_column('user_teachers', "", 'timeend', 'int', '10', 'unsigned', '0', 'not null', 'editall');
785 table_column('user_teachers', "", 'timestart', 'int', '10', 'unsigned', '0', 'not null', 'editall');
788 if ($oldversion < 2004062401) {
789 table_column('course', '', 'idnumber', 'varchar', '100', '', '', 'not null', 'shortname');
790 execute_sql('UPDATE '.$CFG->prefix
.'course SET idnumber = shortname'); // By default
793 if ($oldversion < 2004062600) {
794 table_column('course', '', 'cost', 'varchar', '10', '', '', 'not null', 'lang');
797 if ($oldversion < 2004072900) {
798 table_column('course', '', 'enrolperiod', 'int', '10', 'unsigned', '0', 'not null', 'startdate');
801 if ($oldversion < 2004072901) { // Fixing error in schema
802 if ($record = get_record('log_display', 'module', 'course', 'action', 'update')) {
803 delete_records('log_display', 'module', 'course', 'action', 'update');
804 insert_record('log_display', $record, false, 'module');
808 if ($oldversion < 2004081200) { // Fixing version errors in some blocks
809 set_field('blocks', 'version', 2004081200, 'name', 'admin');
810 set_field('blocks', 'version', 2004081200, 'name', 'calendar_month');
811 set_field('blocks', 'version', 2004081200, 'name', 'course_list');
814 if ($oldversion < 2004081500) { // Adding new "auth" field to user table to allow more flexibility
815 table_column('user', '', 'auth', 'varchar', '20', '', 'manual', 'not null', 'id');
817 execute_sql("UPDATE {$CFG->prefix}user SET auth = 'manual'"); // Set everyone to 'manual' to be sure
819 if ($admins = get_admins()) { // Set all the NON-admins to whatever the current auth module is
820 $adminlist = array();
821 foreach ($admins as $user) {
822 $adminlist[] = $user->id
;
824 $adminlist = implode(',', $adminlist);
825 execute_sql("UPDATE {$CFG->prefix}user SET auth = '$CFG->auth' WHERE id NOT IN ($adminlist)");
829 if ($oldversion < 2004082200) { // Making admins teachers on site course
831 $admins = get_admins();
832 foreach ($admins as $admin) {
833 add_teacher($admin->id
, $site->id
);
837 if ($oldversion < 2004082900) { // Make sure guest is "manual" too.
838 set_field('user', 'auth', 'manual', 'username', 'guest');
841 if ($oldversion < 2004083127) { // Update any users/courses using wrongly-named lang pack
842 execute_sql("UPDATE {$CFG->prefix}user SET lang = 'mi_nt' WHERE lang = 'ma_nt'");
843 execute_sql("UPDATE {$CFG->prefix}course SET lang = 'mi_nt' WHERE lang = 'ma_nt'");