2014-06-27 12:26:03 -04:00
|
|
|
module Jobs
|
|
|
|
|
|
|
|
class LeaderPromotions < Jobs::Scheduled
|
|
|
|
daily at: 4.hours
|
|
|
|
|
|
|
|
def execute(args)
|
|
|
|
# Demotions
|
|
|
|
demoted_user_ids = []
|
2014-09-05 01:20:39 -04:00
|
|
|
User.real.where(trust_level: TrustLevel[3]).find_each do |u|
|
2014-07-08 17:39:36 -04:00
|
|
|
# Don't demote too soon after being promoted
|
|
|
|
next if UserHistory.for(u, :auto_trust_level_change)
|
2014-09-05 02:55:25 -04:00
|
|
|
.where('created_at >= ?', SiteSetting.tl3_promotion_min_duration.to_i.days.ago)
|
2014-09-05 01:20:39 -04:00
|
|
|
.where(previous_value: TrustLevel[2].to_s)
|
|
|
|
.where(new_value: TrustLevel[3].to_s)
|
2014-07-08 17:39:36 -04:00
|
|
|
.exists?
|
|
|
|
|
2014-09-05 01:20:39 -04:00
|
|
|
if Promotion.tl3_lost?(u)
|
2014-06-27 12:26:03 -04:00
|
|
|
demoted_user_ids << u.id
|
2014-09-05 01:20:39 -04:00
|
|
|
Promotion.new(u).change_trust_level!(TrustLevel[2])
|
2014-06-27 12:26:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Promotions
|
2014-09-05 01:20:39 -04:00
|
|
|
User.real.where(trust_level: TrustLevel[2]).where.not(id: demoted_user_ids).find_each do |u|
|
|
|
|
Promotion.new(u).review_tl2
|
2014-06-27 12:26:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|