Trac importer improvements (patch #2050 by Karl Heinz Marbaise).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2011 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
6a8be88ad6
commit
29bad1dc95
|
@ -90,7 +90,7 @@ namespace :redmine do
|
||||||
|
|
||||||
class TracMilestone < ActiveRecord::Base
|
class TracMilestone < ActiveRecord::Base
|
||||||
set_table_name :milestone
|
set_table_name :milestone
|
||||||
|
# If this attribute is set a milestone has a defined target timepoint
|
||||||
def due
|
def due
|
||||||
if read_attribute(:due) && read_attribute(:due) > 0
|
if read_attribute(:due) && read_attribute(:due) > 0
|
||||||
Time.at(read_attribute(:due)).to_date
|
Time.at(read_attribute(:due)).to_date
|
||||||
|
@ -98,6 +98,14 @@ namespace :redmine do
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# This is the real timepoint at which the milestone has finished.
|
||||||
|
def completed
|
||||||
|
if read_attribute(:completed) && read_attribute(:completed) > 0
|
||||||
|
Time.at(read_attribute(:completed)).to_date
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def description
|
def description
|
||||||
# Attribute is named descr in Trac v0.8.x
|
# Attribute is named descr in Trac v0.8.x
|
||||||
|
@ -284,9 +292,38 @@ namespace :redmine do
|
||||||
s
|
s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# Preformatted blocks
|
# We would like to convert the Code highlighting too
|
||||||
text = text.gsub(/\{\{\{/, '<pre>')
|
# This will go into the next line.
|
||||||
text = text.gsub(/\}\}\}/, '</pre>')
|
shebang_line = false
|
||||||
|
# Reguar expression for start of code
|
||||||
|
pre_re = /\{\{\{/
|
||||||
|
# Code hightlighing...
|
||||||
|
shebang_re = /^\#\!([a-z]+)/
|
||||||
|
# Regular expression for end of code
|
||||||
|
pre_end_re = /\}\}\}/
|
||||||
|
|
||||||
|
# Go through the whole text..extract it line by line
|
||||||
|
text = text.gsub(/^(.*)$/) do |line|
|
||||||
|
m_pre = pre_re.match(line)
|
||||||
|
if m_pre
|
||||||
|
line = '<pre>'
|
||||||
|
else
|
||||||
|
m_sl = shebang_re.match(line)
|
||||||
|
if m_sl
|
||||||
|
shebang_line = true
|
||||||
|
line = '<code class="' + m_sl[1] + '">'
|
||||||
|
end
|
||||||
|
m_pre_end = pre_end_re.match(line)
|
||||||
|
if m_pre_end
|
||||||
|
line = '</pre>'
|
||||||
|
if shebang_line
|
||||||
|
line = '</code>' + line
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
line
|
||||||
|
end
|
||||||
|
|
||||||
# Highlighting
|
# Highlighting
|
||||||
text = text.gsub(/'''''([^\s])/, '_*\1')
|
text = text.gsub(/'''''([^\s])/, '_*\1')
|
||||||
text = text.gsub(/([^\s])'''''/, '\1*_')
|
text = text.gsub(/([^\s])'''''/, '\1*_')
|
||||||
|
@ -315,6 +352,12 @@ namespace :redmine do
|
||||||
migrated_ticket_attachments = 0
|
migrated_ticket_attachments = 0
|
||||||
migrated_wiki_edits = 0
|
migrated_wiki_edits = 0
|
||||||
migrated_wiki_attachments = 0
|
migrated_wiki_attachments = 0
|
||||||
|
|
||||||
|
#Wiki system initializing...
|
||||||
|
@target_project.wiki.destroy if @target_project.wiki
|
||||||
|
@target_project.reload
|
||||||
|
wiki = Wiki.new(:project => @target_project, :start_page => 'WikiStart')
|
||||||
|
wiki_edit_count = 0
|
||||||
|
|
||||||
# Components
|
# Components
|
||||||
print "Migrating components"
|
print "Migrating components"
|
||||||
|
@ -336,10 +379,20 @@ namespace :redmine do
|
||||||
TracMilestone.find(:all).each do |milestone|
|
TracMilestone.find(:all).each do |milestone|
|
||||||
print '.'
|
print '.'
|
||||||
STDOUT.flush
|
STDOUT.flush
|
||||||
|
# First we try to find the wiki page...
|
||||||
|
p = wiki.find_or_new_page(milestone.name.to_s)
|
||||||
|
p.content = WikiContent.new(:page => p) if p.new_record?
|
||||||
|
p.content.text = milestone.description.to_s
|
||||||
|
p.content.author = find_or_create_user('trac')
|
||||||
|
p.content.comments = 'Milestone'
|
||||||
|
p.save
|
||||||
|
|
||||||
v = Version.new :project => @target_project,
|
v = Version.new :project => @target_project,
|
||||||
:name => encode(milestone.name[0, limit_for(Version, 'name')]),
|
:name => encode(milestone.name[0, limit_for(Version, 'name')]),
|
||||||
:description => encode(milestone.description.to_s[0, limit_for(Version, 'description')]),
|
:description => nil,
|
||||||
:effective_date => milestone.due
|
:wiki_page_title => milestone.name.to_s,
|
||||||
|
:effective_date => milestone.completed
|
||||||
|
|
||||||
next unless v.save
|
next unless v.save
|
||||||
version_map[milestone.name] = v
|
version_map[milestone.name] = v
|
||||||
migrated_milestones += 1
|
migrated_milestones += 1
|
||||||
|
@ -462,10 +515,6 @@ namespace :redmine do
|
||||||
|
|
||||||
# Wiki
|
# Wiki
|
||||||
print "Migrating wiki"
|
print "Migrating wiki"
|
||||||
@target_project.wiki.destroy if @target_project.wiki
|
|
||||||
@target_project.reload
|
|
||||||
wiki = Wiki.new(:project => @target_project, :start_page => 'WikiStart')
|
|
||||||
wiki_edit_count = 0
|
|
||||||
if wiki.save
|
if wiki.save
|
||||||
TracWikiPage.find(:all, :order => 'name, version').each do |page|
|
TracWikiPage.find(:all, :order => 'name, version').each do |page|
|
||||||
# Do not migrate Trac manual wiki pages
|
# Do not migrate Trac manual wiki pages
|
||||||
|
@ -678,3 +727,4 @@ namespace :redmine do
|
||||||
TracMigrate.migrate
|
TracMigrate.migrate
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue