2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-28 12:20:05 -04:00
|
|
|
module Jobs
|
2019-10-02 00:01:53 -04:00
|
|
|
class GrantAnniversaryBadges < ::Jobs::Scheduled
|
2017-04-28 12:20:05 -04:00
|
|
|
every 1.day
|
|
|
|
|
|
|
|
def execute(args)
|
|
|
|
return unless SiteSetting.enable_badges?
|
2023-01-16 05:55:00 -05:00
|
|
|
return unless badge = Badge.find_by(id: Badge::Anniversary, enabled: true)
|
2017-04-28 12:20:05 -04:00
|
|
|
|
|
|
|
start_date = args[:start_date] || 1.year.ago
|
|
|
|
end_date = start_date + 1.year
|
|
|
|
|
2023-01-16 05:55:00 -05:00
|
|
|
sql = BadgeQueries.anniversaries(start_date, end_date)
|
|
|
|
user_ids = DB.query_single(sql)
|
2017-04-28 12:20:05 -04:00
|
|
|
|
2017-06-23 03:53:07 -04:00
|
|
|
User
|
|
|
|
.where(id: user_ids)
|
2017-04-28 12:20:05 -04:00
|
|
|
.find_each { |user| BadgeGranter.grant(badge, user, created_at: end_date) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|