mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
REFACTOR: Cleanup rake tasks based on feedback
Follow up to: [FEATURE: Create a rake task for destroying categories][1]
- `Discourse.system_user` is my friend
- Remove puts statements from rake tasks that don't return anything
- `for_each` is also my friend
- Use `human_users` to also exclude discobot
- Sort/format categories:list
[1]: 092eeb5ca3
This commit is contained in:
@ -39,8 +39,13 @@ end
|
||||
|
||||
desc "Output a list of categories"
|
||||
task "categories:list" => :environment do
|
||||
categories = Category.pluck(:id, :slug, :parent_category_id)
|
||||
categories = Category.where(parent_category_id: nil).order(:slug).pluck(:id, :slug)
|
||||
puts "id category-slug"
|
||||
puts "-- -----------------"
|
||||
categories.each do |c|
|
||||
puts "id: #{c[0]}, slug: #{c[1]}, parent: #{c[2]}"
|
||||
puts "#{c[0]} #{c[1]}"
|
||||
Category.where(parent_category_id: c[0]).order(:slug).pluck(:id, :slug).each do |s|
|
||||
puts " #{s[0]} #{s[1]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,47 +4,41 @@
|
||||
# content and users from your site.
|
||||
desc "Remove all topics in a category"
|
||||
task "destroy:topics", [:category, :parent_category] => :environment do |t, args|
|
||||
destroy_task = DestroyTask.new
|
||||
category = args[:category]
|
||||
parent_category = args[:parent_category]
|
||||
descriptive_slug = parent_category ? "#{parent_category}/#{category}" : category
|
||||
puts "Going to delete all topics in the #{descriptive_slug} category"
|
||||
destroy_task.destroy_topics(category, parent_category)
|
||||
DestroyTask.new.destroy_topics(category, parent_category)
|
||||
end
|
||||
|
||||
desc "Remove all topics in all categories"
|
||||
task "destroy:topics_all_categories" => :environment do
|
||||
destroy_task = DestroyTask.new
|
||||
puts "Going to delete all topics in all categories..."
|
||||
puts log = destroy_task.destroy_topics_all_categories
|
||||
DestroyTask.new.destroy_topics_all_categories
|
||||
end
|
||||
|
||||
desc "Remove all private messages"
|
||||
task "destroy:private_messages" => :environment do
|
||||
destroy_task = DestroyTask.new
|
||||
puts "Going to delete all private messages..."
|
||||
puts log = destroy_task.destroy_private_messages
|
||||
DestroyTask.new.destroy_private_messages
|
||||
end
|
||||
|
||||
desc "Destroy all groups"
|
||||
task "destroy:groups" => :environment do
|
||||
destroy_task = DestroyTask.new
|
||||
puts "Going to delete all non-default groups..."
|
||||
puts log = destroy_task.destroy_groups
|
||||
DestroyTask.new.destroy_groups
|
||||
end
|
||||
|
||||
desc "Destroy all non-admin users"
|
||||
task "destroy:users" => :environment do
|
||||
destroy_task = DestroyTask.new
|
||||
puts "Going to delete all non-admin users..."
|
||||
puts log = destroy_task.destroy_users
|
||||
DestroyTask.new.destroy_users
|
||||
end
|
||||
|
||||
desc "Destroy site stats"
|
||||
task "destroy:stats" => :environment do
|
||||
destroy_task = DestroyTask.new
|
||||
puts "Going to delete all site stats..."
|
||||
destroy_task.destroy_stats
|
||||
DestroyTask.new.destroy_stats
|
||||
end
|
||||
|
||||
# Example: rake destroy:categories[28,29,44,85]
|
||||
|
Reference in New Issue
Block a user