mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 12:43:39 +08:00
new rake task to bulk tag all topics in a category
This commit is contained in:
parent
777055f960
commit
78e14abb32
26
lib/tasks/tags.rake
Normal file
26
lib/tasks/tags.rake
Normal file
|
@ -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
|
Loading…
Reference in New Issue
Block a user