BURs: make rename command move aliases/implications.

Make the tag rename command also move any aliases or implications from
the old tag to the new tag. Previously only the create alias command
moved aliases and implications.
This commit is contained in:
evazion
2020-11-12 17:12:09 -06:00
parent 9a287cd71f
commit 5844f16ed6
4 changed files with 50 additions and 52 deletions

View File

@@ -9,6 +9,8 @@ class TagMover
def move!
CurrentUser.scoped(user) do
move_aliases!
move_implications!
move_cosplay_tag!
move_tag_category!
move_artist!
@@ -57,6 +59,22 @@ class TagMover
end
end
def move_aliases!
old_tag.consequent_aliases.each do |tag_alias|
tag_alias.update!(consequent_name: new_tag.name)
end
end
def move_implications!
old_tag.antecedent_implications.each do |tag_implication|
tag_implication.update!(antecedent_name: new_tag.name)
end
old_tag.consequent_implications.each do |tag_implication|
tag_implication.update!(consequent_name: new_tag.name)
end
end
def move_cosplay_tag!
old_cosplay_tag = "#{old_tag.name}_(cosplay)"
new_cosplay_tag = "#{new_tag.name}_(cosplay)"

View File

@@ -16,7 +16,6 @@ class TagAlias < TagRelationship
def process!(approver)
update!(approver: approver, status: "processing")
move_aliases_and_implications
TagMover.new(antecedent_name, consequent_name, user: User.system).move!
update!(status: "active")
rescue Exception => e
@@ -34,35 +33,6 @@ class TagAlias < TagRelationship
end
end
def move_aliases_and_implications
aliases = TagAlias.where(["consequent_name = ?", antecedent_name])
aliases.each do |ta|
ta.consequent_name = self.consequent_name
success = ta.save
if !success && ta.errors.full_messages.join("; ") =~ /Cannot alias a tag to itself/
ta.destroy
end
end
implications = TagImplication.where(["antecedent_name = ?", antecedent_name])
implications.each do |ti|
ti.antecedent_name = self.consequent_name
success = ti.save
if !success && ti.errors.full_messages.join("; ") =~ /Cannot implicate a tag to itself/
ti.destroy
end
end
implications = TagImplication.where(["consequent_name = ?", antecedent_name])
implications.each do |ti|
ti.consequent_name = self.consequent_name
success = ti.save
if !success && ti.errors.full_messages.join("; ") =~ /Cannot implicate a tag to itself/
ti.destroy
end
end
end
def create_mod_action
alias_desc = %("tag alias ##{id}":[#{Rails.application.routes.url_helpers.tag_alias_path(self)}]: [[#{antecedent_name}]] -> [[#{consequent_name}]])