From 5b4812add8d93ea9d8705beac10072081e4cae9b Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 13 Aug 2007 15:29:16 +0000 Subject: [PATCH] Added migration of Mantis bug relationships. git-svn-id: http://redmine.rubyforge.org/svn/trunk@625 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/tasks/migrate_from_mantis.rake | 31 ++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/tasks/migrate_from_mantis.rake b/lib/tasks/migrate_from_mantis.rake index 3fbc048ff..1a2d0877b 100644 --- a/lib/tasks/migrate_from_mantis.rake +++ b/lib/tasks/migrate_from_mantis.rake @@ -19,6 +19,7 @@ desc 'Mantis migration script' require 'active_record' require 'iconv' +require 'pp' task :migrate_from_mantis => :environment do @@ -58,7 +59,14 @@ task :migrate_from_mantis => :environment do 6 => 'list', # List 7 => 'list', # Multiselection list 8 => 'date', # Date - } + } + + RELATION_TYPE_MAPPING = {1 => IssueRelation::TYPE_RELATES, # related to + 2 => IssueRelation::TYPE_RELATES, # parent of + 3 => IssueRelation::TYPE_RELATES, # child of + 0 => IssueRelation::TYPE_DUPLICATES, # duplicate of + 4 => IssueRelation::TYPE_DUPLICATES # has duplicate + } class MantisUser < ActiveRecord::Base set_table_name :mantis_user_table @@ -161,6 +169,10 @@ task :migrate_from_mantis => :environment do end end + class MantisBugRelationship < ActiveRecord::Base + set_table_name :mantis_bug_relationship_table + end + class MantisNews < ActiveRecord::Base set_table_name :mantis_news_table end @@ -298,6 +310,17 @@ task :migrate_from_mantis => :environment do end puts + # Bug relationships + print "Migrating bug relations" + MantisBugRelationship.find(:all).each do |relation| + next unless issues_map[relation.source_bug_id] && issues_map[relation.destination_bug_id] + r = IssueRelation.new :relation_type => RELATION_TYPE_MAPPING[relation.relationship_type] + r.issue_from = Issue.find_by_id(issues_map[relation.source_bug_id]) + r.issue_to = Issue.find_by_id(issues_map[relation.destination_bug_id]) + pp r unless r.save + print '.' + end + # News print "Migrating news" News.destroy_all @@ -354,6 +377,7 @@ task :migrate_from_mantis => :environment do puts "Bugs: #{Issue.count}/#{MantisBug.count}" puts "Bug notes: #{Journal.count}/#{MantisBugNote.count}" puts "Bug files: #{Attachment.count}/#{MantisBugFile.count}" + puts "Bug relations: #{IssueRelation.count}/#{MantisBugRelationship.count}" puts "News: #{News.count}/#{MantisNews.count}" puts "Custom fields: #{IssueCustomField.count}/#{MantisCustomField.count}" end @@ -385,7 +409,7 @@ task :migrate_from_mantis => :environment do print "Are you sure you want to continue ? [y/N] " break unless STDIN.gets.match(/^y$/i) - # default Mantis database settings + # Default Mantis database settings db_params = {:adapter => 'mysql', :database => 'bugtracker', :host => 'localhost', @@ -409,6 +433,9 @@ task :migrate_from_mantis => :environment do end puts + # Make sure bugs can refer bugs in other projects + Setting.cross_project_issue_relations = 1 + MantisMigrate.establish_connection db_params MantisMigrate.migrate end -- 2.39.5