diff --git a/app/logical/bulk_update_request_processor.rb b/app/logical/bulk_update_request_processor.rb index 836ceb43f..9601e95ef 100644 --- a/app/logical/bulk_update_request_processor.rb +++ b/app/logical/bulk_update_request_processor.rb @@ -32,6 +32,8 @@ class BulkUpdateRequestProcessor [:mass_update, $1, $2] when /\Acategory (\S+) -> (#{Tag.categories.regexp})\z/i [:change_category, Tag.normalize_name($1), $2.downcase] + when /\Anuke (\S+)\z/i + [:nuke, $1] else [:invalid_line, line] end @@ -90,7 +92,7 @@ class BulkUpdateRequestProcessor errors[:base] << "Can't rename #{args[0]} -> #{args[1]} (the '#{args[0]}' tag doesn't exist)" end - when :mass_update + when :mass_update, :nuke # okay when :invalid_line @@ -129,6 +131,9 @@ class BulkUpdateRequestProcessor when :mass_update TagBatchChangeJob.perform_later(args[0], args[1]) + when :nuke + TagBatchChangeJob.perform_later(args[0], "-#{args[0]}") + when :rename TagRenameJob.perform_later(args[0], args[1]) @@ -152,6 +157,8 @@ class BulkUpdateRequestProcessor when :mass_update tags = PostQueryBuilder.new(args[0]).tags + PostQueryBuilder.new(args[1]).tags tags.reject(&:negated).reject(&:optional).reject(&:wildcard).map(&:name) + when :nuke + PostQueryBuilder.new(args[0]).tags.map(&:name) when :change_category args[0] end @@ -181,6 +188,14 @@ class BulkUpdateRequestProcessor "#{command.to_s.tr("_", " ")} [[#{args[0]}]] -> [[#{args[1]}]]" when :mass_update "mass update {{#{args[0]}}} -> #{args[1]}" + when :nuke + query = PostQueryBuilder.new(args[0]) + + if query.is_simple_tag? + "nuke [[#{args[0]}]]" + else + "nuke {{#{args[0]}}}" + end when :change_category "category [[#{args[0]}]] -> #{args[1]}" else diff --git a/test/unit/bulk_update_request_test.rb b/test/unit/bulk_update_request_test.rb index 3bd7f7486..77031626f 100644 --- a/test/unit/bulk_update_request_test.rb +++ b/test/unit/bulk_update_request_test.rb @@ -252,6 +252,24 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase end end + context "the nuke command" do + should "remove tags" do + @p1 = create(:post, tag_string: "foo") + @p2 = create(:post, tag_string: "bar") + @bur = create_bur!("nuke foo", @admin) + + assert_equal("tagme", @p1.reload.tag_string) + end + + should "remove pools" do + @pool = create(:pool) + @post = create(:post, tag_string: "bar pool:#{@pool.id}") + @bur = create_bur!("nuke pool:#{@pool.id}", @admin) + + assert_equal([], @pool.post_ids) + end + end + context "that contains a mass update followed by an alias" do should "make the alias take effect after the mass update" do @p1 = create(:post, tag_string: "maid_dress")