discourse/app/jobs/regular/delete_topic.rb

22 lines
624 B
Ruby
Raw Normal View History

2017-05-12 00:52:15 +08:00
module Jobs
class DeleteTopic < Jobs::Base
def execute(args)
topic_timer = TopicTimer.find_by(id: args[:topic_timer_id] || args[:topic_status_update_id])
2017-05-12 00:52:15 +08:00
topic = topic_timer&.topic
2017-05-12 00:52:15 +08:00
if topic_timer.blank? || topic.blank? || topic_timer.execute_at > Time.zone.now
2017-05-12 00:52:15 +08:00
return
end
if Guardian.new(topic_timer.user).can_delete?(topic)
2017-05-12 00:52:15 +08:00
first_post = topic.ordered_posts.first
PostDestroyer.new(topic_timer.user, first_post, { context: I18n.t("topic_statuses.auto_deleted_by_timer") }).destroy
topic_timer.trash!(Discourse.system_user)
2017-05-12 00:52:15 +08:00
end
end
end
end