2021-03-11 07:30:15 +01:00
|
|
|
# frozen_string_literal: true
|
2017-11-01 05:21:14 +01:00
|
|
|
module Jobs
|
2019-10-03 07:17:21 +02:00
|
|
|
class SetAfterTimeWizard < ::Jobs::Base
|
2017-11-01 05:21:14 +01:00
|
|
|
def execute(args)
|
2020-04-14 07:46:06 +02:00
|
|
|
if SiteSetting.custom_wizard_enabled
|
2024-10-17 16:15:25 +02:00
|
|
|
@wizard = CustomWizard::Wizard.create(args[:wizard_id])
|
2021-03-11 07:30:15 +01:00
|
|
|
|
2024-10-17 16:15:25 +02:00
|
|
|
if @wizard && @wizard.after_time
|
2020-04-14 07:46:06 +02:00
|
|
|
user_ids = []
|
2018-07-06 02:58:53 +02:00
|
|
|
|
2024-10-17 16:15:25 +02:00
|
|
|
target_users.each do |user|
|
|
|
|
user_ids.push(user.id) if CustomWizard::Wizard.set_after_time_redirect(@wizard.id, user)
|
2018-07-06 02:58:53 +02:00
|
|
|
end
|
|
|
|
|
2022-01-31 10:18:04 +01:00
|
|
|
CustomWizard::Template.clear_cache_keys
|
|
|
|
|
2024-10-17 16:15:25 +02:00
|
|
|
MessageBus.publish "/redirect_to_wizard", @wizard.id, user_ids: user_ids
|
2020-04-14 07:46:06 +02:00
|
|
|
end
|
2017-11-01 05:21:14 +01:00
|
|
|
end
|
|
|
|
end
|
2024-10-17 16:15:25 +02:00
|
|
|
|
|
|
|
def target_users
|
|
|
|
users = []
|
|
|
|
|
|
|
|
if @wizard.after_time_groups.exists?
|
|
|
|
@wizard.after_time_groups.each { |group| users += group.users }
|
|
|
|
else
|
|
|
|
users = User.human_users
|
|
|
|
end
|
|
|
|
|
|
|
|
users
|
|
|
|
end
|
2017-11-01 05:21:14 +01:00
|
|
|
end
|
|
|
|
end
|