Fix race condition when auto-moving implications

This commit is contained in:
Toks
2014-07-15 01:17:15 -04:00
parent ad8fa463b1
commit 20cceda4e5

View File

@@ -145,8 +145,14 @@ class TagAlias < ActiveRecord::Base
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
if !success
case ti.errors.full_messages.join("; ")
when /Cannot implicate a tag to itself/
ti.destroy
when /Consequent tag must not be aliased to another tag/
ti.consequent_name = TagAlias.to_aliased(ti.consequent_name).first
ti.save
end
end
end
@@ -154,8 +160,14 @@ class TagAlias < ActiveRecord::Base
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
if !success
case ti.errors.full_messages.join("; ")
when /Cannot implicate a tag to itself/
ti.destroy
when /Antecedent tag must not be aliased to another tag/
ti.antecedent_name = TagAlias.to_aliased(ti.antecedent_name).first
ti.save
end
end
end
end