]> source.dussan.org Git - redmine.git/commitdiff
Added migration of Mantis bug relationships.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 13 Aug 2007 15:29:16 +0000 (15:29 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 13 Aug 2007 15:29:16 +0000 (15:29 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@625 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/tasks/migrate_from_mantis.rake

index 3fbc048ffdccaafe3d44d81152b70f5f06510562..1a2d0877bdc38f125185fd04c23588308bd59751 100644 (file)
@@ -19,6 +19,7 @@ desc 'Mantis migration script'
 \r
 require 'active_record'\r
 require 'iconv'\r
+require 'pp'\r
 \r
 task :migrate_from_mantis => :environment do\r
   \r
@@ -58,7 +59,14 @@ task :migrate_from_mantis => :environment do
                                    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
@@ -161,6 +169,10 @@ task :migrate_from_mantis => :environment do
       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
@@ -298,6 +310,17 @@ task :migrate_from_mantis => :environment do
       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
@@ -354,6 +377,7 @@ task :migrate_from_mantis => :environment do
       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
@@ -385,7 +409,7 @@ task :migrate_from_mantis => :environment do
   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
@@ -409,6 +433,9 @@ task :migrate_from_mantis => :environment do
   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