Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. DELETE FROM comment
  2. WHERE nid = <the involved node id>
  3.  
  4. SELECT * FROM comment
  5. WHERE nid = <the involved node id>
  6.  
  7. DELETE FROM field_data_comment_body
  8. WHERE entity_type = "comment"
  9. AND entity_id IN (
  10. SELECT cid
  11. FROM comment
  12. WHERE nid = <the involved node id>
  13. )
  14.  
  15. <?php
  16.  
  17. // Change this to the nid you want to clear comments from
  18. $nid = 12345;
  19.  
  20. // Queries the database for all comment IDs associated with the nid, max 1000
  21. $cids = db_select('comment', 'c')
  22. ->fields('c', array('cid'))
  23. ->condition('c.nid', $nid)
  24. ->range(0, 1000)
  25. ->execute()
  26. ->fetchCol();
  27.  
  28. if (!count($cids)) {
  29. drush_print("No more comments found. Aborting.");
  30.  
  31. // Abort with an error code (so a bash script can key off that)
  32. exit(1);
  33. }
  34.  
  35. // Delete the comments with comment IDs we got from the DB
  36. comment_delete_multiple($cids);
  37. drush_print(count($cids) . " comments deleted");
  38.  
  39. #!/bin/bash
  40.  
  41. while drush @your-server-alias scr /path/to/script/on/server/so.php; do
  42. sleep 1
  43. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement