Added migration of Mantis bug relationships.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@625 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-08-13 15:29:16 +00:00
parent 005ce1b21d
commit 5b4812add8
1 changed files with 29 additions and 2 deletions

View File

@ -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