-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3141 from bitzesty/pb/add-script-to-check-phone-n…
…umbers Add scripts to export/remove invalid User phone numbers
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |