Mantis importer: few fixes in user mapping.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1127 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-02-06 20:43:31 +00:00
parent c80c1e1ead
commit 9a2ec76a81
1 changed files with 12 additions and 6 deletions

View File

@ -87,18 +87,24 @@ task :migrate_from_mantis => :environment do
set_table_name :mantis_user_table set_table_name :mantis_user_table
def firstname def firstname
realname.blank? ? username : realname.split.first[0..29] @firstname = realname.blank? ? username : realname.split.first[0..29]
@firstname.gsub!(/[^\w\s\'\-]/i, '')
@firstname
end end
def lastname def lastname
realname.blank? ? username : realname.split[1..-1].join(' ')[0..29] @lastname = realname.blank? ? username : realname.split[1..-1].join(' ')[0..29]
@lastname.gsub!(/[^\w\s\'\-]/i, '')
@lastname = '-' if @lastname.blank?
@lastname
end end
def email def email
if read_attribute(:email).match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) if read_attribute(:email).match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) &&
read_attribute(:email) !User.find_by_mail(read_attribute(:email))
@email = read_attribute(:email)
else else
"#{username}@foo.bar" @email = "#{username}@foo.bar"
end end
end end
@ -246,7 +252,7 @@ task :migrate_from_mantis => :environment do
u.password = 'mantis' u.password = 'mantis'
u.status = User::STATUS_LOCKED if user.enabled != 1 u.status = User::STATUS_LOCKED if user.enabled != 1
u.admin = true if user.access_level == 90 u.admin = true if user.access_level == 90
next unless u.save next unless u.save!
users_migrated += 1 users_migrated += 1
users_map[user.id] = u.id users_map[user.id] = u.id
print '.' print '.'