2017-03-22 11:12:02 +08:00
|
|
|
module Jobs
|
|
|
|
class ToggleTopicClosed < Jobs::Base
|
|
|
|
def execute(args)
|
2017-05-12 06:23:18 +08:00
|
|
|
topic_timer = TopicTimer.find_by(id: args[:topic_timer_id] || args[:topic_status_update_id])
|
2017-04-04 14:29:47 +08:00
|
|
|
state = !!args[:state]
|
2017-03-22 11:12:02 +08:00
|
|
|
|
2017-05-12 06:23:18 +08:00
|
|
|
if topic_timer.blank? ||
|
|
|
|
topic_timer.execute_at > Time.zone.now ||
|
|
|
|
(topic = topic_timer.topic).blank? ||
|
2017-04-04 14:29:47 +08:00
|
|
|
topic.closed == state
|
2017-03-22 11:12:02 +08:00
|
|
|
|
2017-04-04 14:29:47 +08:00
|
|
|
return
|
|
|
|
end
|
2017-03-22 11:12:02 +08:00
|
|
|
|
2017-05-12 06:23:18 +08:00
|
|
|
user = topic_timer.user
|
2017-03-22 11:12:02 +08:00
|
|
|
|
|
|
|
if Guardian.new(user).can_close?(topic)
|
|
|
|
topic.update_status('autoclosed', state, user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|