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???

Comments

dawehner’s picture

It would be cool if you could paste an example $values variable here.

dawehner’s picture

Status: Active » Needs work
StatusFileSize
new1.4 KB

Here is a patch which should be tested, i'm not sure whether it will really work.

merlinofchaos’s picture

Status: Needs work » Needs review

Apparently 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. =)

dawehner’s picture

StatusFileSize
new1.36 KB

Update

merlinofchaos’s picture

Since we're looking at this piece of code, $values->node_new_comments should be examined, since that's referencing a field alias directly that could be a problem too?

merlinofchaos’s picture

Oh wait, duh, that's *removed* code.

If someone can test that this works, it passes a visual review just fine.

m_z’s picture

@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.

merlinofchaos’s picture

Version: 6.x-2.11 » 7.x-3.x-dev
Status: Needs review » Patch (to be ported)

Needs porting to D7.

dawehner’s picture

Status: Patch (to be ported) » Fixed

Ported and commited.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.