From: mchurch Date: Mon, 31 Jan 2005 19:24:14 +0000 (+0000) Subject: Fixed insert_record call in forum_tp_add_read_record. Added read post X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=90fd2b51aadb6a52e5ba17edacf58f92d65fe10a;p=moodle.git Fixed insert_record call in forum_tp_add_read_record. Added read post marking for posts over a day old to the upgrade procedure. --- diff --git a/mod/forum/db/mysql.php b/mod/forum/db/mysql.php index e538c753f1..fd70872191 100644 --- a/mod/forum/db/mysql.php +++ b/mod/forum/db/mysql.php @@ -173,6 +173,42 @@ function forum_upgrade($oldversion) { KEY `prefix_forum_user_discussion_idx` (`userid`,`discussionid`), KEY `prefix_forum_user_post_idx` (`userid`,`postid`) ) COMMENT=\'Tracks each users read posts\';'); + + /// 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); + } + } + } + } + } + } + } return true; @@ -181,4 +217,4 @@ function forum_upgrade($oldversion) { -?> +?> \ No newline at end of file diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 1570d51ed9..8ea31ab0a2 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -3082,7 +3082,7 @@ function forum_tp_add_read_record($userid, $postid, $discussionid=-1, $forumid=- $readrecord->forumid = $forumid; $readrecord->firstread = time(); $readrecord->lastread = $readrecord->firstread; - return insert_record('forum_read', $readrecord, true, 'userid'); + return insert_record('forum_read', $readrecord, true); } else { /// Update read record