A user, TallTrees, is seeking a way to bulk delete old whispers from all topics in their forum. Whispers are used to discuss potential moderator actions, but once action is taken, they become noise.
Tshenry provided a Ruby script that uses PostDestroyer to delete the whispers, effectively acting as if the System user deleted each post manually. The script works, but TallTrees found that the whispers are only collapsed and still viewable by Admins and moderators.
After further research, TallTrees discovered that it’s not possible to permanently remove deleted or hidden posts, including whispers, as per previous discussions and recent findings.
I’m looking for a way to delete whispers over a certain age from all topics.
Generally we use whispers to discuss potential moderator actions, but once action had been taken, the whispers aren’t so useful and increasingly become noise as time passes.
I could delete posts over a certain age with post_type=4 (whisper) but this seems like could leave things dangling or inconsistent in the database, or not be allowed due to forum keys.
This would be the cleanest way to delete the posts:
whispers = Post.where(post_type: 4).where("created_at < ?", 1.year.ago)
whispers.find_each do |w|
PostDestroyer.new(Discourse.system_user, w, skip_staff_log: true).destroy
putc "."
end
This will essentially act as if the System user deleted each post by hand using the delete button on the post. I included skip_staff_log so you don’t pollute your staff logs, but you can remove that if you’d prefer to have the action logged.