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.