Fixed that Trac importer was creating duplicate custom values (#2506).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2280 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2009-01-18 11:54:56 +00:00
parent 08304afe54
commit a4882467cb

View File

@ -293,11 +293,11 @@ namespace :redmine do
text = text.gsub(/\[wiki:([^\s\]]+)\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"} text = text.gsub(/\[wiki:([^\s\]]+)\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
text = text.gsub(/\[wiki:([^\s\]]+)\s(.*)\]/) {|s| "[[#{$1.delete(',./?;|:')}|#{$2.delete(',./?;|:')}]]"} text = text.gsub(/\[wiki:([^\s\]]+)\s(.*)\]/) {|s| "[[#{$1.delete(',./?;|:')}|#{$2.delete(',./?;|:')}]]"}
# Links to pages UsingJustWikiCaps # Links to pages UsingJustWikiCaps
text = text.gsub(/([^!]|^)(^| )([A-Z][a-z]+[A-Z][a-zA-Z]+)/, '\\1\\2[[\3]]') text = text.gsub(/([^!]|^)(^| )([A-Z][a-z]+[A-Z][a-zA-Z]+)/, '\\1\\2[[\3]]')
# Normalize things that were supposed to not be links # Normalize things that were supposed to not be links
# like !NotALink # like !NotALink
text = text.gsub(/(^| )!([A-Z][A-Za-z]+)/, '\1\2') text = text.gsub(/(^| )!([A-Z][A-Za-z]+)/, '\1\2')
# Revisions links # Revisions links
text = text.gsub(/\[(\d+)\]/, 'r\1') text = text.gsub(/\[(\d+)\]/, 'r\1')
# Ticket number re-writing # Ticket number re-writing
@ -380,13 +380,13 @@ namespace :redmine do
print "Migrating components" print "Migrating components"
issues_category_map = {} issues_category_map = {}
TracComponent.find(:all).each do |component| TracComponent.find(:all).each do |component|
print '.' print '.'
STDOUT.flush STDOUT.flush
c = IssueCategory.new :project => @target_project, c = IssueCategory.new :project => @target_project,
:name => encode(component.name[0, limit_for(IssueCategory, 'name')]) :name => encode(component.name[0, limit_for(IssueCategory, 'name')])
next unless c.save next unless c.save
issues_category_map[component.name] = c issues_category_map[component.name] = c
migrated_components += 1 migrated_components += 1
end end
puts puts
@ -452,32 +452,31 @@ namespace :redmine do
# Tickets # Tickets
print "Migrating tickets" print "Migrating tickets"
TracTicket.find(:all, :order => 'id ASC').each do |ticket| TracTicket.find(:all, :order => 'id ASC').each do |ticket|
print '.' print '.'
STDOUT.flush STDOUT.flush
i = Issue.new :project => @target_project, i = Issue.new :project => @target_project,
:subject => encode(ticket.summary[0, limit_for(Issue, 'subject')]), :subject => encode(ticket.summary[0, limit_for(Issue, 'subject')]),
:description => convert_wiki_text(encode(ticket.description)), :description => convert_wiki_text(encode(ticket.description)),
:priority => PRIORITY_MAPPING[ticket.priority] || DEFAULT_PRIORITY, :priority => PRIORITY_MAPPING[ticket.priority] || DEFAULT_PRIORITY,
:created_on => ticket.time :created_on => ticket.time
i.author = find_or_create_user(ticket.reporter) i.author = find_or_create_user(ticket.reporter)
i.category = issues_category_map[ticket.component] unless ticket.component.blank? i.category = issues_category_map[ticket.component] unless ticket.component.blank?
i.fixed_version = version_map[ticket.milestone] unless ticket.milestone.blank? i.fixed_version = version_map[ticket.milestone] unless ticket.milestone.blank?
i.status = STATUS_MAPPING[ticket.status] || DEFAULT_STATUS i.status = STATUS_MAPPING[ticket.status] || DEFAULT_STATUS
i.tracker = TRACKER_MAPPING[ticket.ticket_type] || DEFAULT_TRACKER i.tracker = TRACKER_MAPPING[ticket.ticket_type] || DEFAULT_TRACKER
i.custom_values << CustomValue.new(:custom_field => custom_field_map['resolution'], :value => ticket.resolution) unless ticket.resolution.blank? i.id = ticket.id unless Issue.exists?(ticket.id)
i.id = ticket.id unless Issue.exists?(ticket.id) next unless Time.fake(ticket.changetime) { i.save }
next unless Time.fake(ticket.changetime) { i.save } TICKET_MAP[ticket.id] = i.id
TICKET_MAP[ticket.id] = i.id migrated_tickets += 1
migrated_tickets += 1
# Owner # Owner
unless ticket.owner.blank? unless ticket.owner.blank?
i.assigned_to = find_or_create_user(ticket.owner, true) i.assigned_to = find_or_create_user(ticket.owner, true)
Time.fake(ticket.changetime) { i.save } Time.fake(ticket.changetime) { i.save }
end end
# Comments and status/resolution changes # Comments and status/resolution changes
ticket.changes.group_by(&:time).each do |time, changeset| ticket.changes.group_by(&:time).each do |time, changeset|
status_change = changeset.select {|change| change.field == 'status'}.first status_change = changeset.select {|change| change.field == 'status'}.first
resolution_change = changeset.select {|change| change.field == 'resolution'}.first resolution_change = changeset.select {|change| change.field == 'resolution'}.first
comment_change = changeset.select {|change| change.field == 'comment'}.first comment_change = changeset.select {|change| change.field == 'comment'}.first
@ -502,28 +501,32 @@ namespace :redmine do
:value => resolution_change.newvalue) :value => resolution_change.newvalue)
end end
n.save unless n.details.empty? && n.notes.blank? n.save unless n.details.empty? && n.notes.blank?
end end
# Attachments # Attachments
ticket.attachments.each do |attachment| ticket.attachments.each do |attachment|
next unless attachment.exist? next unless attachment.exist?
a = Attachment.new :created_on => attachment.time a = Attachment.new :created_on => attachment.time
a.file = attachment a.file = attachment
a.author = find_or_create_user(attachment.author) a.author = find_or_create_user(attachment.author)
a.container = i a.container = i
a.description = attachment.description a.description = attachment.description
migrated_ticket_attachments += 1 if a.save migrated_ticket_attachments += 1 if a.save
end end
# Custom fields # Custom fields
ticket.customs.each do |custom| custom_values = ticket.customs.inject({}) do |h, custom|
next if custom_field_map[custom.name].nil? if custom_field = custom_field_map[custom.name]
v = CustomValue.new :custom_field => custom_field_map[custom.name], h[custom_field.id] = custom.value
:value => custom.value
v.customized = i
next unless v.save
migrated_custom_values += 1 migrated_custom_values += 1
end end
h
end
if custom_field_map['resolution'] && !ticket.resolution.blank?
custom_values[custom_field_map['resolution'].id] = ticket.resolution
end
i.custom_field_values = custom_values
i.save_custom_field_values
end end
# update issue id sequence if needed (postgresql) # update issue id sequence if needed (postgresql)