Fixes #1121, rename Post#annihilate to Post#expunge

This commit is contained in:
albert
2013-04-08 13:44:43 -04:00
parent 9a337346df
commit c540c4f891
10 changed files with 98 additions and 52 deletions

View File

@@ -31,7 +31,6 @@ class Post < ActiveRecord::Base
has_many :disapprovals, :class_name => "PostDisapproval"
validates_uniqueness_of :md5
validates_presence_of :parent, :if => lambda {|rec| !rec.parent_id.nil?}
# validate :validate_parent_does_not_have_a_parent
attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at, :parent_id, :as => [:member, :builder, :privileged, :platinum, :contributor, :janitor, :moderator, :admin, :default]
attr_accessible :is_rating_locked, :is_note_locked, :as => [:builder, :contributor, :janitor, :moderator, :admin]
attr_accessible :is_status_locked, :as => [:admin]
@@ -251,7 +250,6 @@ class Post < ActiveRecord::Base
self.is_deleted = false
self.approver_id = CurrentUser.id
save!
# ModAction.create(:description => "approved post ##{id}")
end
def disapproved_by?(user)
@@ -678,13 +676,13 @@ class Post < ActiveRecord::Base
# A parent has many children. A child belongs to a parent.
# A parent cannot have a parent.
#
# After deleting a child:
# After expunging a child:
# - Move favorites to parent.
# - Does the parent have any active children?
# - Yes: Done.
# - No: Update parent's has_children flag to false.
#
# After deleting a parent:
# After expunging a parent:
# - Move favorites to the first child.
# - Reparent all active children to the first active child.
@@ -756,15 +754,18 @@ class Post < ActiveRecord::Base
end
module DeletionMethods
def annihilate!
def expunge!
if is_status_locked?
self.errors.add(:is_status_locked, "; cannot delete post")
return false
end
ModAction.create(:description => "permanently deleted post ##{id}")
decrement_tag_post_counts
delete!(:without_mod_action => true)
give_favorites_to_parent
update_children_on_destroy
update_parent_on_destroy
decrement_tag_post_counts
destroy
end
@@ -779,11 +780,6 @@ class Post < ActiveRecord::Base
update_column(:is_pending, false)
update_column(:is_flagged, false)
update_column(:is_banned, true) if options[:ban]
give_favorites_to_parent
update_children_on_destroy
update_parent_on_destroy
# decrement_tag_post_counts
update_column(:parent_id, nil)
unless options[:without_mod_action]
ModAction.create(:description => "deleted post ##{id}")
@@ -801,7 +797,6 @@ class Post < ActiveRecord::Base
self.approver_id = CurrentUser.id
save
Post.expire_cache_for_all(tag_array)
update_parent_on_save
ModAction.create(:description => "undeleted post ##{id}")
end
end