Index: lib/tasks/migrate_from_mantis.rake =================================================================== --- lib/tasks/migrate_from_mantis.rake (revision 11561) +++ lib/tasks/migrate_from_mantis.rake (working copy) @@ -88,11 +88,13 @@ def firstname @firstname = realname.blank? ? username : realname.split.first[0..29] + @firstname.gsub!(/[^\w\s\'\-]/i, '') @firstname end def lastname @lastname = realname.blank? ? '-' : realname.split[1..-1].join(' ')[0..29] + @lastname.gsub!(/[^\w\s\'\-]/i, '') @lastname = '-' if @lastname.blank? @lastname end @@ -118,11 +120,19 @@ has_many :news, :class_name => "MantisNews", :foreign_key => :project_id has_many :members, :class_name => "MantisProjectUser", :foreign_key => :project_id + def name + read_attribute(:name)[0..29] + end + def identifier - read_attribute(:name).gsub(/[^a-z0-9\-]+/, '-').slice(0, Project::IDENTIFIER_MAX_LENGTH) + read_attribute(:name).underscore[0..19].gsub(/[^a-z0-9\-]/, '-') end end + class MantisProjectHierarchy < ActiveRecord::Base + self.table_name = :mantis_project_hierarchy_table; + end + class MantisVersion < ActiveRecord::Base self.table_name = :mantis_project_version_table @@ -136,7 +146,7 @@ end class MantisCategory < ActiveRecord::Base - self.table_name = :mantis_project_category_table + self.table_name = :mantis_category_table end class MantisProjectUser < ActiveRecord::Base @@ -222,7 +232,7 @@ end def name - read_attribute(:name)[0..29] + read_attribute(:name)[0..29].gsub(/[^\w\s\'\-]/, '-') end end @@ -248,7 +258,8 @@ :last_login_on => user.last_visit u.login = user.username u.password = 'mantis' - u.status = User::STATUS_LOCKED if user.enabled != 1 + u.status = User::STATUS_ACTIVE if user.enabled == true + u.status = User::STATUS_LOCKED if user.enabled != true u.admin = true if user.access_level == 90 next unless u.save! users_migrated += 1 @@ -259,7 +270,7 @@ # Projects print "Migrating projects" - Project.destroy_all + Project.destroy_all(:parent_id => nil) projects_map = {} versions_map = {} categories_map = {} @@ -286,7 +297,7 @@ project.versions.each do |version| v = Version.new :name => encode(version.version), :description => encode(version.description), - :effective_date => (version.date_order ? version.date_order.to_date : nil) + :effective_date => Time.at(version.date_order).to_date v.project = p v.save versions_map[version.id] = v.id @@ -294,14 +305,22 @@ # Project categories project.categories.each do |category| - g = IssueCategory.new :name => category.category[0,30] + g = IssueCategory.new :name => category.name[0,30] g.project = p g.save - categories_map[category.category] = g.id + categories_map[category.id] = g.id end end puts + # Project Hierarchy + print "Migrating project hierarchy..." + MantisProjectHierarchy.find(:all).each do |entry| + p = Project.find_by_id(projects_map[entry.child_id]) + p.set_parent!(projects_map[entry.parent_id]) + end + puts + # Bugs print "Migrating bugs" Issue.destroy_all @@ -313,10 +332,10 @@ :subject => encode(bug.summary), :description => encode(bug.bug_text.full_description), :priority => PRIORITY_MAPPING[bug.priority] || DEFAULT_PRIORITY, - :created_on => bug.date_submitted, - :updated_on => bug.last_updated + :created_on => Time.at(bug.date_submitted), + :updated_on => Time.at(bug.last_updated) i.author = User.find_by_id(users_map[bug.reporter_id]) - i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category[0,30]) unless bug.category.blank? + i.category = IssueCategory.find_by_id(categories_map[bug.category_id]) unless bug.category_id.blank? i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank? i.status = STATUS_MAPPING[bug.status] || DEFAULT_STATUS i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG) @@ -337,7 +356,7 @@ bug.bug_notes.each do |note| next unless users_map[note.reporter_id] n = Journal.new :notes => encode(note.bug_note_text.note), - :created_on => note.date_submitted + :created_on => Time.at(note.date_submitted) n.user = User.find_by_id(users_map[note.reporter_id]) n.journalized = i n.save @@ -345,7 +364,7 @@ # Bug files bug.bug_files.each do |file| - a = Attachment.new :created_on => file.date_added + a = Attachment.new :created_on => Time.at(file.date_added) a.file = file a.author = User.find :first a.container = i @@ -357,6 +376,9 @@ next unless users_map[monitor.user_id] i.add_watcher(User.find_by_id(users_map[monitor.user_id])) end + + # Fix updated time (setting some attribute breaks it) + i.updated_on = Time.at(bug.last_updated) end # update issue id sequence if needed (postgresql) @@ -384,7 +406,7 @@ n = News.new :project_id => projects_map[news.project_id], :title => encode(news.headline[0..59]), :description => encode(news.body), - :created_on => news.date_posted + :created_on => Time.at(news.date_posted) n.author = User.find_by_id(users_map[news.poster_id]) n.save print '.'