2004-09-12 16:24:41 +00:00
|
|
|
<?php // $Id$
|
2002-10-05 17:20:24 +00:00
|
|
|
|
|
|
|
function forum_upgrade($oldversion) {
|
|
|
|
// This function does anything necessary to upgrade
|
|
|
|
// older versions to match current functionality
|
|
|
|
|
2003-04-24 08:45:27 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2002-10-05 17:20:24 +00:00
|
|
|
if ($oldversion < 2002073008) {
|
|
|
|
execute_sql("DELETE FROM modules WHERE name = 'discuss' ");
|
|
|
|
execute_sql("ALTER TABLE `discuss` RENAME `forum_discussions` ");
|
|
|
|
execute_sql("ALTER TABLE `discuss_posts` RENAME `forum_posts` ");
|
|
|
|
execute_sql("ALTER TABLE `discuss_ratings` RENAME `forum_ratings` ");
|
|
|
|
execute_sql("ALTER TABLE `forum` CHANGE `intro` `intro` TEXT NOT NULL ");
|
|
|
|
execute_sql("ALTER TABLE `forum` ADD `forcesubscribe` TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL AFTER `assessed`");
|
|
|
|
execute_sql("ALTER TABLE `forum` CHANGE `type` `type` ENUM( 'single', 'news', 'social', 'general',
|
|
|
|
'eachuser', 'teacher' ) DEFAULT 'general' NOT NULL ");
|
|
|
|
execute_sql("ALTER TABLE `forum_posts` CHANGE `discuss` `discussion` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL ");
|
|
|
|
execute_sql("INSERT INTO log_display VALUES ('forum', 'add', 'forum', 'name') ");
|
|
|
|
execute_sql("INSERT INTO log_display VALUES ('forum', 'add discussion', 'forum_discussions', 'name') ");
|
|
|
|
execute_sql("INSERT INTO log_display VALUES ('forum', 'add post', 'forum_posts', 'subject') ");
|
|
|
|
execute_sql("INSERT INTO log_display VALUES ('forum', 'update post', 'forum_posts', 'subject') ");
|
|
|
|
execute_sql("INSERT INTO log_display VALUES ('forum', 'view discussion', 'forum_discussions', 'name') ");
|
|
|
|
execute_sql("DELETE FROM log_display WHERE module = 'discuss' ");
|
|
|
|
execute_sql("UPDATE log SET action = 'view discussion' WHERE module = 'discuss' AND action = 'view' ");
|
|
|
|
execute_sql("UPDATE log SET action = 'add discussion' WHERE module = 'discuss' AND action = 'add' ");
|
|
|
|
execute_sql("UPDATE log SET module = 'forum' WHERE module = 'discuss' ");
|
|
|
|
notify("Renamed all the old discuss tables (now part of forum) and created new forum_types");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($oldversion < 2002080100) {
|
|
|
|
execute_sql("INSERT INTO log_display VALUES ('forum', 'view subscribers', 'forum', 'name') ");
|
|
|
|
execute_sql("INSERT INTO log_display VALUES ('forum', 'update', 'forum', 'name') ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($oldversion < 2002082900) {
|
|
|
|
execute_sql(" ALTER TABLE `forum_posts` ADD `attachment` VARCHAR(100) NOT NULL AFTER `message` ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($oldversion < 2002091000) {
|
|
|
|
if (! execute_sql(" ALTER TABLE `forum_posts` ADD `attachment` VARCHAR(100) NOT NULL AFTER `message` ")) {
|
2004-09-12 16:24:41 +00:00
|
|
|
echo "<p>Don't worry about this error - your server already had this upgrade applied";
|
2002-10-05 17:20:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($oldversion < 2002100300) {
|
|
|
|
execute_sql(" ALTER TABLE `forum` CHANGE `open` `open` TINYINT(2) UNSIGNED DEFAULT '2' NOT NULL ");
|
|
|
|
execute_sql(" UPDATE `forum` SET `open` = 2 WHERE `open` = 1 ");
|
|
|
|
execute_sql(" UPDATE `forum` SET `open` = 1 WHERE `open` = 0 ");
|
|
|
|
}
|
2002-10-10 07:27:57 +00:00
|
|
|
if ($oldversion < 2002101001) {
|
|
|
|
execute_sql(" ALTER TABLE `forum_posts` ADD `format` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `message` ");
|
|
|
|
}
|
2002-10-05 17:20:24 +00:00
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
if ($oldversion < 2002122300) {
|
|
|
|
execute_sql("ALTER TABLE `forum_posts` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
|
|
|
|
execute_sql("ALTER TABLE `forum_ratings` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
|
|
|
|
execute_sql("ALTER TABLE `forum_subscriptions` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
|
|
|
|
}
|
|
|
|
|
2003-04-24 08:45:27 +00:00
|
|
|
if ($oldversion < 2003042402) {
|
|
|
|
execute_sql("INSERT INTO {$CFG->prefix}log_display VALUES ('forum', 'move discussion', 'forum_discussions', 'name')");
|
|
|
|
}
|
2003-08-15 13:59:24 +00:00
|
|
|
|
|
|
|
if ($oldversion < 2003081403) {
|
2003-08-16 02:30:23 +00:00
|
|
|
table_column("forum", "assessed", "assessed", "integer", "10", "unsigned", "0");
|
2003-08-15 13:59:24 +00:00
|
|
|
}
|
2003-08-25 07:39:06 +00:00
|
|
|
|
|
|
|
if ($oldversion < 2003082500) {
|
|
|
|
table_column("forum", "", "assesstimestart", "integer", "10", "unsigned", "0", "", "assessed");
|
|
|
|
table_column("forum", "", "assesstimefinish", "integer", "10", "unsigned", "0", "", "assesstimestart");
|
|
|
|
}
|
2003-08-25 12:47:36 +00:00
|
|
|
|
|
|
|
if ($oldversion < 2003082502) {
|
|
|
|
table_column("forum", "scale", "scale", "integer", "10", "", "0");
|
|
|
|
execute_sql("UPDATE {$CFG->prefix}forum SET scale = (- scale)");
|
|
|
|
}
|
2003-10-06 18:02:35 +00:00
|
|
|
|
|
|
|
if ($oldversion < 2003100600) {
|
|
|
|
table_column("forum", "", "maxbytes", "integer", "10", "unsigned", "0", "", "scale");
|
|
|
|
}
|
2004-01-01 04:48:55 +00:00
|
|
|
|
|
|
|
if ($oldversion < 2004010100) {
|
|
|
|
table_column("forum", "", "assesspublic", "integer", "4", "unsigned", "0", "", "assessed");
|
|
|
|
}
|
2004-01-14 11:50:29 +00:00
|
|
|
|
|
|
|
if ($oldversion < 2004011404) {
|
|
|
|
table_column("forum_discussions", "", "userid", "integer", "10", "unsigned", "0", "", "firstpost");
|
|
|
|
|
|
|
|
if ($discussions = get_records_sql("SELECT d.id, p.userid
|
|
|
|
FROM {$CFG->prefix}forum_discussions as d,
|
|
|
|
{$CFG->prefix}forum_posts as p
|
|
|
|
WHERE d.firstpost = p.id")) {
|
|
|
|
foreach ($discussions as $discussion) {
|
|
|
|
update_record("forum_discussions", $discussion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-01-23 12:09:25 +00:00
|
|
|
|
|
|
|
if ($oldversion < 2004012200) {
|
|
|
|
table_column("forum_discussions", "", "groupid", "integer", "10", "unsigned", "0", "", "userid");
|
|
|
|
}
|
2004-01-30 21:40:31 +00:00
|
|
|
|
|
|
|
if ($oldversion < 2004013000) {
|
|
|
|
table_column("forum_posts", "mailed", "mailed", "tinyint", "2");
|
|
|
|
}
|
2004-02-06 13:15:15 +00:00
|
|
|
|
|
|
|
if ($oldversion < 2004020600) {
|
|
|
|
table_column("forum_discussions", "", "usermodified", "integer", "10", "unsigned", "0", "", "timemodified");
|
|
|
|
}
|
2004-05-02 23:08:19 +00:00
|
|
|
|
|
|
|
if ($oldversion < 2004050300) {
|
|
|
|
table_column("forum","","rsstype","tinyint","2", "unsigned", "0", "", "forcesubscribe");
|
|
|
|
table_column("forum","","rssarticles","tinyint","2", "unsigned", "0", "", "rsstype");
|
|
|
|
set_config("forum_enablerssfeeds",0);
|
|
|
|
}
|
2004-06-01 07:39:27 +00:00
|
|
|
|
|
|
|
if ($oldversion < 2004060100) {
|
|
|
|
modify_database('', "CREATE TABLE `prefix_forum_queue` (
|
|
|
|
`id` int(11) unsigned NOT NULL auto_increment,
|
|
|
|
`userid` int(11) unsigned default 0 NOT NULL,
|
|
|
|
`discussionid` int(11) unsigned default 0 NOT NULL,
|
|
|
|
`postid` int(11) unsigned default 0 NOT NULL,
|
|
|
|
PRIMARY KEY (`id`),
|
|
|
|
KEY `user` (userid),
|
2004-06-01 07:45:18 +00:00
|
|
|
KEY `post` (postid)
|
2004-06-01 07:39:27 +00:00
|
|
|
) TYPE=MyISAM COMMENT='For keeping track of posts that will be mailed in digest form';");
|
|
|
|
}
|
|
|
|
|
2004-07-07 17:42:53 +00:00
|
|
|
if ($oldversion < 2004070700) { // This may be redoing it from STABLE but that's OK
|
|
|
|
table_column("forum_discussions", "groupid", "groupid", "integer", "10", "", "0", "");
|
|
|
|
}
|
2004-11-18 04:10:47 +00:00
|
|
|
|
|
|
|
if ($oldversion < 2004111700) {
|
|
|
|
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` DROP INDEX {$CFG->prefix}forum_posts_parent_idx;",false);
|
|
|
|
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` DROP INDEX {$CFG->prefix}forum_posts_discussion_idx;",false);
|
|
|
|
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` DROP INDEX {$CFG->prefix}forum_posts_userid_idx;",false);
|
|
|
|
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_discussions` DROP INDEX {$CFG->prefix}forum_discussions_forum_idx;",false);
|
|
|
|
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_discussions` DROP INDEX {$CFG->prefix}forum_discussions_userid_idx;",false);
|
|
|
|
|
|
|
|
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` ADD INDEX {$CFG->prefix}forum_posts_parent_idx (parent) ");
|
|
|
|
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` ADD INDEX {$CFG->prefix}forum_posts_discussion_idx (discussion) ");
|
|
|
|
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` ADD INDEX {$CFG->prefix}forum_posts_userid_idx (userid) ");
|
|
|
|
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_discussions` ADD INDEX {$CFG->prefix}forum_discussions_forum_idx (forum) ");
|
|
|
|
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_discussions` ADD INDEX {$CFG->prefix}forum_discussions_userid_idx (userid) ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($oldversion < 2004111700) {
|
|
|
|
execute_sql("ALTER TABLE {$CFG->prefix}forum DROP INDEX course;",false);
|
|
|
|
execute_sql("ALTER TABLE {$CFG->prefix}forum_ratings DROP INDEX userid;",false);
|
|
|
|
execute_sql("ALTER TABLE {$CFG->prefix}forum_ratings DROP INDEX post;",false);
|
|
|
|
execute_sql("ALTER TABLE {$CFG->prefix}forum_subscriptions DROP INDEX userid;",false);
|
|
|
|
execute_sql("ALTER TABLE {$CFG->prefix}forum_subscriptions DROP INDEX forum;",false);
|
|
|
|
|
|
|
|
modify_database('','ALTER TABLE prefix_forum ADD INDEX course (course);');
|
|
|
|
modify_database('','ALTER TABLE prefix_forum_ratings ADD INDEX userid (userid);');
|
|
|
|
modify_database('','ALTER TABLE prefix_forum_ratings ADD INDEX post (post);');
|
|
|
|
modify_database('','ALTER TABLE prefix_forum_subscriptions ADD INDEX userid (userid);');
|
|
|
|
modify_database('','ALTER TABLE prefix_forum_subscriptions ADD INDEX forum (forum);');
|
|
|
|
}
|
2004-07-07 17:42:53 +00:00
|
|
|
|
2005-01-29 09:49:42 +00:00
|
|
|
if ($oldversion < 2005011500) {
|
|
|
|
modify_database('','CREATE TABLE prefix_forum_read (
|
|
|
|
`id` int(10) unsigned NOT NULL auto_increment,
|
|
|
|
`userid` int(10) NOT NULL default \'0\',
|
|
|
|
`forumid` int(10) NOT NULL default \'0\',
|
|
|
|
`discussionid` int(10) NOT NULL default \'0\',
|
|
|
|
`postid` int(10) NOT NULL default \'0\',
|
|
|
|
`firstread` int(10) NOT NULL default \'0\',
|
|
|
|
`lastread` int(10) NOT NULL default \'0\',
|
|
|
|
PRIMARY KEY (`id`),
|
|
|
|
KEY `prefix_forum_user_forum_idx` (`userid`,`forumid`),
|
|
|
|
KEY `prefix_forum_user_discussion_idx` (`userid`,`discussionid`),
|
|
|
|
KEY `prefix_forum_user_post_idx` (`userid`,`postid`)
|
|
|
|
) COMMENT=\'Tracks each users read posts\';');
|
2005-01-31 19:24:14 +00:00
|
|
|
|
|
|
|
/// Enter initial read records for all posts older than 1 day.
|
|
|
|
|
|
|
|
require $CFG->dirroot.'/mod/forum/lib.php';
|
|
|
|
/// Timestamp for old posts (and therefore considered read).
|
|
|
|
$dateafter = time() - ($CFG->forum_oldpostdays*24*60*60);
|
|
|
|
/// Timestamp for one day ago.
|
|
|
|
$onedayago = time() - (24*60*60);
|
|
|
|
|
|
|
|
/// Get all discussions that have had posts since the old post date.
|
|
|
|
if ($discrecords = get_records_select('forum_discussions', 'timemodified > '.$dateafter,
|
|
|
|
'course', 'id,course,forum,groupid')) {
|
|
|
|
$currcourse = 0;
|
|
|
|
$users = 0;
|
|
|
|
foreach ($discrecords as $discrecord) {
|
|
|
|
if ($discrecord->course != $currcourse) {
|
|
|
|
/// Discussions are ordered by course, so we only need to get any course's users once.
|
|
|
|
$currcourse = $discrecord->course;
|
|
|
|
$users = get_course_users($currcourse);
|
|
|
|
}
|
|
|
|
/// If this course has users, and posts more than a day old, mark them for each user.
|
|
|
|
if (is_array($users) &&
|
|
|
|
($posts = get_records_select('forum_posts', 'discussion = '.$discrecord->id.
|
|
|
|
' AND modified < '.$onedayago, '', 'id,discussion,modified'))) {
|
|
|
|
foreach($posts as $post) {
|
|
|
|
foreach ($users as $user) {
|
|
|
|
/// If its a group discussion, make sure the user is in the group.
|
|
|
|
if (!$discrecord->groupid || ismember($discrecord->groupid, $user->id)) {
|
|
|
|
forum_tp_mark_post_read($user->id, $post, $discrecord->forum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-29 09:49:42 +00:00
|
|
|
}
|
|
|
|
|
2005-03-29 04:32:48 +00:00
|
|
|
if ($oldversion < 2005032900) {
|
|
|
|
modify_database('','ALTER TABLE prefix_forum_posts ADD INDEX prefix_form_posts_created_idx (created);');
|
|
|
|
modify_database('','ALTER TABLE prefix_forum_posts ADD INDEX prefix_form_posts_mailed_idx (mailed);');
|
|
|
|
}
|
|
|
|
|
2005-04-11 13:04:48 +00:00
|
|
|
if ($oldversion < 2005041100) { // replace wiki-like with markdown
|
|
|
|
include_once( "$CFG->dirroot/lib/wiki_to_markdown.php" );
|
|
|
|
$wtm = new WikiToMarkdown();
|
|
|
|
$sql = "select course from {$CFG->prefix}forum_discussions, {$CFG->prefix}forum_posts ";
|
2005-04-13 07:34:43 +00:00
|
|
|
$sql .= "where {$CFG->prefix}forum_posts.discussion = {$CFG->prefix}forum_discussions.id ";
|
2005-04-12 19:57:51 +00:00
|
|
|
$sql .= "and {$CFG->prefix}forum_posts.id = ";
|
2005-04-11 13:04:48 +00:00
|
|
|
$wtm->update( 'forum_posts','message','format',$sql );
|
|
|
|
}
|
|
|
|
|
2002-10-05 17:20:24 +00:00
|
|
|
return true;
|
2004-11-18 04:10:47 +00:00
|
|
|
|
2002-10-05 17:20:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-11 13:04:48 +00:00
|
|
|
?>
|