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