From 777055f96061ba07b35bb1c0c4f970fbe613c14d Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Thu, 16 Aug 2018 13:50:52 +0530 Subject: [PATCH] new rake task to create category definition --- lib/tasks/categories.rake | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/tasks/categories.rake b/lib/tasks/categories.rake index 407bf65f74..dd7ede720c 100644 --- a/lib/tasks/categories.rake +++ b/lib/tasks/categories.rake @@ -21,3 +21,27 @@ task "categories:move_topics", [:from_category, :to_category] => [:environment] puts "", "Done!", "" end + +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