BURs: add nuke command.
Usage: * `nuke touhou` * `nuke pool:Disgustingly_Adorable` Add a command for nuking tags. `nuke A` is a shortcut for `mass update A -> -A`. This means it also works for pools.
This commit is contained in:
@@ -32,6 +32,8 @@ class BulkUpdateRequestProcessor
|
|||||||
[:mass_update, $1, $2]
|
[:mass_update, $1, $2]
|
||||||
when /\Acategory (\S+) -> (#{Tag.categories.regexp})\z/i
|
when /\Acategory (\S+) -> (#{Tag.categories.regexp})\z/i
|
||||||
[:change_category, Tag.normalize_name($1), $2.downcase]
|
[:change_category, Tag.normalize_name($1), $2.downcase]
|
||||||
|
when /\Anuke (\S+)\z/i
|
||||||
|
[:nuke, $1]
|
||||||
else
|
else
|
||||||
[:invalid_line, line]
|
[:invalid_line, line]
|
||||||
end
|
end
|
||||||
@@ -90,7 +92,7 @@ class BulkUpdateRequestProcessor
|
|||||||
errors[:base] << "Can't rename #{args[0]} -> #{args[1]} (the '#{args[0]}' tag doesn't exist)"
|
errors[:base] << "Can't rename #{args[0]} -> #{args[1]} (the '#{args[0]}' tag doesn't exist)"
|
||||||
end
|
end
|
||||||
|
|
||||||
when :mass_update
|
when :mass_update, :nuke
|
||||||
# okay
|
# okay
|
||||||
|
|
||||||
when :invalid_line
|
when :invalid_line
|
||||||
@@ -129,6 +131,9 @@ class BulkUpdateRequestProcessor
|
|||||||
when :mass_update
|
when :mass_update
|
||||||
TagBatchChangeJob.perform_later(args[0], args[1])
|
TagBatchChangeJob.perform_later(args[0], args[1])
|
||||||
|
|
||||||
|
when :nuke
|
||||||
|
TagBatchChangeJob.perform_later(args[0], "-#{args[0]}")
|
||||||
|
|
||||||
when :rename
|
when :rename
|
||||||
TagRenameJob.perform_later(args[0], args[1])
|
TagRenameJob.perform_later(args[0], args[1])
|
||||||
|
|
||||||
@@ -152,6 +157,8 @@ class BulkUpdateRequestProcessor
|
|||||||
when :mass_update
|
when :mass_update
|
||||||
tags = PostQueryBuilder.new(args[0]).tags + PostQueryBuilder.new(args[1]).tags
|
tags = PostQueryBuilder.new(args[0]).tags + PostQueryBuilder.new(args[1]).tags
|
||||||
tags.reject(&:negated).reject(&:optional).reject(&:wildcard).map(&:name)
|
tags.reject(&:negated).reject(&:optional).reject(&:wildcard).map(&:name)
|
||||||
|
when :nuke
|
||||||
|
PostQueryBuilder.new(args[0]).tags.map(&:name)
|
||||||
when :change_category
|
when :change_category
|
||||||
args[0]
|
args[0]
|
||||||
end
|
end
|
||||||
@@ -181,6 +188,14 @@ class BulkUpdateRequestProcessor
|
|||||||
"#{command.to_s.tr("_", " ")} [[#{args[0]}]] -> [[#{args[1]}]]"
|
"#{command.to_s.tr("_", " ")} [[#{args[0]}]] -> [[#{args[1]}]]"
|
||||||
when :mass_update
|
when :mass_update
|
||||||
"mass update {{#{args[0]}}} -> #{args[1]}"
|
"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
|
when :change_category
|
||||||
"category [[#{args[0]}]] -> #{args[1]}"
|
"category [[#{args[0]}]] -> #{args[1]}"
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -252,6 +252,24 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
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
|
context "that contains a mass update followed by an alias" do
|
||||||
should "make the alias take effect after the mass update" do
|
should "make the alias take effect after the mass update" do
|
||||||
@p1 = create(:post, tag_string: "maid_dress")
|
@p1 = create(:post, tag_string: "maid_dress")
|
||||||
|
|||||||
Reference in New Issue
Block a user