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:
parent
005ce1b21d
commit
5b4812add8
|
@ -19,6 +19,7 @@ desc 'Mantis migration script'
|
||||||
|
|
||||||
require 'active_record'
|
require 'active_record'
|
||||||
require 'iconv'
|
require 'iconv'
|
||||||
|
require 'pp'
|
||||||
|
|
||||||
task :migrate_from_mantis => :environment do
|
task :migrate_from_mantis => :environment do
|
||||||
|
|
||||||
|
@ -58,7 +59,14 @@ task :migrate_from_mantis => :environment do
|
||||||
6 => 'list', # List
|
6 => 'list', # List
|
||||||
7 => 'list', # Multiselection list
|
7 => 'list', # Multiselection list
|
||||||
8 => 'date', # Date
|
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
|
class MantisUser < ActiveRecord::Base
|
||||||
set_table_name :mantis_user_table
|
set_table_name :mantis_user_table
|
||||||
|
@ -161,6 +169,10 @@ task :migrate_from_mantis => :environment do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class MantisBugRelationship < ActiveRecord::Base
|
||||||
|
set_table_name :mantis_bug_relationship_table
|
||||||
|
end
|
||||||
|
|
||||||
class MantisNews < ActiveRecord::Base
|
class MantisNews < ActiveRecord::Base
|
||||||
set_table_name :mantis_news_table
|
set_table_name :mantis_news_table
|
||||||
end
|
end
|
||||||
|
@ -298,6 +310,17 @@ task :migrate_from_mantis => :environment do
|
||||||
end
|
end
|
||||||
puts
|
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
|
# News
|
||||||
print "Migrating news"
|
print "Migrating news"
|
||||||
News.destroy_all
|
News.destroy_all
|
||||||
|
@ -354,6 +377,7 @@ task :migrate_from_mantis => :environment do
|
||||||
puts "Bugs: #{Issue.count}/#{MantisBug.count}"
|
puts "Bugs: #{Issue.count}/#{MantisBug.count}"
|
||||||
puts "Bug notes: #{Journal.count}/#{MantisBugNote.count}"
|
puts "Bug notes: #{Journal.count}/#{MantisBugNote.count}"
|
||||||
puts "Bug files: #{Attachment.count}/#{MantisBugFile.count}"
|
puts "Bug files: #{Attachment.count}/#{MantisBugFile.count}"
|
||||||
|
puts "Bug relations: #{IssueRelation.count}/#{MantisBugRelationship.count}"
|
||||||
puts "News: #{News.count}/#{MantisNews.count}"
|
puts "News: #{News.count}/#{MantisNews.count}"
|
||||||
puts "Custom fields: #{IssueCustomField.count}/#{MantisCustomField.count}"
|
puts "Custom fields: #{IssueCustomField.count}/#{MantisCustomField.count}"
|
||||||
end
|
end
|
||||||
|
@ -385,7 +409,7 @@ task :migrate_from_mantis => :environment do
|
||||||
print "Are you sure you want to continue ? [y/N] "
|
print "Are you sure you want to continue ? [y/N] "
|
||||||
break unless STDIN.gets.match(/^y$/i)
|
break unless STDIN.gets.match(/^y$/i)
|
||||||
|
|
||||||
# default Mantis database settings
|
# Default Mantis database settings
|
||||||
db_params = {:adapter => 'mysql',
|
db_params = {:adapter => 'mysql',
|
||||||
:database => 'bugtracker',
|
:database => 'bugtracker',
|
||||||
:host => 'localhost',
|
:host => 'localhost',
|
||||||
|
@ -409,6 +433,9 @@ task :migrate_from_mantis => :environment do
|
||||||
end
|
end
|
||||||
puts
|
puts
|
||||||
|
|
||||||
|
# Make sure bugs can refer bugs in other projects
|
||||||
|
Setting.cross_project_issue_relations = 1
|
||||||
|
|
||||||
MantisMigrate.establish_connection db_params
|
MantisMigrate.establish_connection db_params
|
||||||
MantisMigrate.migrate
|
MantisMigrate.migrate
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue