Drupal - deleting comments in bulk

AFAIK, VBO should be able to do the job, but I haven't tried it myself to delete comments.

Another way is to run some code (in a module or in Devel module's 'execute php' block) that gets a list of all queries from the db, builds an array of the comment IDs and passes that array to the comment_delete_multiple function. Note that this can take a while to complete (depending on server performance and the number of comments), so you may have work your way around that, for instance by using set_time_limit (http://php.net/manual/en/function.set-time-limit.php) or Drupal's batch API.

[update: see Chris Cohen's answer for example code based on this approach.]


This is not an alternative answer, more an elaboration on marcvangend's, but I couldn't comment on his answer and leave example code. So the manual approach, using devel's execute code block, would look a bit like:


$cids = db_select('comment', 'c')
  ->fields('c', array('cid'))
  ->execute()
  ->fetchCol();

comment_delete_multiple($cids);

As marcvangend points out, this is going to be limited to the execution time on your server, so you will need to temporarily raise it if you have a lot of comments. Thanks to manarth and instanceofjamie for the dbtng assistance.


Personally, I'd go for the Views Bulk Operations module.

This module augments Views by allowing bulk operations to be executed on the displayed rows. It does so by showing a checkbox in front of each node, and adding a select box containing operations that can be applied. Drupal Core or Rules actions can be used.

Tags:

Comments

Views

7