Fix #4629: Tag renames/aliases should also modify pool descriptions.
This commit is contained in:
@@ -139,9 +139,10 @@ class TagMover
|
||||
User.rewrite_blacklists!(old_tag.name, new_tag.name)
|
||||
end
|
||||
|
||||
# Update any wiki pages linking to the old tag, to link to the new tag.
|
||||
# Update any wiki pages or pools linking to the old tag, to link to the new tag.
|
||||
def rewrite_wiki_links!
|
||||
WikiPage.rewrite_wiki_links!(old_tag.name, new_tag.name)
|
||||
Pool.rewrite_wiki_links!(old_tag.name, new_tag.name)
|
||||
end
|
||||
|
||||
# Merge two artist entries, copying everything from the old entry to the new
|
||||
|
||||
@@ -254,4 +254,10 @@ class Pool < ApplicationRecord
|
||||
errors.add(:name, "cannot contain only digits")
|
||||
end
|
||||
end
|
||||
|
||||
def self.rewrite_wiki_links!(old_name, new_name)
|
||||
Pool.linked_to(old_name).each do |pool|
|
||||
pool.lock!.update!(description: DText.rewrite_wiki_links(pool.description, old_name, new_name))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -212,12 +212,8 @@ class WikiPage < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.rewrite_wiki_links!(old_name, new_name)
|
||||
broken_wikis = WikiPage.linked_to(old_name)
|
||||
|
||||
broken_wikis.each do |wiki|
|
||||
wiki.lock!
|
||||
wiki.body = DText.rewrite_wiki_links(wiki.body, old_name, new_name)
|
||||
wiki.save!
|
||||
WikiPage.linked_to(old_name).each do |wiki|
|
||||
wiki.lock!.update!(body: DText.rewrite_wiki_links(wiki.body, old_name, new_name))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -217,6 +217,15 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
|
||||
assert_equal("foo [[bbb]] bar", @wiki.reload.body)
|
||||
end
|
||||
|
||||
should "rewrite links in pool descriptions to use the new tag" do
|
||||
@pool = create(:pool, description: "foo [[aaa]] bar")
|
||||
|
||||
TagAlias.approve!(antecedent_name: "aaa", consequent_name: "bbb", approver: @admin)
|
||||
perform_enqueued_jobs
|
||||
|
||||
assert_equal("foo [[bbb]] bar", @pool.reload.description)
|
||||
end
|
||||
end
|
||||
|
||||
context "when the tags have artist entries" do
|
||||
|
||||
Reference in New Issue
Block a user