]> source.dussan.org Git - redmine.git/commitdiff
Make Mantis importer preserve bug ids.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 15 Feb 2008 16:41:44 +0000 (16:41 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 15 Feb 2008 16:41:44 +0000 (16:41 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1146 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/tasks/migrate_from_mantis.rake

index af8892a6bfa79cb93edb6deb5ad676d388660117..99607f2a2da40771478b084f8d0afc482e46c36f 100644 (file)
@@ -308,7 +308,8 @@ task :migrate_from_mantis => :environment do
       print "Migrating bugs"\r
       Issue.destroy_all\r
       issues_map = {}\r
-      MantisBug.find(:all).each do |bug|\r
+      keep_bug_ids = (Issue.count == 0)\r
+      MantisBug.find(:all, :order => 'id ASC').each do |bug|\r
         next unless projects_map[bug.project_id] && users_map[bug.reporter_id]\r
        i = Issue.new :project_id => projects_map[bug.project_id], \r
                       :subject => encode(bug.summary),\r
@@ -321,6 +322,7 @@ task :migrate_from_mantis => :environment do
        i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank?\r
        i.status = STATUS_MAPPING[bug.status] || DEFAULT_STATUS\r
        i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG)\r
+       i.id = bug.id if keep_bug_ids\r
        next unless i.save\r
        issues_map[bug.id] = i.id\r
        print '.'\r
@@ -357,6 +359,9 @@ task :migrate_from_mantis => :environment do
           i.add_watcher(User.find_by_id(users_map[monitor.user_id]))\r
         end\r
       end\r
+      \r
+      # update issue id sequence if needed (postgresql)\r
+      Issue.connection.reset_pk_sequence!(Issue.table_name) if Issue.connection.respond_to?('reset_pk_sequence!')\r
       puts\r
       \r
       # Bug relationships\r