@@ -25,21 +25,22 task :migrate_from_mantis => :environment do | |||
|
25 | 25 | |
|
26 | 26 | module MantisMigrate |
|
27 | 27 | |
|
28 |
|
|
|
28 | DEFAULT_STATUS = IssueStatus.default | |
|
29 | 29 | assigned_status = IssueStatus.find_by_position(2) |
|
30 | 30 | resolved_status = IssueStatus.find_by_position(3) |
|
31 | 31 | feedback_status = IssueStatus.find_by_position(4) |
|
32 | 32 | closed_status = IssueStatus.find :first, :conditions => { :is_closed => true } |
|
33 |
STATUS_MAPPING = {10 => |
|
|
33 | STATUS_MAPPING = {10 => DEFAULT_STATUS, # new | |
|
34 | 34 | 20 => feedback_status, # feedback |
|
35 |
30 => |
|
|
36 |
40 => |
|
|
35 | 30 => DEFAULT_STATUS, # acknowledged | |
|
36 | 40 => DEFAULT_STATUS, # confirmed | |
|
37 | 37 | 50 => assigned_status, # assigned |
|
38 | 38 | 80 => resolved_status, # resolved |
|
39 | 39 | 90 => closed_status # closed |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | priorities = Enumeration.get_values('IPRI') |
|
43 | DEFAULT_PRIORITY = priorities[2] | |
|
43 | 44 | PRIORITY_MAPPING = {10 => priorities[1], # none |
|
44 | 45 | 20 => priorities[1], # low |
|
45 | 46 | 30 => priorities[2], # normal |
@@ -97,6 +98,10 task :migrate_from_mantis => :environment do | |||
|
97 | 98 | "#{username}@foo.bar" |
|
98 | 99 | end |
|
99 | 100 | end |
|
101 | ||
|
102 | def username | |
|
103 | read_attribute(:username)[0..29].gsub(/[^a-zA-Z0-9_\-@\.]/, '-') | |
|
104 | end | |
|
100 | 105 | end |
|
101 | 106 | |
|
102 | 107 | class MantisProject < ActiveRecord::Base |
@@ -296,18 +301,18 task :migrate_from_mantis => :environment do | |||
|
296 | 301 | Issue.destroy_all |
|
297 | 302 | issues_map = {} |
|
298 | 303 | MantisBug.find(:all).each do |bug| |
|
299 | next unless projects_map[bug.project_id] | |
|
304 | next unless projects_map[bug.project_id] && users_map[bug.reporter_id] | |
|
300 | 305 | i = Issue.new :project_id => projects_map[bug.project_id], |
|
301 | 306 | :subject => encode(bug.summary), |
|
302 | 307 | :description => encode(bug.bug_text.full_description), |
|
303 | :priority => PRIORITY_MAPPING[bug.priority], | |
|
308 | :priority => PRIORITY_MAPPING[bug.priority] || DEFAULT_PRIORITY, | |
|
304 | 309 | :created_on => bug.date_submitted, |
|
305 | 310 | :updated_on => bug.last_updated |
|
306 | 311 | i.author = User.find_by_id(users_map[bug.reporter_id]) |
|
307 | 312 | i.assigned_to = User.find_by_id(users_map[bug.handler_id]) if bug.handler_id && users_map[bug.handler_id] |
|
308 | 313 | i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category) unless bug.category.blank? |
|
309 | 314 | i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank? |
|
310 |
i.status = STATUS_MAPPING[bug.status] || |
|
|
315 | i.status = STATUS_MAPPING[bug.status] || DEFAULT_STATUS | |
|
311 | 316 | i.tracker = TARGET_TRACKER |
|
312 | 317 | next unless i.save |
|
313 | 318 | issues_map[bug.id] = i.id |
@@ -315,6 +320,7 task :migrate_from_mantis => :environment do | |||
|
315 | 320 | |
|
316 | 321 | # Bug notes |
|
317 | 322 | bug.bug_notes.each do |note| |
|
323 | next unless users_map[note.reporter_id] | |
|
318 | 324 | n = Journal.new :notes => encode(note.bug_note_text.note), |
|
319 | 325 | :created_on => note.date_submitted |
|
320 | 326 | n.user = User.find_by_id(users_map[note.reporter_id]) |
@@ -333,6 +339,7 task :migrate_from_mantis => :environment do | |||
|
333 | 339 | |
|
334 | 340 | # Bug monitors |
|
335 | 341 | bug.bug_monitors.each do |monitor| |
|
342 | next unless users_map[monitor.user_id] | |
|
336 | 343 | i.add_watcher(User.find_by_id(users_map[monitor.user_id])) |
|
337 | 344 | end |
|
338 | 345 | end |
@@ -375,7 +382,7 task :migrate_from_mantis => :environment do | |||
|
375 | 382 | :max_length => field.length_max, |
|
376 | 383 | :regexp => field.valid_regexp, |
|
377 | 384 | :possible_values => field.possible_values.split('|'), |
|
378 |
:is_required => |
|
|
385 | :is_required => field.require_report? | |
|
379 | 386 | next unless f.save |
|
380 | 387 | print '.' |
|
381 | 388 | |
@@ -455,9 +462,9 task :migrate_from_mantis => :environment do | |||
|
455 | 462 | end |
|
456 | 463 | |
|
457 | 464 | while true |
|
458 |
print "encoding [ |
|
|
465 | print "encoding [UTF-8]: " | |
|
459 | 466 | encoding = STDIN.gets.chomp! |
|
460 |
encoding = ' |
|
|
467 | encoding = 'UTF-8' if encoding.blank? | |
|
461 | 468 | break if MantisMigrate.encoding encoding |
|
462 | 469 | puts "Invalid encoding!" |
|
463 | 470 | end |
General Comments 0
You need to be logged in to leave comments.
Login now