BURs: fix tags field not finding all BURs with that tag.
Fix the Tags field in the BUR search form not finding all BURs mentioning that tag. Specifically, tags that were part of a mass update, and that were prefixed with `~` or `-` (OR tags and NOT tags), weren't indexed as tags affected by the BUR. This requires re-running script/fixes/064_initialize_bulk_update_request_tags.rb to fix old BURs.
This commit is contained in:
@@ -196,18 +196,17 @@ class BulkUpdateRequestProcessor
|
||||
end
|
||||
end
|
||||
|
||||
# The list of tags in the script. Used for search BURs by tag.
|
||||
# @return [Tag] the list of tags
|
||||
# The list of tags in the script. Used to search BURs by tag.
|
||||
# @return [Array<String>] the list of tags
|
||||
def affected_tags
|
||||
commands.flat_map do |command, *args|
|
||||
case command
|
||||
when :create_alias, :remove_alias, :create_implication, :remove_implication, :rename
|
||||
[args[0], args[1]]
|
||||
when :mass_update
|
||||
tags = PostQueryBuilder.new(args[0]).tags + PostQueryBuilder.new(args[1]).tags
|
||||
tags.reject(&:negated).reject(&:optional).reject(&:wildcard).map(&:name)
|
||||
PostQuery.new(args[0]).tag_names + PostQuery.new(args[1]).tag_names
|
||||
when :nuke
|
||||
PostQueryBuilder.new(args[0]).tags.map(&:name)
|
||||
PostQuery.new(args[0]).tag_names
|
||||
when :change_category
|
||||
args[0]
|
||||
end
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require_relative "../../config/environment"
|
||||
require_relative "base"
|
||||
|
||||
BulkUpdateRequest.transaction do
|
||||
with_confirmation do
|
||||
BulkUpdateRequest.find_each do |request|
|
||||
request.tags = request.processor.affected_tags
|
||||
request.save!(validate: false)
|
||||
puts "bur id=#{request.id} tags=#{request.tags}"
|
||||
|
||||
if request.changed?
|
||||
request.save!(validate: false)
|
||||
puts "bur id=#{request.id} added_tags=#{request.tags - request.tags_before_last_save} removed_tags=#{request.tags_before_last_save - request.tags}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -546,7 +546,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
assert_equal(%w[aaa bbb], @bur.tags)
|
||||
|
||||
@bur.update!(script: @script)
|
||||
assert_equal(%w(000 111 222 333 444 aaa bbb ccc ddd eee iii), @bur.tags)
|
||||
assert_equal(%w(000 111 222 333 444 555 aaa bbb ccc ddd eee fff ggg iii), @bur.tags)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user