fixes #1092, fixes naming for tag alias|implication requests, includes fix method
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class TagAlias < ActiveRecord::Base
|
||||
before_save :ensure_tags_exist
|
||||
after_save :clear_all_cache
|
||||
after_save :ensure_category_consistency
|
||||
after_destroy :clear_all_cache
|
||||
before_validation :initialize_creator, :on => :create
|
||||
validates_presence_of :creator_id, :antecedent_name, :consequent_name
|
||||
@@ -13,6 +13,10 @@ class TagAlias < ActiveRecord::Base
|
||||
def name_matches(name)
|
||||
where("(antecedent_name like ? escape E'\\\\' or consequent_name like ? escape E'\\\\')", name.downcase.to_escaped_for_sql_like, name.downcase.to_escaped_for_sql_like)
|
||||
end
|
||||
|
||||
def active
|
||||
where("status = ?", "active")
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = scoped
|
||||
@@ -70,6 +74,7 @@ class TagAlias < ActiveRecord::Base
|
||||
def process!
|
||||
update_column(:status, "processing")
|
||||
clear_all_cache
|
||||
ensure_category_consistency
|
||||
update_posts
|
||||
update_column(:status, "active")
|
||||
rescue Exception => e
|
||||
@@ -105,8 +110,13 @@ class TagAlias < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_tags_exist
|
||||
Tag.find_or_create_by_name(antecedent_name)
|
||||
Tag.find_or_create_by_name(consequent_name)
|
||||
end
|
||||
|
||||
def ensure_category_consistency
|
||||
if antecedent_tag && consequent_tag && antecedent_tag.category != consequent_tag.category
|
||||
if antecedent_tag.category != consequent_tag.category
|
||||
consequent_tag.update_attribute(:category, antecedent_tag.category)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user