fixes #1473
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
class TagImplication < ActiveRecord::Base
|
||||
before_save :update_descendant_names
|
||||
after_save :update_descendant_names_for_parent
|
||||
after_destroy :update_descendant_names_for_parent
|
||||
after_destroy :update_posts_for_destroy
|
||||
belongs_to :creator, :class_name => "User"
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :normalize_names
|
||||
@@ -90,13 +92,41 @@ class TagImplication < ActiveRecord::Base
|
||||
q = q.where("antecedent_name = ?", params[:antecedent_name])
|
||||
end
|
||||
|
||||
if params[:consequent_name].present?
|
||||
q = q.where("consequent_name = ?", params[:consequent_name])
|
||||
end
|
||||
|
||||
q
|
||||
end
|
||||
end
|
||||
|
||||
module DeletionMethods
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
module ClassMethods
|
||||
def update_posts_for_destroy(creator_id, creator_ip_addr, tag_name)
|
||||
Post.tag_match("#{tag_name} status:any").find_each do |post|
|
||||
escaped_tag_name = Regexp.escape(tag_name)
|
||||
fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_tag_name}(?:\Z| )/, " ").strip
|
||||
CurrentUser.scoped(User.find(creator_id), creator_ip_addr) do
|
||||
post.disable_versioning = true
|
||||
post.update_attributes(
|
||||
:tag_string => fixed_tags
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_posts_for_destroy
|
||||
TagImplication.delay(:queue => "default").update_posts_for_destroy(CurrentUser.user.id, CurrentUser.ip_addr, consequent_name)
|
||||
end
|
||||
end
|
||||
|
||||
include DescendantMethods
|
||||
include ParentMethods
|
||||
extend SearchMethods
|
||||
include DeletionMethods
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.user.id
|
||||
@@ -105,7 +135,7 @@ class TagImplication < ActiveRecord::Base
|
||||
|
||||
def process!
|
||||
update_column(:status, "processing")
|
||||
update_posts
|
||||
update_posts_for_create
|
||||
update_column(:status, "active")
|
||||
update_descendant_names_for_parent
|
||||
rescue Exception => e
|
||||
@@ -120,7 +150,7 @@ class TagImplication < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def update_posts
|
||||
def update_posts_for_create
|
||||
Post.tag_match("#{antecedent_name} status:any").find_each do |post|
|
||||
escaped_antecedent_name = Regexp.escape(antecedent_name)
|
||||
fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{antecedent_name} #{descendant_names} ").strip
|
||||
|
||||
Reference in New Issue
Block a user