Files
discourse/spec/support/rake_context.rb
Ted Johansson 42c4427cb1 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.
2025-03-04 17:29:38 +08:00

27 lines
624 B
Ruby

# frozen_string_literal: true
require "rake"
shared_context "in a rake task" do
subject { rake[task_name] }
let(:rake) { Rake::Application.new }
let(:task_name) { self.class.top_level_description }
let(:task_path) { "lib/tasks/#{task_name.split(":").first}" }
def loaded_files_excluding_current_rake_file
$".reject { |file| file == Rails.root.join("#{task_path}.rake").to_s }
end
before do
Rake.application = rake
Rake.application.rake_require(
task_path,
[Rails.root.to_s],
loaded_files_excluding_current_rake_file,
)
Rake::Task.define_task(:environment)
end
end