2019-11-07 23:34:24 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
|
|
|
class BulkUserTitleUpdate < ::Jobs::Base
|
2023-01-09 06:20:10 -06:00
|
|
|
UPDATE_ACTION = "update"
|
|
|
|
RESET_ACTION = "reset"
|
2019-11-07 23:34:24 -06:00
|
|
|
|
|
|
|
def execute(args)
|
|
|
|
new_title = args[:new_title]
|
|
|
|
granted_badge_id = args[:granted_badge_id]
|
|
|
|
action = args[:action]
|
2023-01-09 06:20:10 -06:00
|
|
|
badge =
|
|
|
|
begin
|
|
|
|
Badge.find(granted_badge_id)
|
|
|
|
rescue StandardError
|
|
|
|
nil
|
|
|
|
end
|
2020-05-02 20:02:28 -05:00
|
|
|
|
|
|
|
return unless badge # Deleted badge protection
|
2019-11-07 23:34:24 -06:00
|
|
|
|
|
|
|
case action
|
|
|
|
when UPDATE_ACTION
|
2020-05-02 20:02:28 -05:00
|
|
|
badge.update_user_titles!(new_title)
|
2019-11-07 23:34:24 -06:00
|
|
|
when RESET_ACTION
|
2020-05-02 20:02:28 -05:00
|
|
|
badge.reset_user_titles!
|
2019-11-07 23:34:24 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|