Fix #4899: Alias fails when implication already exists.

This commit is contained in:
evazion
2021-10-27 00:23:11 -05:00
parent eddff747d6
commit e697d1886d
2 changed files with 43 additions and 7 deletions

View File

@@ -86,12 +86,24 @@ class TagMover
# Transfer any implications from the old tag to the new tag.
def move_implications!
# When renaming A to B, remove any existing A -> ??? implications and
# replace them with B -> ???, unless they already exist.
old_tag.antecedent_implications.each do |tag_implication|
tag_implication.update!(antecedent_name: new_tag.name)
tag_implication.update!(status: :deleted)
unless TagImplication.active.exists?(antecedent_name: new_tag.name, consequent_name: tag_implication.consequent_name)
TagImplication.create!(antecedent_name: new_tag.name, consequent_name: tag_implication.consequent_name, creator: user, approver: user, status: :active)
end
end
# When renaming A to B, remove any existing ??? -> A implications and
# replace them with ??? -> B, unless they already exist.
old_tag.consequent_implications.each do |tag_implication|
tag_implication.update!(consequent_name: new_tag.name)
tag_implication.update!(status: :deleted)
unless TagImplication.active.exists?(antecedent_name: tag_implication.antecedent_name, consequent_name: new_tag.name)
TagImplication.create!(antecedent_name: tag_implication.antecedent_name, consequent_name: new_tag.name, creator: user, approver: user, status: :active)
end
end
end