Revision 693
Added by Jean-Philippe Lang almost 18 years ago
trunk/lib/tasks/migrate_from_trac.rake | ||
---|---|---|
85 | 85 |
set_table_name :ticket |
86 | 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 | 90 |
has_many :attachments, :class_name => "TracAttachment", :foreign_key => :id, :conditions => "type = 'ticket'" |
90 | 91 |
has_many :customs, :class_name => "TracTicketCustom", :foreign_key => :ticket |
91 | 92 |
|
... | ... | |
202 | 203 |
migrated_components = 0 |
203 | 204 |
migrated_milestones = 0 |
204 | 205 |
migrated_tickets = 0 |
205 |
migrated_ticket_comments = 0 |
|
206 | 206 |
migrated_custom_values = 0 |
207 |
trac_ticket_comments = 0 |
|
208 | 207 |
migrated_ticket_attachments = 0 |
209 | 208 |
migrated_wiki_edits = 0 |
210 | 209 |
|
... | ... | |
238 | 237 |
|
239 | 238 |
# Custom fields |
240 | 239 |
# TODO: read trac.ini instead |
241 |
print "Custom fields"
|
|
240 |
print "Migrating custom fields"
|
|
242 | 241 |
custom_field_map = {} |
243 | 242 |
TracTicketCustom.find_by_sql("SELECT DISTINCT name FROM #{TracTicketCustom.table_name}").each do |field| |
244 | 243 |
print '.' |
245 |
f = IssueCustomField.new :name => encode(field.name[0, limit_for(IssueCustomField, 'name')]), |
|
246 |
:field_format => 'string', |
|
247 |
:is_for_all => true |
|
244 |
f = IssueCustomField.new :name => encode(field.name[0, limit_for(IssueCustomField, 'name')]).humanize, |
|
245 |
:field_format => 'string' |
|
248 | 246 |
next unless f.save |
249 | 247 |
f.trackers = Tracker.find(:all) |
248 |
f.projects << @target_project |
|
250 | 249 |
custom_field_map[field.name] = f |
251 | 250 |
end |
252 | 251 |
puts |
... | ... | |
270 | 269 |
migrated_tickets += 1 |
271 | 270 |
|
272 | 271 |
# Owner |
273 |
unless ticket.owner.blank?
|
|
274 |
i.assigned_to = find_or_create_user(ticket.owner, true) |
|
275 |
i.save |
|
276 |
end |
|
272 |
unless ticket.owner.blank?
|
|
273 |
i.assigned_to = find_or_create_user(ticket.owner, true)
|
|
274 |
i.save
|
|
275 |
end
|
|
277 | 276 |
|
278 |
# Comments |
|
279 |
# TODO: migrate status changes history
|
|
280 |
ticket.comments.each do |comment|
|
|
281 |
next if comment.newvalue.blank?
|
|
282 |
trac_ticket_comments += 1 |
|
283 |
n = Journal.new :notes => convert_wiki_text(encode(comment.newvalue)),
|
|
284 |
:created_on => comment.time
|
|
285 |
n.user = find_or_create_user(comment.author)
|
|
277 |
# Comments and status changes
|
|
278 |
ticket.changes.group_by(&:time).each do |time, changeset|
|
|
279 |
status_change = changeset.select {|change| change.field == 'status'}.first
|
|
280 |
comment_change = changeset.select {|change| change.field == 'comment'}.first
|
|
281 |
|
|
282 |
n = Journal.new :notes => (comment_change ? convert_wiki_text(encode(comment_change.newvalue)) : ''),
|
|
283 |
:created_on => time |
|
284 |
n.user = find_or_create_user(changeset.first.author)
|
|
286 | 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 | 296 |
end |
289 | 297 |
|
290 | 298 |
# Attachments |
... | ... | |
337 | 345 |
puts "Components: #{migrated_components}/#{TracComponent.count}" |
338 | 346 |
puts "Milestones: #{migrated_milestones}/#{TracMilestone.count}" |
339 | 347 |
puts "Tickets: #{migrated_tickets}/#{TracTicket.count}" |
340 |
puts "Ticket comments: #{migrated_ticket_comments}/#{trac_ticket_comments}" |
|
341 | 348 |
puts "Ticket files: #{migrated_ticket_attachments}/" + TracAttachment.count("type = 'ticket'").to_s |
342 | 349 |
puts "Custom values: #{migrated_custom_values}/#{TracTicketCustom.count}" |
343 | 350 |
puts "Wiki edits: #{migrated_wiki_edits}/#{TracWikiPage.count}" |
Also available in: Unified diff
Trac importer now migrates status changes.