2017-03-21 23:12:02 -04:00
|
|
|
module Jobs
|
|
|
|
class ToggleTopicClosed < 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-04-04 02:29:47 -04:00
|
|
|
state = !!args[:state]
|
2017-03-21 23:12:02 -04:00
|
|
|
|
2017-05-11 18:23:18 -04:00
|
|
|
if topic_timer.blank? ||
|
|
|
|
topic_timer.execute_at > Time.zone.now ||
|
|
|
|
(topic = topic_timer.topic).blank? ||
|
2017-04-04 02:29:47 -04:00
|
|
|
topic.closed == state
|
2017-03-21 23:12:02 -04:00
|
|
|
|
2017-04-04 02:29:47 -04:00
|
|
|
return
|
|
|
|
end
|
2017-03-21 23:12:02 -04:00
|
|
|
|
2017-05-11 18:23:18 -04:00
|
|
|
user = topic_timer.user
|
2017-03-21 23:12:02 -04:00
|
|
|
|
|
|
|
if Guardian.new(user).can_close?(topic)
|
|
|
|
topic.update_status('autoclosed', state, user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|