Use lowercased email addresses to check duplicates

This commit is contained in:
Vinoth Kannan 2018-06-16 20:34:37 +05:30
parent ac44374a59
commit 2a0f409b9d
1 changed files with 5 additions and 4 deletions

View File

@ -128,7 +128,7 @@ class ImportScripts::Lithium < ImportScripts::Base
ORDER BY user_id
SQL
duplicate_emails = mysql_query("SELECT email FROM users GROUP BY email HAVING COUNT(email) > 1").map { |e| [e["email"], 0] }.to_h
duplicate_emails = mysql_query("SELECT email_lower FROM users GROUP BY email_lower HAVING COUNT(email_lower) > 1").map { |e| [e["email_lower"], 0] }.to_h
create_users(users, total: user_count, offset: offset) do |user|
user_id = user["id"]
@ -139,9 +139,10 @@ class ImportScripts::Lithium < ImportScripts::Base
username = USERNAME_MAPPINGS[username] if USERNAME_MAPPINGS[username].present?
email = user["email"].presence || fake_email
if duplicate_emails.key?(email)
duplicate_emails[email] += 1
email.sub!("@", "+#{duplicate_emails[email]}@")
email_lower = email.downcase
if duplicate_emails.key?(email_lower)
duplicate_emails[email_lower] += 1
email.sub!("@", "+#{duplicate_emails[email_lower]}@")
end
{