From 9a2ec76a81d2c97c0ccc33452c2ef4557016a0a5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 6 Feb 2008 20:43:31 +0000 Subject: [PATCH] Mantis importer: few fixes in user mapping. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1127 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/tasks/migrate_from_mantis.rake | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/tasks/migrate_from_mantis.rake b/lib/tasks/migrate_from_mantis.rake index 36e7e1514..af8892a6b 100644 --- a/lib/tasks/migrate_from_mantis.rake +++ b/lib/tasks/migrate_from_mantis.rake @@ -87,18 +87,24 @@ task :migrate_from_mantis => :environment do set_table_name :mantis_user_table 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 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 def email - if read_attribute(:email).match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) - read_attribute(:email) + if read_attribute(:email).match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) && + !User.find_by_mail(read_attribute(:email)) + @email = read_attribute(:email) else - "#{username}@foo.bar" + @email = "#{username}@foo.bar" end end @@ -246,7 +252,7 @@ task :migrate_from_mantis => :environment do u.password = 'mantis' u.status = User::STATUS_LOCKED if user.enabled != 1 u.admin = true if user.access_level == 90 - next unless u.save + next unless u.save! users_migrated += 1 users_map[user.id] = u.id print '.' -- 2.39.5