Store the original username during import (#4349)

This commit is contained in:
Gerhard Schlager 2016-07-27 22:30:15 +02:00 committed by Régis Hanol
parent e848c336bb
commit fccc0c93c5
2 changed files with 9 additions and 2 deletions

View file

@ -282,10 +282,14 @@ class ImportScripts::Base
location = opts.delete(:location) location = opts.delete(:location)
avatar_url = opts.delete(:avatar_url) avatar_url = opts.delete(:avatar_url)
original_username = opts[:username]
original_name = opts[:name]
# Allow the || operations to work with empty strings '' # Allow the || operations to work with empty strings ''
opts[:username] = nil if opts[:username].blank? opts[:username] = nil if opts[:username].blank?
opts[:name] = User.suggest_name(opts[:email]) unless opts[:name] opts[:name] = User.suggest_name(opts[:email]) unless opts[:name]
if opts[:username].blank? || if opts[:username].blank? ||
opts[:username].length < User.username_length.begin || opts[:username].length < User.username_length.begin ||
opts[:username].length > User.username_length.end || opts[:username].length > User.username_length.end ||
@ -294,6 +298,9 @@ class ImportScripts::Base
opts[:username] = UserNameSuggester.suggest(opts[:username] || opts[:name].presence || opts[:email]) opts[:username] = UserNameSuggester.suggest(opts[:username] || opts[:name].presence || opts[:email])
end end
opts[:name] = original_username if original_name.blank? && opts[:username] != original_username
opts[:email] = opts[:email].downcase opts[:email] = opts[:email].downcase
opts[:trust_level] = TrustLevel[1] unless opts[:trust_level] opts[:trust_level] = TrustLevel[1] unless opts[:trust_level]
opts[:active] = opts.fetch(:active, true) opts[:active] = opts.fetch(:active, true)
@ -303,7 +310,7 @@ class ImportScripts::Base
u = User.new(opts) u = User.new(opts)
(opts[:custom_fields] || {}).each { |k, v| u.custom_fields[k] = v } (opts[:custom_fields] || {}).each { |k, v| u.custom_fields[k] = v }
u.custom_fields["import_id"] = import_id u.custom_fields["import_id"] = import_id
u.custom_fields["import_username"] = opts[:username] if opts[:username].present? u.custom_fields["import_username"] = opts[:username] if original_username.present?
u.custom_fields["import_avatar_url"] = avatar_url if avatar_url.present? u.custom_fields["import_avatar_url"] = avatar_url if avatar_url.present?
u.custom_fields["import_pass"] = opts[:password] if opts[:password].present? u.custom_fields["import_pass"] = opts[:password] if opts[:password].present?

View file

@ -53,7 +53,7 @@ import:
polls: true polls: true
# When true: each imported user will have the original username from phpBB as its name # When true: each imported user will have the original username from phpBB as its name
# When false: the name of each user will be blank # When false: the name of each imported user will be blank unless the username was changed during import
username_as_name: false username_as_name: false
# Map Emojis to smilies used in phpBB. Most of the default smilies already have a mapping, but you can override # Map Emojis to smilies used in phpBB. Most of the default smilies already have a mapping, but you can override