added post pruner, added mod action notifications when approving/deleting posts

This commit is contained in:
albert
2011-09-30 11:34:41 -04:00
parent f5e1139eec
commit 3c1a25f6d8
6 changed files with 104 additions and 2 deletions

View File

@@ -0,0 +1,47 @@
class PostPruner
attr_reader :admin
def initialize
@admin = User.where(:level => User::Levels::ADMIN).first
end
def prune!
prune_pending!
prune_flagged!
prune_mod_actions!
end
protected
def prune_pending!
CurrentUser.scoped(admin, "127.0.0.1") do
Post.where("is_deleted = ? and is_pending = ? and created_at < ?", false, true, 3.days.ago).each do |post|
begin
post.flag!("Unapproved in three days")
rescue PostFlag::Error
# swallow
end
post.delete!
end
end
end
def prune_flagged!
CurrentUser.scoped(admin, "127.0.0.1") do
Post.where("is_deleted = ? and is_flagged = ?", false, true).each do |post|
if post.flags.unresolved.old.any?
begin
post.flag!("Unapproved in three days after returning to moderation queue")
rescue PostFlag::Error
# swallow
end
post.delete!
end
end
end
end
def prune_mod_actions!
ModAction.destroy_all(["creator_id = ? and description like ?", admin.id, "deleted post %"])
end
end