mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 01:31:35 +08:00

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.
27 lines
624 B
Ruby
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
|