diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-09-02 12:00:48 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-09-02 12:00:48 +0000 |
commit | eb6ab2af50e53cf4a8037390536b5501719863e0 (patch) | |
tree | b56686e08e92e62641047a87905a082390aea8fa /lib/tasks | |
parent | 72b5cd3889778ab028ddc96127db9a7ba27e6341 (diff) | |
download | redmine-eb6ab2af50e53cf4a8037390536b5501719863e0.tar.gz redmine-eb6ab2af50e53cf4a8037390536b5501719863e0.zip |
Trac importer: 'resolution' field imported with history as a custom field.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@694 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/migrate_from_trac.rake | 83 |
1 files changed, 50 insertions, 33 deletions
diff --git a/lib/tasks/migrate_from_trac.rake b/lib/tasks/migrate_from_trac.rake index 78d9ea135..ef1d3ab38 100644 --- a/lib/tasks/migrate_from_trac.rake +++ b/lib/tasks/migrate_from_trac.rake @@ -81,36 +81,6 @@ namespace :redmine do set_table_name :ticket_custom end - class TracTicket < ActiveRecord::Base - set_table_name :ticket - set_inheritance_column :none - - # ticket changes: only migrate status changes and comments - has_many :changes, :class_name => "TracTicketChange", :foreign_key => :ticket, :conditions => "field = 'comment' OR field='status'" - has_many :attachments, :class_name => "TracAttachment", :foreign_key => :id, :conditions => "type = 'ticket'" - has_many :customs, :class_name => "TracTicketCustom", :foreign_key => :ticket - - def ticket_type - read_attribute(:type) - end - - def summary - read_attribute(:summary).blank? ? "(no subject)" : read_attribute(:summary) - end - - def description - read_attribute(:description).blank? ? summary : read_attribute(:description) - end - - def time; Time.at(read_attribute(:time)) end - end - - class TracTicketChange < ActiveRecord::Base - set_table_name :ticket_change - - def time; Time.at(read_attribute(:time)) end - end - class TracAttachment < ActiveRecord::Base set_table_name :attachment set_inheritance_column :none @@ -141,6 +111,36 @@ namespace :redmine do end end + class TracTicket < ActiveRecord::Base + set_table_name :ticket + set_inheritance_column :none + + # ticket changes: only migrate status changes and comments + has_many :changes, :class_name => "TracTicketChange", :foreign_key => :ticket + has_many :attachments, :class_name => "TracAttachment", :foreign_key => :id, :conditions => "#{TracMigrate::TracAttachment.table_name}.type = 'ticket'" + has_many :customs, :class_name => "TracTicketCustom", :foreign_key => :ticket + + def ticket_type + read_attribute(:type) + end + + def summary + read_attribute(:summary).blank? ? "(no subject)" : read_attribute(:summary) + end + + def description + read_attribute(:description).blank? ? summary : read_attribute(:description) + end + + def time; Time.at(read_attribute(:time)) end + end + + class TracTicketChange < ActiveRecord::Base + set_table_name :ticket_change + + def time; Time.at(read_attribute(:time)) end + end + class TracWikiPage < ActiveRecord::Base set_table_name :wiki end @@ -249,6 +249,15 @@ namespace :redmine do custom_field_map[field.name] = f end puts + + # Trac 'resolution' field as a Redmine custom field + r = IssueCustomField.new :name => 'Resolution', + :field_format => 'list', + :is_filter => true + r.trackers = Tracker.find(:all) + r.projects << @target_project + r.possible_values = %w(fixed invalid wontfix duplicate worksforme) + custom_field_map['resolution'] = r if r.save # Tickets print "Migrating tickets" @@ -265,6 +274,7 @@ namespace :redmine do i.status = STATUS_MAPPING[ticket.status] || DEFAULT_STATUS i.tracker = TRACKER_MAPPING[ticket.ticket_type] || DEFAULT_TRACKER i.id = ticket.id + i.custom_values << CustomValue.new(:custom_field => custom_field_map['resolution'], :value => ticket.resolution) unless ticket.resolution.blank? next unless i.save migrated_tickets += 1 @@ -274,9 +284,10 @@ namespace :redmine do i.save end - # Comments and status changes + # Comments and status/resolution changes ticket.changes.group_by(&:time).each do |time, changeset| status_change = changeset.select {|change| change.field == 'status'}.first + resolution_change = changeset.select {|change| change.field == 'resolution'}.first comment_change = changeset.select {|change| change.field == 'comment'}.first n = Journal.new :notes => (comment_change ? convert_wiki_text(encode(comment_change.newvalue)) : ''), @@ -292,7 +303,13 @@ namespace :redmine do :old_value => STATUS_MAPPING[status_change.oldvalue].id, :value => STATUS_MAPPING[status_change.newvalue].id) end - n.save + if resolution_change + n.details << JournalDetail.new(:property => 'cf', + :prop_key => custom_field_map['resolution'].id, + :old_value => resolution_change.oldvalue, + :value => resolution_change.newvalue) + end + n.save unless n.details.empty? && n.notes.blank? end # Attachments @@ -424,7 +441,7 @@ namespace :redmine do end prompt('Trac directory') {|directory| TracMigrate.set_trac_directory directory} - prompt('Database encoding', :default => 'UTF-8') {|encoding| TracMigrate.encoding encoding} + prompt('Trac database encoding', :default => 'UTF-8') {|encoding| TracMigrate.encoding encoding} prompt('Target project identifier') {|identifier| TracMigrate.target_project_identifier identifier} puts |