delete a bunch of comments in Drupal 6

Public

You can use this via drush e.g. "drush @sitealias scr scriptname.php"

Get raw version
php
  1. <?php
  2.  
  3. module_load_include('inc', 'comment', 'comment.admin');
  4.  
  5. $cids = db_query("SELECT cid FROM comments WHERE cid != 1 AND thread not like '%.%' LIMIT 1000");
  6.  
  7. $counter = 0;
  8. while ($cid = db_result($cids)) {
  9. $counter++;
  10. print "Deleting $cid." . PHP_EOL;
  11. if (($counter % 100) == 0) {
  12. print "rest the DB a bit" . PHP_EOL;
  13. sleep(1);
  14. }
  15. $comment = _comment_load($cid);
  16. _comment_delete_thread($comment);
  17. }
  18.  
  19. print "deleted $counter top level comments. So that's cool." . PHP_EOL;