-
Bug
-
Resolution: Fixed
-
Minor
-
2.2.3
-
None
-
MOODLE_22_STABLE
-
MOODLE_21_STABLE, MOODLE_22_STABLE
-
Easy
-
In mod/forum/lib.php, there is a function called forum_tp_count_discussion_unread_posts() which returns the number of unread messages in a given discussion, for a given user.
As far as I can tell, this function is not called anywhere in Moodle. But I call it from some custom navigational code (a button that jumps to "more unread messages" in whatever forum you are viewing.)
The function prepares a database query, and calls count_records_sql(). The call includes the correct parameters, but they are in the wrong order (they don't match the sql query).
Looking in CVS, I think the mistake crept in when the DB api changed, in revision 1.675 on 5 June 2008.
It's an obvious, trivial fix.. the call to DB->count_records_sql has the discussionid and cutoffid parameters reversed. Can someone with CVS access fix this please?
The broken code:
function forum_tp_count_discussion_unread_posts($userid, $discussionid) {
|
global $CFG, $DB;
|
$cutoffdate = isset($CFG->forum_oldpostdays) ? (time() - ($CFG->forum_oldpostdays*24*60*60)) : 0;
|
|
$sql = 'SELECT COUNT(p.id) '.
|
'FROM {forum_posts} p '.
|
'LEFT JOIN {forum_read} r ON r.postid = p.id AND r.userid = ? '.
|
'WHERE p.discussion = ? '.
|
'AND p.modified >= ? AND r.id is NULL';
|
|
return $DB->count_records_sql($sql, array($userid, $cutoffdate, $discussionid));
|
}
|
To fix this, just reverse the $cutoffdata and $discussionid parameters in the count_records_sql call:
return $DB->count_records_sql($sql, array($userid, $discussionid, $cutoffdate));
|