From 4ffa4a28b0fa4cff24eb9a874519a862bedc0fba Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Tue, 19 Jun 2018 00:21:48 +0530 Subject: [PATCH] FIX: duplicate_emails get overridden in new batch of import --- script/import_scripts/lithium.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/script/import_scripts/lithium.rb b/script/import_scripts/lithium.rb index 5033ee0d663..a778f0831f2 100644 --- a/script/import_scripts/lithium.rb +++ b/script/import_scripts/lithium.rb @@ -104,6 +104,7 @@ class ImportScripts::Lithium < ImportScripts::Base user_count = mysql_query("SELECT COUNT(*) count FROM users").first["count"] avatar_files = Dir.entries(AVATAR_DIR) + 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 batches(BATCH_SIZE) do |offset| users = mysql_query <<-SQL @@ -129,8 +130,6 @@ class ImportScripts::Lithium < ImportScripts::Base ORDER BY user_id SQL - 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"] profile = profiles.select { |p| p["user_id"] == user_id } @@ -143,7 +142,7 @@ class ImportScripts::Lithium < ImportScripts::Base email_lower = email.downcase if duplicate_emails.key?(email_lower) duplicate_emails[email_lower] += 1 - email.sub!("@", "+#{duplicate_emails[email_lower]}@") + email.sub!("@", "+#{duplicate_emails[email_lower]}@") if duplicate_emails[email_lower] > 1 end {