DEV: Add rake task to bulk delete posts (#31642)

Same as #31576, but in that one I added some support files that turned out to be unnecessary and broke the build. So this is the re-do. 🙏
This commit is contained in:
Ted Johansson
2025-03-05 09:31:23 +08:00
committed by GitHub
parent 503645dc34
commit 828fcb1ad3
5 changed files with 82 additions and 0 deletions

View File

@ -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