Project

General

Profile

Patch #2504 ยป import_trac_ticket_keywords.diff

Jm Delehaye, 2009-01-14 09:20

View differences:

migrate_from_trac.rake (copie de travail)
449 449
        r.save!
450 450
        custom_field_map['resolution'] = r
451 451
            
452
        # Trac 'keywords' field as a Redmine custom field
453
        r = IssueCustomField.find(:first, :conditions => { :name => "Keywords" })
454
        r = IssueCustomField.new(:name => 'Keywords',
455
                                 :field_format => 'string',
456
                                 :is_filter => true) if r.nil?
457
        r.trackers = Tracker.find(:all)
458
        r.projects << @target_project
459
        #r.possible_values = (r.possible_values + %w(fixed invalid wontfix duplicate worksforme)).flatten.compact.uniq
460
        r.save!
461
        custom_field_map['keywords'] = r
462

  
463

  
452 464
        # Tickets
453 465
        print "Migrating tickets"
454 466
          TracTicket.find(:all, :order => 'id ASC').each do |ticket|
......
465 477
        	i.status = STATUS_MAPPING[ticket.status] || DEFAULT_STATUS
466 478
        	i.tracker = TRACKER_MAPPING[ticket.ticket_type] || DEFAULT_TRACKER
467 479
        	i.custom_values << CustomValue.new(:custom_field => custom_field_map['resolution'], :value => ticket.resolution) unless ticket.resolution.blank?
480
        	i.custom_values << CustomValue.new(:custom_field => custom_field_map['keywords'], :value => ticket.keywords) unless ticket.keywords.blank?
468 481
        	i.id = ticket.id unless Issue.exists?(ticket.id)
469 482
        	next unless Time.fake(ticket.changetime) { i.save }
470 483
        	TICKET_MAP[ticket.id] = i.id
......
476 489
              Time.fake(ticket.changetime) { i.save }
477 490
            end
478 491
      	
479
        	# Comments and status/resolution changes
492
        	# Comments and status/resolution/keywords changes
480 493
        	ticket.changes.group_by(&:time).each do |time, changeset|
481 494
              status_change = changeset.select {|change| change.field == 'status'}.first
482 495
              resolution_change = changeset.select {|change| change.field == 'resolution'}.first
496
              keywords_change = changeset.select {|change| change.field == 'keywords'}.first
483 497
              comment_change = changeset.select {|change| change.field == 'comment'}.first
484 498
              
485 499
              n = Journal.new :notes => (comment_change ? convert_wiki_text(encode(comment_change.newvalue)) : ''),
......
501 515
                                               :old_value => resolution_change.oldvalue,
502 516
                                               :value => resolution_change.newvalue)
503 517
              end
518
              if keywords_change
519
                n.details << JournalDetail.new(:property => 'cf',
520
                                               :prop_key => custom_field_map['keywords'].id,
521
                                               :old_value => keywords_change.oldvalue,
522
                                               :value => keywords_change.newvalue)
523
              end
504 524
              n.save unless n.details.empty? && n.notes.blank?
505 525
        	end
506 526
        	
    (1-1/1)