From 78e14abb32db4b50fad7565bc770e77ba3dabeb4 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Thu, 16 Aug 2018 13:56:57 +0530 Subject: [PATCH] new rake task to bulk tag all topics in a category --- lib/tasks/tags.rake | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lib/tasks/tags.rake diff --git a/lib/tasks/tags.rake b/lib/tasks/tags.rake new file mode 100644 index 00000000000..3c10614a4b4 --- /dev/null +++ b/lib/tasks/tags.rake @@ -0,0 +1,26 @@ +task "tags:bulk_tag_category", [:tags, :category] => [:environment] do |_, args| + tags = args[:tags].split("|") + category_id = args[:category] + + if !tags || !category_id + puts 'ERROR: Expecting tags:bulk_tag_category["tag",category_id]' + exit 1 + end + + guardian = Guardian.new(Discourse.system_user) + category = Category.find(category_id) + + tagged = 0 + total = category.topics.count + + category.topics.find_each do |topic| + DiscourseTagging.tag_topic_by_names(topic, guardian, tags) + print_status(tagged += 1, total) + end + + puts "", "Done!", "" +end + +def print_status(current, max) + print "\r%9d / %d (%5.1f%%)" % [current, max, ((current.to_f / max.to_f) * 100).round(1)] +end