From 2e0534a66b4c0e4548ff95437f6be08134bddc9b Mon Sep 17 00:00:00 2001 From: r888888888 Date: Thu, 16 Nov 2017 12:00:54 -0800 Subject: [PATCH] fixes #3372 --- app/logical/alias_and_implication_importer.rb | 14 ++++++++++++-- app/models/tag.rb | 4 ++-- app/views/bulk_update_requests/_form.html.erb | 1 + test/unit/alias_and_implication_importer_test.rb | 14 ++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/logical/alias_and_implication_importer.rb b/app/logical/alias_and_implication_importer.rb index e081d1c2f..144210668 100644 --- a/app/logical/alias_and_implication_importer.rb +++ b/app/logical/alias_and_implication_importer.rb @@ -43,8 +43,12 @@ class AliasAndImplicationImporter elsif line =~ /^(?:mass update|updating|update|change) (.+?) -> (.*)$/i [:mass_update, $1, $2] + elsif line =~ /^category (\S+) -> (#{Tag.categories.regexp})/ + [:change_category, $1, $2] + elsif line.strip.empty? # do nothing + else raise "Unparseable line: #{line}" 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})" end - when :remove_alias, :remove_implication, :mass_update + when :remove_alias, :remove_implication, :mass_update, :change_category # okay else @@ -107,7 +111,13 @@ private tag_implication.destroy 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 raise "Unknown token: #{token[0]}" diff --git a/app/models/tag.rb b/app/models/tag.rb index 7d0b0ddb0..18d2f67a2 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -149,7 +149,7 @@ class Tag < ApplicationRecord end def update_category_cache - Cache.put("tc:#{Cache.hash(name)}", category, 1.hour) + Cache.put("tc:#{Cache.hash(name)}", category, 3.hours) end end @@ -221,7 +221,7 @@ class Tag < ApplicationRecord # next few lines if the category is changed. 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_category_cache_for_all end diff --git a/app/views/bulk_update_requests/_form.html.erb b/app/views/bulk_update_requests/_form.html.erb index ba4e76a31..2408ff459 100644 --- a/app/views/bulk_update_requests/_form.html.erb +++ b/app/views/bulk_update_requests/_form.html.erb @@ -12,6 +12,7 @@ unimply aaa -> bbb alias aaa -> bbb imply aaa -> bbb update aaa -> bbb +category tag_name -> category_name <%= text_area :bulk_update_request, :script, :size => "50x10" %> diff --git a/test/unit/alias_and_implication_importer_test.rb b/test/unit/alias_and_implication_importer_test.rb index 77b811841..d4f91f68f 100644 --- a/test/unit/alias_and_implication_importer_test.rb +++ b/test/unit/alias_and_implication_importer_test.rb @@ -12,6 +12,20 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase CurrentUser.ip_addr = nil 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 setup do @list = "create alias abc -> def\ncreate implication aaa -> bbb\n"