From 3df404dbd91385fec1e11d3805a65485211d14c0 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 17 Nov 2017 11:57:05 -0600 Subject: [PATCH] Fix #3380: Change category on Bulk Update Requests are broken. --- app/helpers/bulk_update_requests_helper.rb | 11 ++++++++++- app/models/bulk_update_request.rb | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/helpers/bulk_update_requests_helper.rb b/app/helpers/bulk_update_requests_helper.rb index 7dde42837..95a762a27 100644 --- a/app/helpers/bulk_update_requests_helper.rb +++ b/app/helpers/bulk_update_requests_helper.rb @@ -15,6 +15,10 @@ module BulkUpdateRequestsHelper when :remove_implication TagImplication.where(antecedent_name: antecedent, consequent_name: consequent, status: "deleted").exists? || !TagImplication.where(antecedent_name: antecedent, consequent_name: consequent).exists? + when :change_category + tag, category = antecedent, consequent + Tag.where(name: tag, category: Tag.categories.value_for(category)).exists? + else false end @@ -38,7 +42,7 @@ module BulkUpdateRequestsHelper def script_with_line_breaks(script) escaped_script = AliasAndImplicationImporter.tokenize(script).map do |cmd, arg1, arg2| case cmd - when :create_alias, :create_implication, :remove_alias, :remove_implication, :mass_update + when :create_alias, :create_implication, :remove_alias, :remove_implication, :mass_update, :change_category if approved?(cmd, arg1, arg2) btag = '' etag = '' @@ -79,6 +83,11 @@ module BulkUpdateRequestsHelper when :mass_update "#{btag}mass update " + link_to(arg1, posts_path(:tags => arg1)) + " -> " + link_to(arg2, posts_path(:tags => arg2)) + "#{etag}" + when :change_category + arg1_count = Tag.find_by_name(arg1).try(:post_count).to_i + + "#{btag}category " + link_to(arg1, posts_path(:tags => arg1)) + " (#{arg1_count}) -> (#{arg2})#{etag}" + end end.join("\n") diff --git a/app/models/bulk_update_request.rb b/app/models/bulk_update_request.rb index a771fb420..3378fa148 100644 --- a/app/models/bulk_update_request.rb +++ b/app/models/bulk_update_request.rb @@ -178,6 +178,9 @@ class BulkUpdateRequest < ApplicationRecord when :mass_update "mass update {{#{token[1]}}} -> #{token[2]}" + when :change_category + "category [[#{token[1]}]] -> #{token[2]}" + else raise "Unknown token: #{token[0]}" end