@@ -85,7 +85,8 namespace :redmine do | |||||
85 | set_table_name :ticket |
|
85 | set_table_name :ticket | |
86 | set_inheritance_column :none |
|
86 | set_inheritance_column :none | |
87 |
|
87 | |||
88 | has_many :comments, :class_name => "TracTicketChange", :foreign_key => :ticket, :conditions => "field = 'comment'" |
|
88 | # ticket changes: only migrate status changes and comments | |
|
89 | has_many :changes, :class_name => "TracTicketChange", :foreign_key => :ticket, :conditions => "field = 'comment' OR field='status'" | |||
89 | has_many :attachments, :class_name => "TracAttachment", :foreign_key => :id, :conditions => "type = 'ticket'" |
|
90 | has_many :attachments, :class_name => "TracAttachment", :foreign_key => :id, :conditions => "type = 'ticket'" | |
90 | has_many :customs, :class_name => "TracTicketCustom", :foreign_key => :ticket |
|
91 | has_many :customs, :class_name => "TracTicketCustom", :foreign_key => :ticket | |
91 |
|
92 | |||
@@ -202,9 +203,7 namespace :redmine do | |||||
202 | migrated_components = 0 |
|
203 | migrated_components = 0 | |
203 | migrated_milestones = 0 |
|
204 | migrated_milestones = 0 | |
204 | migrated_tickets = 0 |
|
205 | migrated_tickets = 0 | |
205 | migrated_ticket_comments = 0 |
|
|||
206 | migrated_custom_values = 0 |
|
206 | migrated_custom_values = 0 | |
207 | trac_ticket_comments = 0 |
|
|||
208 | migrated_ticket_attachments = 0 |
|
207 | migrated_ticket_attachments = 0 | |
209 | migrated_wiki_edits = 0 |
|
208 | migrated_wiki_edits = 0 | |
210 |
|
209 | |||
@@ -238,15 +237,15 namespace :redmine do | |||||
238 |
|
237 | |||
239 | # Custom fields |
|
238 | # Custom fields | |
240 | # TODO: read trac.ini instead |
|
239 | # TODO: read trac.ini instead | |
241 |
print " |
|
240 | print "Migrating custom fields" | |
242 | custom_field_map = {} |
|
241 | custom_field_map = {} | |
243 | TracTicketCustom.find_by_sql("SELECT DISTINCT name FROM #{TracTicketCustom.table_name}").each do |field| |
|
242 | TracTicketCustom.find_by_sql("SELECT DISTINCT name FROM #{TracTicketCustom.table_name}").each do |field| | |
244 | print '.' |
|
243 | print '.' | |
245 | f = IssueCustomField.new :name => encode(field.name[0, limit_for(IssueCustomField, 'name')]), |
|
244 | f = IssueCustomField.new :name => encode(field.name[0, limit_for(IssueCustomField, 'name')]).humanize, | |
246 |
:field_format => 'string' |
|
245 | :field_format => 'string' | |
247 | :is_for_all => true |
|
|||
248 | next unless f.save |
|
246 | next unless f.save | |
249 | f.trackers = Tracker.find(:all) |
|
247 | f.trackers = Tracker.find(:all) | |
|
248 | f.projects << @target_project | |||
250 | custom_field_map[field.name] = f |
|
249 | custom_field_map[field.name] = f | |
251 | end |
|
250 | end | |
252 | puts |
|
251 | puts | |
@@ -275,16 +274,25 namespace :redmine do | |||||
275 | i.save |
|
274 | i.save | |
276 | end |
|
275 | end | |
277 |
|
276 | |||
278 | # Comments |
|
277 | # Comments and status changes | |
279 | # TODO: migrate status changes history |
|
278 | ticket.changes.group_by(&:time).each do |time, changeset| | |
280 | ticket.comments.each do |comment| |
|
279 | status_change = changeset.select {|change| change.field == 'status'}.first | |
281 | next if comment.newvalue.blank? |
|
280 | comment_change = changeset.select {|change| change.field == 'comment'}.first | |
282 | trac_ticket_comments += 1 |
|
281 | ||
283 | n = Journal.new :notes => convert_wiki_text(encode(comment.newvalue)), |
|
282 | n = Journal.new :notes => (comment_change ? convert_wiki_text(encode(comment_change.newvalue)) : ''), | |
284 |
:created_on => |
|
283 | :created_on => time | |
285 |
n.user = find_or_create_user(c |
|
284 | n.user = find_or_create_user(changeset.first.author) | |
286 | n.journalized = i |
|
285 | n.journalized = i | |
287 | migrated_ticket_comments += 1 if n.save |
|
286 | if status_change && | |
|
287 | STATUS_MAPPING[status_change.oldvalue] && | |||
|
288 | STATUS_MAPPING[status_change.newvalue] && | |||
|
289 | (STATUS_MAPPING[status_change.oldvalue] != STATUS_MAPPING[status_change.newvalue]) | |||
|
290 | n.details << JournalDetail.new(:property => 'attr', | |||
|
291 | :prop_key => 'status_id', | |||
|
292 | :old_value => STATUS_MAPPING[status_change.oldvalue].id, | |||
|
293 | :value => STATUS_MAPPING[status_change.newvalue].id) | |||
|
294 | end | |||
|
295 | n.save | |||
288 | end |
|
296 | end | |
289 |
|
297 | |||
290 | # Attachments |
|
298 | # Attachments | |
@@ -337,7 +345,6 namespace :redmine do | |||||
337 | puts "Components: #{migrated_components}/#{TracComponent.count}" |
|
345 | puts "Components: #{migrated_components}/#{TracComponent.count}" | |
338 | puts "Milestones: #{migrated_milestones}/#{TracMilestone.count}" |
|
346 | puts "Milestones: #{migrated_milestones}/#{TracMilestone.count}" | |
339 | puts "Tickets: #{migrated_tickets}/#{TracTicket.count}" |
|
347 | puts "Tickets: #{migrated_tickets}/#{TracTicket.count}" | |
340 | puts "Ticket comments: #{migrated_ticket_comments}/#{trac_ticket_comments}" |
|
|||
341 | puts "Ticket files: #{migrated_ticket_attachments}/" + TracAttachment.count("type = 'ticket'").to_s |
|
348 | puts "Ticket files: #{migrated_ticket_attachments}/" + TracAttachment.count("type = 'ticket'").to_s | |
342 | puts "Custom values: #{migrated_custom_values}/#{TracTicketCustom.count}" |
|
349 | puts "Custom values: #{migrated_custom_values}/#{TracTicketCustom.count}" | |
343 | puts "Wiki edits: #{migrated_wiki_edits}/#{TracWikiPage.count}" |
|
350 | puts "Wiki edits: #{migrated_wiki_edits}/#{TracWikiPage.count}" |
General Comments 0
You need to be logged in to leave comments.
Login now