Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts to export/remove invalid User phone numbers #3141

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ gem "simple_form", "~> 5.0"
gem "country_select", "~> 3.1"
gem "email_validator"
gem "enumerize"
gem "phonelib"

# PDF generation
gem "prawn"
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ GEM
pg_search (2.3.6)
activerecord (>= 5.2)
activesupport (>= 5.2)
phonelib (0.9.3)
poltergeist (1.18.1)
capybara (>= 2.1, < 4)
cliver (~> 0.3.1)
Expand Down Expand Up @@ -780,6 +781,7 @@ DEPENDENCIES
pdf-inspector
pg
pg_search (~> 2.3.3)
phonelib
poltergeist
prawn
prawn-table
Expand Down
47 changes: 47 additions & 0 deletions lib/tasks/temprary/remove_invalid_user_phone_numbers.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace :db do
desc "Remove invalid user phone_numbers"
task remove_invalid_user_phone_numbers: :environment do
User.find_each do |user|
invalid = false

if user.phone_number && Phonelib.invalid_for_country?(user.phone_number, "GB")
user.phone_number = nil
invalid = true
end

if user.company_phone_number && Phonelib.invalid_for_country?(user.company_phone_number, "GB")
user.company_phone_number = nil
invalid = true
end

user.save! if invalid
end
end

desc "Export users with invalid phone numbers"
task export_user_phone_numbers: :environment do
CSV.open("user_phone_numbers.csv", "w") do |csv|
csv << ["Email", "Name", "Number", "Field"]

User.find_each do |user|
if user.phone_number && Phonelib.invalid_for_country?(user.phone_number, "GB")
csv << [
user.email,
user.full_name,
user.phone_number,
"phone_number",
]
end

if user.company_phone_number && Phonelib.invalid_for_country?(user.company_phone_number, "GB")
csv << [
user.email,
user.full_name,
user.company_phone_number,
"company_phone_number",
]
end
end
end
end
end
Loading