2019-03-18 23:25:15 +08:00
|
|
|
module Jobs
|
|
|
|
|
|
|
|
class CleanUpInactiveUsers < Jobs::Scheduled
|
|
|
|
every 1.day
|
|
|
|
|
|
|
|
def execute(args)
|
|
|
|
return if SiteSetting.clean_up_inactive_users_after_days <= 0
|
|
|
|
|
|
|
|
destroyer = UserDestroyer.new(Discourse.system_user)
|
|
|
|
|
|
|
|
User.joins("LEFT JOIN posts ON posts.user_id = users.id")
|
2019-04-25 17:59:31 +08:00
|
|
|
.where(last_posted_at: nil, trust_level: TrustLevel.levels[:newuser], admin: false)
|
2019-03-19 09:53:18 +08:00
|
|
|
.where(
|
|
|
|
"posts.user_id IS NULL AND users.last_seen_at < ?",
|
|
|
|
SiteSetting.clean_up_inactive_users_after_days.days.ago
|
|
|
|
)
|
2019-04-09 20:24:19 +08:00
|
|
|
.limit(1000)
|
|
|
|
.pluck(:id).each do |id|
|
2019-03-18 23:25:15 +08:00
|
|
|
begin
|
2019-04-09 20:24:19 +08:00
|
|
|
user = User.find(id)
|
2019-03-18 23:25:15 +08:00
|
|
|
destroyer.destroy(user, context: I18n.t("user.destroy_reasons.inactive_user"))
|
|
|
|
rescue => e
|
|
|
|
Discourse.handle_job_exception(e,
|
|
|
|
message: "Cleaning up inactive users",
|
2019-04-16 06:26:51 +08:00
|
|
|
extra: { user_id: id }
|
2019-03-18 23:25:15 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|