Just noticed that hook_comment(delete) is not invoked for comments related to a node, when this node is deleted.
When a node is deleted, the comment module catches the the event through hook_nodeapi(delete), where this code is executed:
db_query('DELETE FROM {comments} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid);
No other actions are taken. However, when you look at how comments are deleted the flow is:
- _comment_delete_thread() is invoked, which recursively deletes the corresponding comment replies, but that also invokes hook_comment(delete) for each comment.
- Then _comment_update_node_statistics() is also invoked. This is not particulary needed when deleting a node, but anyway...
Not sure how a fix would be best approached, but I would suggest to write a new function in comment module, similar to _comment_delete_thread(), but to recursively delete comments of a node. something like that would easy the task of contrib modules that may need to trigger this kind of operations themselves, such as the spam module or the akismet module (something I'm working on right now and where I noticed this).
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 67703-comment_delete.patch | 732 bytes | quotesbro |
| #3 | 67703_comment_delete_hook.patch | 773 bytes | nvahalik |
Comments
Comment #1
magico commented@markus_petrux: could you make some tests with the current HEAD? Thanks!
Comment #2
magico commentedConfirmed.
Comment #3
nvahalik commentedStill a problem in 6.x-dev.
#545032: casetracker_comment_status table entry not removed on case delete depends on this issue.
Patch attached.
Comment #4
mstef commentedsubscribing
Comment #5
mstef commentedthis issue is 4 years old??
Comment #6
mr.j commented++
Another issue that depends on fixing this bug:
#1216048: Points for comments are not subtracted when node is deleted
Comment #7
mr.j commentedWrong status, sorry. And it looks like this has been fixed for Drupal 7 but not backported.
http://api.drupal.org/api/drupal/modules--comment--comment.module/functi...
Eyeballing the patch in #3, it looks to me like _comment_delete_thread() could possibly be deleting child comments in threaded discussions before they are iterated in the while loop. Not sure if this would cause problems?
Comment #9
Exploratus commentedUploads through the comment upload module are not deleted when the node is deleted.
http://drupal.org/node/1503264
Comment #10
quotesbro commented#3 patch for Git