2018-05-08 04:35:12 -05:00
|
|
|
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)
|
|
|
|
|
2018-05-08 04:44:19 -05:00
|
|
|
if from_category.present? && to_category.present?
|
|
|
|
puts "Moving topics from #{from_category.slug} to #{to_category.slug}..."
|
|
|
|
Topic.where(category_id: from_category.id).update_all(category_id: to_category.id)
|
2018-05-08 04:35:12 -05:00
|
|
|
from_category.update_attribute(:topic_count, 0)
|
2018-05-08 04:44:19 -05:00
|
|
|
|
|
|
|
puts "Updating category stats..."
|
2018-05-08 04:35:12 -05:00
|
|
|
Category.update_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
puts "", "Done!", ""
|
|
|
|
end
|
2018-08-16 03:20:52 -05:00
|
|
|
|
|
|
|
task "categories:create_definition" => :environment do
|
|
|
|
puts "Creating category definitions"
|
|
|
|
puts
|
|
|
|
|
|
|
|
done = 0
|
|
|
|
current = 0
|
|
|
|
total = Category.count
|
|
|
|
|
|
|
|
Category.find_each do |c|
|
|
|
|
if c.topic_id.blank?
|
|
|
|
c.create_category_definition
|
|
|
|
done += 1
|
|
|
|
end
|
|
|
|
print_status(current += 1, total)
|
|
|
|
end
|
|
|
|
|
|
|
|
puts "", "category definition created for #{done} categories!", ""
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def print_status(current, max)
|
|
|
|
print "\r%9d / %d (%5.1f%%)" % [current, max, ((current.to_f / max.to_f) * 100).round(1)]
|
|
|
|
end
|