\r
require 'active_record'\r
require 'iconv'\r
+require 'pp'\r
\r
task :migrate_from_mantis => :environment do\r
\r
6 => 'list', # List\r
7 => 'list', # Multiselection list\r
8 => 'date', # Date\r
- } \r
+ }\r
+ \r
+ RELATION_TYPE_MAPPING = {1 => IssueRelation::TYPE_RELATES, # related to\r
+ 2 => IssueRelation::TYPE_RELATES, # parent of\r
+ 3 => IssueRelation::TYPE_RELATES, # child of\r
+ 0 => IssueRelation::TYPE_DUPLICATES, # duplicate of\r
+ 4 => IssueRelation::TYPE_DUPLICATES # has duplicate\r
+ }\r
\r
class MantisUser < ActiveRecord::Base\r
set_table_name :mantis_user_table\r
end\r
end\r
\r
+ class MantisBugRelationship < ActiveRecord::Base\r
+ set_table_name :mantis_bug_relationship_table\r
+ end\r
+ \r
class MantisNews < ActiveRecord::Base\r
set_table_name :mantis_news_table\r
end\r
end\r
puts\r
\r
+ # Bug relationships\r
+ print "Migrating bug relations"\r
+ MantisBugRelationship.find(:all).each do |relation|\r
+ next unless issues_map[relation.source_bug_id] && issues_map[relation.destination_bug_id]\r
+ r = IssueRelation.new :relation_type => RELATION_TYPE_MAPPING[relation.relationship_type]\r
+ r.issue_from = Issue.find_by_id(issues_map[relation.source_bug_id])\r
+ r.issue_to = Issue.find_by_id(issues_map[relation.destination_bug_id])\r
+ pp r unless r.save\r
+ print '.'\r
+ end\r
+ \r
# News\r
print "Migrating news"\r
News.destroy_all\r
puts "Bugs: #{Issue.count}/#{MantisBug.count}"\r
puts "Bug notes: #{Journal.count}/#{MantisBugNote.count}"\r
puts "Bug files: #{Attachment.count}/#{MantisBugFile.count}"\r
+ puts "Bug relations: #{IssueRelation.count}/#{MantisBugRelationship.count}"\r
puts "News: #{News.count}/#{MantisNews.count}"\r
puts "Custom fields: #{IssueCustomField.count}/#{MantisCustomField.count}"\r
end\r
print "Are you sure you want to continue ? [y/N] "\r
break unless STDIN.gets.match(/^y$/i)\r
\r
- # default Mantis database settings\r
+ # Default Mantis database settings\r
db_params = {:adapter => 'mysql', \r
:database => 'bugtracker', \r
:host => 'localhost', \r
end\r
puts\r
\r
+ # Make sure bugs can refer bugs in other projects\r
+ Setting.cross_project_issue_relations = 1\r
+ \r
MantisMigrate.establish_connection db_params\r
MantisMigrate.migrate\r
end\r