diff --git a/script/import_scripts/base.rb b/script/import_scripts/base.rb index 0bc796c7301..039e4de83d2 100644 --- a/script/import_scripts/base.rb +++ b/script/import_scripts/base.rb @@ -258,9 +258,8 @@ class ImportScripts::Base if opts[:username].blank? || opts[:username].length < User.username_length.begin || opts[:username].length > User.username_length.end || - opts[:username] =~ /[^A-Za-z0-9_]/ || - opts[:username][0] =~ /[^A-Za-z0-9]/ || - !User.username_available?(opts[:username]) + !User.username_available?(opts[:username]) || + !UsernameValidator.new(opts[:username]).valid_format? opts[:username] = UserNameSuggester.suggest(opts[:username] || opts[:name] || opts[:email]) end opts[:email] = opts[:email].downcase @@ -289,13 +288,18 @@ class ImportScripts::Base if opts[:active] && opts[:password].present? u.activate end - rescue + rescue => e # try based on email - existing = User.find_by(email: opts[:email].downcase) - if existing - existing.custom_fields["import_id"] = import_id - existing.save! - u = existing + if e.record.errors.messages[:email].present? + existing = User.find_by(email: opts[:email].downcase) + if existing + existing.custom_fields["import_id"] = import_id + existing.save! + u = existing + end + else + puts "Error on record: #{opts}" + raise e end end post_create_action.try(:call, u) if u.persisted?