When viewing comments ordered by date comment.module function comment_render queries the database with an ORDER BY cid instead of an ORDER BY timestamp. This breaks adding old comments manually.

CommentFileSizeAuthor
#7 comment-D6.patch1.05 KBszantog
#1 comment.module.patch899 bytessebdah

Comments

sebdah’s picture

Status: Active » Needs review
StatusFileSize
new899 bytes

I have created a patch that works as suggested in the ticket.

bradweikel’s picture

Version: 6.6 » 6.x-dev
Status: Needs review » Reviewed & tested by the community

works as described

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs review

The thread ordering is also based on cids so looks like your import script should ensure that it keeps the cid order right as far as I can tell. Would be good to look into this a little bit. I tried to look up why are we exactly using cid here, since we use timestamp elsewhere in the module, but did not manage to find that out. Any other opinions on that?

szantog’s picture

I'played a lot with comment's states with this patch, I can't make any other error with this patch.
This order by cid make lot of errors.
One of the problem is, there are a lot of module, that makes, changes comments different ways. And the cid is constant, but the timestamp not.
An example: the nodecomments can convert comments to node, and vica versa. Convert nodecomments to comment can break the complete comment structure without this patch.

I tried to make some error with this patch more than one hour, and I couldn't. I've installed the latest drupal dev, make 4 content type: Threaded newest, Threaded oldest, Flat newest, Flat oldest. I made tons of comment, with reply, without reply, I modified the post dates after posting a comment.
The threaded views doesn't change, the flat views always works as well.

szantog’s picture

Status: Needs review » Reviewed & tested by the community

set to rtbc

Status: Reviewed & tested by the community » Needs work

The last submitted patch, comment.module.patch, failed testing.

szantog’s picture

Status: Needs work » Needs review
StatusFileSize
new1.05 KB

Ok, attached the new patch..

carteriii’s picture

I found this thread when searching for a solution to the same problem, that ordering by c.cid doesn't order properly when the comment timestamps have been updated.

I looked into using hook_db_rewrite_sql to modify the behavior, but it's not possible to modify the "order by" clause using hook_db_rewrite_sql.

One other user posted a significant workaround that seems to be far more dangerous than simply fixing comment_render as described here. For the benefit of others, here is the other thread: http://drupal.org/node/554752

Can we get this into core such that it doesn't require a patch in the future?

sivaji_ganesh_jojodae’s picture

+1 for this patch.

Also d8 seems to rely on cid instead of timestamp see comment_get_thread().

  if ($mode === COMMENT_MODE_FLAT) {
    $query->orderBy('c.cid', 'ASC');
  }
  else {
    // See comment above. Analysis reveals that this doesn't cost too
    // much. It scales much much better than having the whole comment
    // structure.
    $query->addExpression('SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))', 'torder');
    $query->orderBy('torder', 'ASC');
  }

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.