fixes #3372
This commit is contained in:
@@ -43,8 +43,12 @@ class AliasAndImplicationImporter
|
|||||||
elsif line =~ /^(?:mass update|updating|update|change) (.+?) -> (.*)$/i
|
elsif line =~ /^(?:mass update|updating|update|change) (.+?) -> (.*)$/i
|
||||||
[:mass_update, $1, $2]
|
[:mass_update, $1, $2]
|
||||||
|
|
||||||
|
elsif line =~ /^category (\S+) -> (#{Tag.categories.regexp})/
|
||||||
|
[:change_category, $1, $2]
|
||||||
|
|
||||||
elsif line.strip.empty?
|
elsif line.strip.empty?
|
||||||
# do nothing
|
# do nothing
|
||||||
|
|
||||||
else
|
else
|
||||||
raise "Unparseable line: #{line}"
|
raise "Unparseable line: #{line}"
|
||||||
end
|
end
|
||||||
@@ -66,7 +70,7 @@ class AliasAndImplicationImporter
|
|||||||
raise "Error: #{tag_implication.errors.full_messages.join("; ")} (create implication #{tag_implication.antecedent_name} -> #{tag_implication.consequent_name})"
|
raise "Error: #{tag_implication.errors.full_messages.join("; ")} (create implication #{tag_implication.antecedent_name} -> #{tag_implication.consequent_name})"
|
||||||
end
|
end
|
||||||
|
|
||||||
when :remove_alias, :remove_implication, :mass_update
|
when :remove_alias, :remove_implication, :mass_update, :change_category
|
||||||
# okay
|
# okay
|
||||||
|
|
||||||
else
|
else
|
||||||
@@ -107,7 +111,13 @@ private
|
|||||||
tag_implication.destroy
|
tag_implication.destroy
|
||||||
|
|
||||||
when :mass_update
|
when :mass_update
|
||||||
Delayed::Job.enqueue(Moderator::TagBatchChange.new(token[1], token[2], CurrentUser.user, CurrentUser.ip_addr), :queue => "default")
|
Delayed::Job.enqueue(Moderator::TagBatchChange.new(token[1], token[2], CurrentUser.id, CurrentUser.ip_addr), :queue => "default")
|
||||||
|
|
||||||
|
when :change_category
|
||||||
|
tag = Tag.find_by_name(token[1])
|
||||||
|
tag.category = Tag.categories.value_for(token[2])
|
||||||
|
tag.save
|
||||||
|
tag.update_category_cache_for_all
|
||||||
|
|
||||||
else
|
else
|
||||||
raise "Unknown token: #{token[0]}"
|
raise "Unknown token: #{token[0]}"
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ class Tag < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update_category_cache
|
def update_category_cache
|
||||||
Cache.put("tc:#{Cache.hash(name)}", category, 1.hour)
|
Cache.put("tc:#{Cache.hash(name)}", category, 3.hours)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ class Tag < ApplicationRecord
|
|||||||
# next few lines if the category is changed.
|
# next few lines if the category is changed.
|
||||||
tag.update_category_cache
|
tag.update_category_cache
|
||||||
|
|
||||||
if category_id != tag.category && !tag.is_locked? && (CurrentUser.is_builder? || tag.post_count <= 50)
|
if category_id != tag.category && !tag.is_locked? && ((CurrentUser.is_builder? && tag.post_count < 10_000) || tag.post_count <= 50)
|
||||||
tag.update_column(:category, category_id)
|
tag.update_column(:category, category_id)
|
||||||
tag.update_category_cache_for_all
|
tag.update_category_cache_for_all
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ unimply aaa -> bbb
|
|||||||
alias aaa -> bbb
|
alias aaa -> bbb
|
||||||
imply aaa -> bbb
|
imply aaa -> bbb
|
||||||
update aaa -> bbb
|
update aaa -> bbb
|
||||||
|
category tag_name -> category_name
|
||||||
</pre>
|
</pre>
|
||||||
<%= text_area :bulk_update_request, :script, :size => "50x10" %>
|
<%= text_area :bulk_update_request, :script, :size => "50x10" %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -12,6 +12,20 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
|
|||||||
CurrentUser.ip_addr = nil
|
CurrentUser.ip_addr = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "category command" do
|
||||||
|
setup do
|
||||||
|
@tag = Tag.find_or_create_by_name("hello")
|
||||||
|
@list = "category hello -> artist\n"
|
||||||
|
@importer = AliasAndImplicationImporter.new(@list, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "work" do
|
||||||
|
@importer.process!
|
||||||
|
@tag.reload
|
||||||
|
assert_equal(Tag.categories.value_for("artist"), @tag.category)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "given a valid list" do
|
context "given a valid list" do
|
||||||
setup do
|
setup do
|
||||||
@list = "create alias abc -> def\ncreate implication aaa -> bbb\n"
|
@list = "create alias abc -> def\ncreate implication aaa -> bbb\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user