Maybe I found a solution for closed (but not really solved) issue #315007: New comments links don't point to correct pages.
It is about the field handler which should return a link to new comments (located at modules/comment/views_handler_field_node_new_comments.inc).
The "get the right comment page" is tried to be handled by calling comment_new_page_count() function (see http://api.drupal.org/api/function/comment_new_page_count/6):
$this->options['alter']['query'] = comment_new_page_count($values->node_comment_statistics_comment_count, $values->node_new_comments, $node);
But I can't find $values->node_comment_statistics_comment_count and $values->node_new_comments. It seems that both are not defined. I also visited comment.views.inc, but I can't find it there, too.
$values->node_new_comments could be num_comments from the SQL statement:
$result = db_query("SELECT n.nid, COUNT(c.cid) as num_comments FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid LEFT JOIN {history} h ON h.nid = n.nid AND h.uid = %d WHERE n.nid IN (" . implode(', ', $nids) . ") AND c.timestamp > GREATEST(COALESCE(h.timestamp, %d), %d) AND c.status = %d GROUP BY n.nid ", $user->uid, NODE_NEW_LIMIT, NODE_NEW_LIMIT, COMMENT_PUBLISHED);
But I can't find the value for the total number of comments inside this field handler???
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 871578-comments_count.patch | 1.36 KB | dawehner |
| #2 | 871578-comments_count.patch | 1.4 KB | dawehner |
Comments
Comment #1
dawehnerIt would be cool if you could paste an example $values variable here.
Comment #2
dawehnerHere is a patch which should be tested, i'm not sure whether it will really work.
Comment #3
merlinofchaos commentedApparently whoever wrote that code assumed that you'll have the comment count field added. As a workaround that will make this work.
The patch should do the trick but I would recommend making the key used a little shorter. comment_count is sufficient. =)
Comment #4
dawehnerUpdate
Comment #5
merlinofchaos commentedSince we're looking at this piece of code,
$values->node_new_commentsshould be examined, since that's referencing a field alias directly that could be a problem too?Comment #6
merlinofchaos commentedOh wait, duh, that's *removed* code.
If someone can test that this works, it passes a visual review just fine.
Comment #7
m_z commented@dereine: what a speed ;-)
I took a first look at your patch and it look promising.
Maybe somebody with so many comments that they don't fit on one page can test this patch. I found this bug when I was looking for something else. But this issue can help a lot of people like the old (closed) issue shows us.
So thanks for your work. I will come back here and test the patch if I have a use case for it.
Maybe other users can test it earlier.
Comment #8
merlinofchaos commentedNeeds porting to D7.
Comment #9
dawehnerPorted and commited.