FIX: handle existing users in imports

This commit is contained in:
Arpit Jalan 2017-07-24 16:22:56 +05:30
parent 995d253030
commit ed5d322196
1 changed files with 2 additions and 2 deletions

View File

@ -267,7 +267,7 @@ class ImportScripts::Base
merge = opts.delete(:merge) merge = opts.delete(:merge)
post_create_action = opts.delete(:post_create_action) post_create_action = opts.delete(:post_create_action)
existing = User.where("email = ? OR username = ?", opts[:email].downcase, opts[:username]).first existing = User.joins(:user_emails).where("user_emails.email = ? OR username = ?", opts[:email].downcase, opts[:username]).first
return existing if existing && (merge || existing.custom_fields["import_id"].to_i == import_id.to_i) return existing if existing && (merge || existing.custom_fields["import_id"].to_i == import_id.to_i)
bio_raw = opts.delete(:bio_raw) bio_raw = opts.delete(:bio_raw)
@ -323,7 +323,7 @@ class ImportScripts::Base
end end
rescue => e rescue => e
# try based on email # try based on email
if e.try(:record).try(:errors).try(:messages).try(:[], :email).present? if e.try(:record).try(:errors).try(:messages).try(:[], :primary_email).present?
if existing = User.find_by_email(opts[:email].downcase) if existing = User.find_by_email(opts[:email].downcase)
existing.custom_fields["import_id"] = import_id existing.custom_fields["import_id"] = import_id
existing.save! existing.save!