fixes #2731: Expunged posts should clear favorite groups

This commit is contained in:
Albert Yi
2016-11-01 13:44:36 -07:00
parent cb1c694074
commit 91793fff82
4 changed files with 92 additions and 0 deletions

View File

@@ -18,6 +18,11 @@ class FavoriteGroup < ActiveRecord::Base
where("favorite_groups.creator_id = ?", user_id)
end
def for_post(post_id)
regexp = "(^#{post_id}$|^#{post_id} | #{post_id}$| #{post_id} )"
where("favorite_groups.post_ids ~ ?", regexp)
end
def named(name)
where("lower(name) = ?", name.to_s.mb_chars.downcase.strip)
end

View File

@@ -959,6 +959,12 @@ class Post < ActiveRecord::Base
groups.uniq
end
end
def remove_from_fav_groups
FavoriteGroup.for_post(id).find_each do |group|
group.remove!(self)
end
end
end
module UploaderMethods
@@ -1313,6 +1319,7 @@ class Post < ActiveRecord::Base
update_children_on_destroy
decrement_tag_post_counts
remove_from_all_pools
remove_from_fav_groups
destroy
update_parent_on_destroy
end