fix infinite loop
This commit is contained in:
@@ -7,6 +7,7 @@ class TagAlias < ActiveRecord::Base
|
|||||||
validates_presence_of :creator_id, :antecedent_name, :consequent_name
|
validates_presence_of :creator_id, :antecedent_name, :consequent_name
|
||||||
validates_uniqueness_of :antecedent_name
|
validates_uniqueness_of :antecedent_name
|
||||||
validate :absence_of_transitive_relation
|
validate :absence_of_transitive_relation
|
||||||
|
validate :antecedent_and_consequent_are_different
|
||||||
belongs_to :creator, :class_name => "User"
|
belongs_to :creator, :class_name => "User"
|
||||||
belongs_to :forum_topic
|
belongs_to :forum_topic
|
||||||
attr_accessible :antecedent_name, :consequent_name, :forum_topic_id, :status
|
attr_accessible :antecedent_name, :consequent_name, :forum_topic_id, :status
|
||||||
@@ -117,23 +118,40 @@ class TagAlias < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def antecedent_and_consequent_are_different
|
||||||
|
normalize_names
|
||||||
|
if antecedent_name == consequent_name
|
||||||
|
self.errors[:base] << "Cannot alias a tag to itself"
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def move_aliases_and_implications
|
def move_aliases_and_implications
|
||||||
aliases = TagAlias.where(["consequent_name = ?", antecedent_name])
|
aliases = TagAlias.where(["consequent_name = ?", antecedent_name])
|
||||||
aliases.each do |ta|
|
aliases.each do |ta|
|
||||||
ta.consequent_name = self.consequent_name
|
ta.consequent_name = self.consequent_name
|
||||||
ta.save
|
success = ta.save
|
||||||
|
if !success && ta.errors.full_messages.join("; ") =~ /Cannot alias a tag to itself/
|
||||||
|
ta.destroy
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
implications = TagImplication.where(["antecedent_name = ?", antecedent_name])
|
implications = TagImplication.where(["antecedent_name = ?", antecedent_name])
|
||||||
implications.each do |ti|
|
implications.each do |ti|
|
||||||
ti.antecedent_name = self.consequent_name
|
ti.antecedent_name = self.consequent_name
|
||||||
ti.save
|
success = ti.save
|
||||||
|
if !success && ti.errors.full_messages.join("; ") =~ /Cannot implicate a tag to itself/
|
||||||
|
ti.destroy
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
implications = TagImplication.where(["consequent_name = ?", antecedent_name])
|
implications = TagImplication.where(["consequent_name = ?", antecedent_name])
|
||||||
implications.each do |ti|
|
implications.each do |ti|
|
||||||
ti.consequent_name = self.consequent_name
|
ti.consequent_name = self.consequent_name
|
||||||
ti.save
|
success = ti.save
|
||||||
|
if !success && ti.errors.full_messages.join("; ") =~ /Cannot implicate a tag to itself/
|
||||||
|
ti.destroy
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class TagImplication < ActiveRecord::Base
|
|||||||
validate :absence_of_circular_relation
|
validate :absence_of_circular_relation
|
||||||
validate :antecedent_is_not_aliased
|
validate :antecedent_is_not_aliased
|
||||||
validate :consequent_is_not_aliased
|
validate :consequent_is_not_aliased
|
||||||
|
validate :antecedent_and_consequent_are_different
|
||||||
attr_accessible :antecedent_name, :consequent_name, :descendant_names, :forum_topic_id, :status, :forum_topic
|
attr_accessible :antecedent_name, :consequent_name, :descendant_names, :forum_topic_id, :status, :forum_topic
|
||||||
|
|
||||||
module DescendantMethods
|
module DescendantMethods
|
||||||
@@ -144,6 +145,14 @@ class TagImplication < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def antecedent_and_consequent_are_different
|
||||||
|
normalize_names
|
||||||
|
if antecedent_name == consequent_name
|
||||||
|
self.errors[:base] << "Cannot implicate a tag to itself"
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def update_posts
|
def update_posts
|
||||||
Post.without_timeout do
|
Post.without_timeout do
|
||||||
Post.raw_tag_match(antecedent_name).find_each do |post|
|
Post.raw_tag_match(antecedent_name).find_each do |post|
|
||||||
|
|||||||
Reference in New Issue
Block a user