2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-11 12:52:15 -04:00
|
|
|
module Jobs
|
|
|
|
class DeleteTopic < Jobs::Base
|
|
|
|
|
|
|
|
def execute(args)
|
2017-05-11 18:23:18 -04:00
|
|
|
topic_timer = TopicTimer.find_by(id: args[:topic_timer_id] || args[:topic_status_update_id])
|
2017-05-11 12:52:15 -04:00
|
|
|
|
2017-05-11 18:23:18 -04:00
|
|
|
topic = topic_timer&.topic
|
2017-05-11 12:52:15 -04:00
|
|
|
|
2017-05-11 18:23:18 -04:00
|
|
|
if topic_timer.blank? || topic.blank? || topic_timer.execute_at > Time.zone.now
|
2017-05-11 12:52:15 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-05-11 18:23:18 -04:00
|
|
|
if Guardian.new(topic_timer.user).can_delete?(topic)
|
2017-05-11 12:52:15 -04:00
|
|
|
first_post = topic.ordered_posts.first
|
2017-07-27 21:20:09 -04:00
|
|
|
PostDestroyer.new(topic_timer.user, first_post, context: I18n.t("topic_statuses.auto_deleted_by_timer")).destroy
|
2017-05-11 22:28:51 -04:00
|
|
|
topic_timer.trash!(Discourse.system_user)
|
2017-05-11 12:52:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2017-05-11 18:23:18 -04:00
|
|
|
end
|