Drupal コメントを SQL で一括削除

Nid: 1220
  • Posted on: 13 February 2019
  • By: admin

status が hidden のコメントを削除する例。0 = hidden, 1 = closed, 2 = open

データを確認、コメントの本体を消して、

$ drush sql-query "SELECT * FROM comment WHERE status = 0"
$ drush sql-query "DELETE FROM comment WHERE status = 0"

リンク先の無くなったデータを削除。

$ drush sql-query "
DELETE field_data_comment_body FROM field_data_comment_body
LEFT JOIN comment ON field_data_comment_body.entity_id = comment.cid
WHERE comment.cid IS NULL;"
$ drush sql-query "
DELETE field_revision_comment_body FROM field_revision_comment_body
LEFT JOIN comment ON field_revision_comment_body.entity_id = comment.cid
WHERE comment.cid IS NULL;"