net/_posts/2012-04-13-using-drush-to-mass-delete-comments.md

23 lines
1.4 KiB
Markdown
Raw Normal View History

2012-04-13 16:54:13 -04:00
---
layout: post
title: Using Drush to Mass Delete Comments
tags:
- drupal
---
2016-10-23 22:09:51 -04:00
Like many kind, good-natured geeks, I (yes, I was talking about me) host a number of small sites for friends. Many of those sites run Drupal and several don't get a lot of attention. That is, until spammers find their way around [Mollom](http://mollom.com/). I've seen this happen a few times, but most recently on a Drupal 7 site. In this particular case, the spam comments had been trickling in over a few weeks undetected. Following a burst of recent activity (enough to notice via monitoring), I checked in to find > 60,000 spam comments.
2012-04-13 16:54:13 -04:00
If this has ever happened to you: you're not alone. At this number of comments, using Drupal's interface (50 comments at a time) isn't really usable. Also, these things tend to happen in bursts - so chances are good there's a block of comments that are all spam (i.e. there haven't been any legitimate comments that you want to save since it started). So, I whipped up a small script here:
2016-10-23 22:09:51 -04:00
{% gist walkah/2379996 %}
2012-04-13 16:54:13 -04:00
Here's how to use it:
1. Place the code in a file (say, `comment-rm.php`) in your Drupal directory.
2016-10-23 22:09:51 -04:00
2. Find the `cid` of the first spam comment (exercise left to the reader) and set `$first_comment` to that value.
2012-04-13 16:54:13 -04:00
3. Run `drush scr comment-rm.php` and go grab a coffee.
Hope that helps someone, but at least now I can find it again next time.
*Beware*: This deletes comments forever, be careful.