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
1 changed files with 130 additions and 127 deletions

View File

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