mirror of
https://github.com/discourse/discourse.git
synced 2025-03-06 03:09:43 +00:00
add a rake task to move all topics from one category to another
This commit is contained in:
parent
858a266031
commit
62c266f987
20
lib/tasks/categories.rake
Normal file
20
lib/tasks/categories.rake
Normal file
@ -0,0 +1,20 @@
|
||||
task "categories:move_topics", [:from_category, :to_category] => [:environment] do |_, args|
|
||||
from_category_id = args[:from_category]
|
||||
to_category_id = args[:to_category]
|
||||
|
||||
if !from_category_id || !to_category_id
|
||||
puts "ERROR: Expecting categories:move_topics[from_category_id,to_category_id]"
|
||||
exit 1
|
||||
end
|
||||
|
||||
from_category = Category.find(from_category_id)
|
||||
to_category = Category.find(to_category_id)
|
||||
|
||||
if from_category && to_category
|
||||
Topic.where(category_id: from_category_id).update_all(category_id: to_category_id)
|
||||
from_category.update_attribute(:topic_count, 0)
|
||||
Category.update_stats
|
||||
end
|
||||
|
||||
puts "", "Done!", ""
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user