discourse/app/jobs/scheduled/invalidate_inactive_admins.rb
Sam f74ef71130 DEV: add transaction and active check to invalidate job
Follows up on 3b76f19668 this per @tgxworld a transaction makes sense here

Very minor
2018-12-13 14:59:56 +11:00

30 lines
774 B
Ruby

module Jobs
class InvalidateInactiveAdmins < Jobs::Scheduled
every 1.day
def execute(_)
return if SiteSetting.invalidate_inactive_admin_email_after_days == 0
User.human_users
.where(admin: true)
.where(active: true)
.where('last_seen_at < ?', SiteSetting.invalidate_inactive_admin_email_after_days.days.ago)
.each do |user|
User.transaction do
user.deactivate
user.email_tokens.update_all(confirmed: false, expired: true)
Discourse.authenticators.each do |authenticator|
if authenticator.can_revoke? && authenticator.description_for_user(user).present?
authenticator.revoke(user)
end
end
end
end
end
end
end