FEATURE: Support append when bulk tagging via rake (#9978)

New argument option for the `tags:bulk_tag_category` rake task.
Backwards compatible - defaults to false (no append) if no argument given.
This commit is contained in:
Joshua Rosenfeld 2020-06-04 09:33:48 -04:00 committed by GitHub
parent 87673e6571
commit 76af25f753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,10 @@
# frozen_string_literal: true
task "tags:bulk_tag_category", [:tags, :category] => [:environment] do |_, args|
task "tags:bulk_tag_category", [:tags, :category, :append] => [:environment] do |_, args|
args.with_defaults(append: false)
tags = args[:tags].split("|")
category_id = args[:category]
append = args[:append]
if !tags || !category_id
puts 'ERROR: Expecting tags:bulk_tag_category["tag",category_id]'
@ -16,7 +18,7 @@ task "tags:bulk_tag_category", [:tags, :category] => [:environment] do |_, args|
total = category.topics.count
category.topics.find_each do |topic|
DiscourseTagging.tag_topic_by_names(topic, guardian, tags)
DiscourseTagging.tag_topic_by_names(topic, guardian, tags, append: append)
print_status(tagged += 1, total)
end