From 3df8f184c3dda38b33f12a83ddc302de1aff0ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 16 May 2016 22:13:23 +0200 Subject: [PATCH] FEATURE: clean up 1 year old and unused staged users --- .../scheduled/clean_up_unused_staged_users.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 app/jobs/scheduled/clean_up_unused_staged_users.rb diff --git a/app/jobs/scheduled/clean_up_unused_staged_users.rb b/app/jobs/scheduled/clean_up_unused_staged_users.rb new file mode 100644 index 000000000..f11ec67c1 --- /dev/null +++ b/app/jobs/scheduled/clean_up_unused_staged_users.rb @@ -0,0 +1,18 @@ +module Jobs + + class CleanUpUnusedStagedUsers < Jobs::Scheduled + every 1.day + + def execute(args) + destroyer = UserDestroyer.new(Discourse.system_user) + + User.joins(:user_stat) + .where(staged: true) + .where("users.created_at < ?", 1.year.ago) + .where("user_stats.post_count = 0") + .find_each { |user| destroyer.destroy(user) } + end + + end + +end