mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 09:57:25 +08:00
DEV: Add rake task to bulk delete posts (#31576)
This PR adds a destroy:posts rake task that can be used to hard-delete a list of posts. Useful for dealing with large amounts of spam that has been soft deleted and needs to go. Notes: Works on both non-deleted and soft-deleted posts. (We might want to change this to work on only soft-deleted posts?) Works exclusively on post IDs. We can't mix topic and post IDs as they might clash, and we have no way of resolving that ambiguity. Accepts either a rake-style array of IDs or, more conveniently, you can pipe the argument in through STDIN. Added a confirmation step since it's a fairly destructive operation.
This commit is contained in:
@ -50,3 +50,16 @@ task "destroy:categories" => :environment do |t, args|
|
||||
puts "Going to delete these categories: #{categories}"
|
||||
categories.each { |id| destroy_task.destroy_category(id, true) }
|
||||
end
|
||||
|
||||
# Hard delete a list of posts by ID. Pass a comma
|
||||
# separated list either as a rake argument or through
|
||||
# STDIN, e.g. through a pipe.
|
||||
#
|
||||
# Example: rake destroy:posts[4,8,15,16,23,42]
|
||||
# Example: cat post_ids.txt | rake destroy:posts
|
||||
desc "Destroy a list of posts given by ID"
|
||||
task "destroy:posts" => :environment do |_task, args|
|
||||
post_ids = args.extras.empty? ? STDIN.read.strip.split(",") : args.extras
|
||||
puts "Going to delete these posts: #{post_ids}"
|
||||
DestroyTask.new.destroy_posts(post_ids)
|
||||
end
|
||||
|
Reference in New Issue
Block a user