How to Delete Comment Spam in Drupal 6

Posted:

I examined the documentation. Here is the important function:

http://api.drupal.org/api/function/commentdelete_thread/6

The other things, like updating the comment stats & clearing the cache, are not important to run, IMHO, because they will most likely eventually get called in normal use anyway.

Also, if some of the comments you want to keep have parent comments, make sure you keep all the parent comments all the way to the root comment of the thread.

Run the following MySQL query:

DELETE FROM comments WHERE cid NOT IN (1,2,3,41826); where 1,2,3,... are the ids of comments that you do not want to delete. This worked since I had very few real comments.

To determine the cids of real comments and their pids (parent ids), do:

SELECT cid, pid, subject, comment FROM comments;

If there are pids that are greater than 0, you'll have to investigate to find out if that pid has a pid > 0 and so on all the way up the chain. Keep all the parents.

HTH!