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)
|
2019-01-08 18:43:10 +08:00
|
|
|
if state == false && PostAction.auto_close_threshold_reached?(topic)
|
|
|
|
topic.set_or_create_timer(
|
|
|
|
TopicTimer.types[:open],
|
|
|
|
SiteSetting.num_hours_to_close_topic,
|
|
|
|
by_user: Discourse.system_user
|
|
|
|
)
|
|
|
|
else
|
|
|
|
topic.update_status('autoclosed', state, user)
|
|
|
|
end
|
|
|
|
|
2018-02-27 15:31:59 +08:00
|
|
|
topic.inherit_auto_close_from_category if state == false
|
2017-03-22 11:12:02 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|