Possible duplicate of #360023: Update node_comment_statistics during "Publish comment" action
Spawned from #2307845: When flagging comments update statistics

The comment api function of comment_unpublish_action() and receptively comment_publish_action() appears to update the comment db for a node directly and skips the update of that node's statistics causing comment count numbers to become out of date when comments are set to be published/unpublished.

I get around this problem by calling _comment_update_node_statistics() directly but we need a better solution than that for contrib modules.

CommentFileSizeAuthor
#6 update_comment_statistic-2309957-6.patch1.97 KBtinko

Comments

dcam’s picture

Version: 7.29 » 7.x-dev
Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)
Issue tags: +Needs steps to reproduce

Thank you for your report! I think that I understand what you say is happening, but I would really appreciate it if you could provide us with steps to reproduce this issue. That way there's no confusion.

coolestdude1’s picture

dcam, sure thing.

1. Create content type with comments enabled
2. Create a node
3. Create a comment on that node
4. Check the node statistics table, the comment count for the node created earlier should now be 1
5. Use the comment module api to unpublish the comment created earlier
6. Check the node statistics table again and the comment count will remain at 1
7. Run _comment_update_node_statistics() on the node created
8. Check the node statistics table again and the comment count will now be 0

Issue arises from updating comment table directly with an SQL call rather than using comments internal functions for unpublishing a node. Affects contrib/custom modules trying to call the comment api as intended.

coolestdude1’s picture

Priority: Normal » Minor
Status: Postponed (maintainer needs more info) » Active
Issue tags: -Needs steps to reproduce

Pushing back after proper steps to reproduce given, issue is still a problem at 7.41

markot91’s picture

Assigned: Unassigned » markot91
tinko’s picture

Status: Active » Needs review

Hello,

The field comment_count in table node_comment_statistics is for the count of published comments on the node.

If you unpublish a comment programmatically the function _comment_update_node_statistics() is never called to update statistics and that is why you still get the comment_count: 1, but when the function is called she updates the comment_count.

You have to do the actions on comments and the statistics update together (if you are doing it programmatically)

Greetings

tinko’s picture

StatusFileSize
new1.97 KB

Hello,

Here is the patch for updating statistic when publish/unpublish comment with the api functions comment_publish_action() and comment_unpublish_action().

Greetings

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.