From 9910e19c2048c6cf5f9836e7d5f64c2081498362 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 28 Feb 2018 16:59:50 +0100 Subject: [PATCH] [Fix #1479] Task to clean invalid emails --- lib/tasks/2018_02_28_clean_gestionnaire_emails.rake | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 lib/tasks/2018_02_28_clean_gestionnaire_emails.rake diff --git a/lib/tasks/2018_02_28_clean_gestionnaire_emails.rake b/lib/tasks/2018_02_28_clean_gestionnaire_emails.rake new file mode 100644 index 000000000..a95a934c3 --- /dev/null +++ b/lib/tasks/2018_02_28_clean_gestionnaire_emails.rake @@ -0,0 +1,11 @@ +namespace :'2018_02_28_clean_invalid_emails_accounts' do + task clean: :environment do + Gestionnaire.pluck(:email, :id).select { |e, id| e.include?(" ") }.each do |email, id| + Gestionnaire.find_by(id: id, current_sign_in_at: nil).try(:destroy) # ensure account was never used + end + + User.pluck(:email, :id).select { |e, id| e.include?(" ") }.each do |email, id| + User.find_by(id: id, current_sign_in_at: nil).try(:destroy) # ensure account was never used + end + end +end