2021-01-13 06:49:29 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
2021-01-19 11:30:58 +08:00
|
|
|
class OpenTopic < ::Jobs::TopicTimerBase
|
|
|
|
def execute_timer_action(topic_timer, topic)
|
2021-01-13 06:49:29 +08:00
|
|
|
user = topic_timer.user
|
|
|
|
|
|
|
|
if !Guardian.new(user).can_open_topic?(topic) || topic.open?
|
|
|
|
topic_timer.destroy!
|
|
|
|
topic.reload
|
|
|
|
|
|
|
|
topic.inherit_auto_close_from_category(timer_type: :close)
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# guards against reopening a topic too early if the topic has
|
|
|
|
# been auto closed because of reviewables/reports, this will
|
|
|
|
# just update the existing topic timer and push it down the line
|
|
|
|
if topic.auto_close_threshold_reached?
|
|
|
|
topic.set_or_create_timer(
|
|
|
|
TopicTimer.types[:open],
|
|
|
|
SiteSetting.num_hours_to_close_topic,
|
|
|
|
by_user: Discourse.system_user
|
|
|
|
)
|
|
|
|
else
|
|
|
|
|
|
|
|
# autoclosed, false is just another way of saying open.
|
2021-05-21 09:43:47 +08:00
|
|
|
# this handles deleting the topic timer as well, see TopicStatusUpdater
|
2021-01-13 06:49:29 +08:00
|
|
|
topic.update_status('autoclosed', false, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
topic.inherit_auto_close_from_category(timer_type: :close)
|
2021-02-03 08:13:32 +08:00
|
|
|
|
|
|
|
MessageBus.publish("/topic/#{topic.id}", reload_topic: true)
|
2021-01-13 06:49:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|