@@ -43,7 +43,13 namespace :redmine do | |||
|
43 | 43 | 'low' => priorities[0], |
|
44 | 44 | 'normal' => priorities[1], |
|
45 | 45 | 'high' => priorities[2], |
|
46 | 'highest' => priorities[3] | |
|
46 | 'highest' => priorities[3], | |
|
47 | # --- | |
|
48 | 'trivial' => priorities[0], | |
|
49 | 'minor' => priorities[1], | |
|
50 | 'major' => priorities[2], | |
|
51 | 'critical' => priorities[3], | |
|
52 | 'blocker' => priorities[4] | |
|
47 | 53 | } |
|
48 | 54 | |
|
49 | 55 | TRACKER_BUG = Tracker.find_by_position(1) |
@@ -143,8 +149,19 namespace :redmine do | |||
|
143 | 149 | def time; Time.at(read_attribute(:time)) end |
|
144 | 150 | end |
|
145 | 151 | |
|
152 | TRAC_WIKI_PAGES = %w(TracAccessibility TracAdmin TracBackup TracBrowser TracCgi TracChangeset \ | |
|
153 | TracEnvironment TracFastCgi TracGuide TracImport TracIni TracInstall TracInterfaceCustomization \ | |
|
154 | TracLinks TracLogging TracModPython TracNotification TracPermissions TracPlugins TracQuery \ | |
|
155 | TracReports TracRoadmap TracRss TracSearch TracStandalone TracSupport TracSyntaxColoring TracTickets \ | |
|
156 | TracTicketsCustomFields TracTimeline TracUnicode TracUpgrade TracWiki WikiDeletePage WikiFormatting \ | |
|
157 | WikiHtml WikiMacros WikiNewPage WikiPageNames WikiProcessors WikiRestructuredText WikiRestructuredTextLinks \ | |
|
158 | CamelCase TitleIndex) | |
|
159 | ||
|
146 | 160 | class TracWikiPage < ActiveRecord::Base |
|
147 | 161 |
set_table_name :wiki |
|
162 | set_primary_key :name | |
|
163 | ||
|
164 | has_many :attachments, :class_name => "TracAttachment", :foreign_key => :id, :conditions => "#{TracMigrate::TracAttachment.table_name}.type = 'wiki'" | |
|
148 | 165 | |
|
149 | 166 | def self.columns |
|
150 | 167 | # Hides readonly Trac field to prevent clash with AR readonly? method (Rails 2.0) |
@@ -203,8 +220,12 namespace :redmine do | |||
|
203 | 220 | text = text.gsub(/\[(\d+)\]/, 'r\1') |
|
204 | 221 | # Ticket number re-writing |
|
205 | 222 | text = text.gsub(/#(\d+)/) do |s| |
|
223 | if $1.length < 10 | |
|
206 | 224 | TICKET_MAP[$1.to_i] ||= $1 |
|
207 | 225 | "\##{TICKET_MAP[$1.to_i] || $1}" |
|
226 | else | |
|
227 | s | |
|
228 | end | |
|
208 | 229 | end |
|
209 | 230 | # Preformatted blocks |
|
210 | 231 | text = text.gsub(/\{\{\{/, '<pre>') |
@@ -236,6 +257,7 namespace :redmine do | |||
|
236 | 257 | migrated_custom_values = 0 |
|
237 | 258 | migrated_ticket_attachments = 0 |
|
238 | 259 | migrated_wiki_edits = 0 |
|
260 | migrated_wiki_attachments = 0 | |
|
239 | 261 | |
|
240 | 262 | # Components |
|
241 | 263 | print "Migrating components" |
@@ -384,8 +406,12 namespace :redmine do | |||
|
384 | 406 | @target_project.wiki.destroy if @target_project.wiki |
|
385 | 407 | @target_project.reload |
|
386 | 408 | wiki = Wiki.new(:project => @target_project, :start_page => 'WikiStart') |
|
409 | wiki_edit_count = 0 | |
|
387 | 410 | if wiki.save |
|
388 | 411 | TracWikiPage.find(:all, :order => 'name, version').each do |page| |
|
412 | # Do not migrate Trac manual wiki pages | |
|
413 | next if TRAC_WIKI_PAGES.include?(page.name) | |
|
414 | wiki_edit_count += 1 | |
|
389 | 415 | print '.' |
|
390 | 416 | STDOUT.flush |
|
391 | 417 | p = wiki.find_or_new_page(page.name) |
@@ -394,7 +420,20 namespace :redmine do | |||
|
394 | 420 | p.content.author = find_or_create_user(page.author) unless page.author.blank? || page.author == 'trac' |
|
395 | 421 | p.content.comments = page.comment |
|
396 | 422 | p.new_record? ? p.save : p.content.save |
|
397 | migrated_wiki_edits += 1 unless p.content.new_record? | |
|
423 | ||
|
424 | next if p.content.new_record? | |
|
425 | migrated_wiki_edits += 1 | |
|
426 | ||
|
427 | # Attachments | |
|
428 | page.attachments.each do |attachment| | |
|
429 | next unless attachment.exist? | |
|
430 | next if p.attachments.find_by_filename(attachment.filename.gsub(/^.*(\\|\/)/, '').gsub(/[^\w\.\-]/,'_')) #add only once per page | |
|
431 | a = Attachment.new :created_on => attachment.time | |
|
432 | a.file = attachment | |
|
433 | a.author = find_or_create_user(attachment.author) | |
|
434 | a.container = p | |
|
435 | migrated_wiki_attachments += 1 if a.save | |
|
436 | end | |
|
398 | 437 | end |
|
399 | 438 | |
|
400 | 439 | wiki.reload |
@@ -409,9 +448,10 namespace :redmine do | |||
|
409 | 448 | puts "Components: #{migrated_components}/#{TracComponent.count}" |
|
410 | 449 | puts "Milestones: #{migrated_milestones}/#{TracMilestone.count}" |
|
411 | 450 | puts "Tickets: #{migrated_tickets}/#{TracTicket.count}" |
|
412 |
puts "Ticket files: #{migrated_ticket_attachments}/" + TracAttachment.count( |
|
|
451 | puts "Ticket files: #{migrated_ticket_attachments}/" + TracAttachment.count(:conditions => {:type => 'ticket'}).to_s | |
|
413 | 452 | puts "Custom values: #{migrated_custom_values}/#{TracTicketCustom.count}" |
|
414 |
puts "Wiki edits: #{migrated_wiki_edits}/#{ |
|
|
453 | puts "Wiki edits: #{migrated_wiki_edits}/#{wiki_edit_count}" | |
|
454 | puts "Wiki files: #{migrated_wiki_attachments}/" + TracAttachment.count(:conditions => {:type => 'wiki'}).to_s | |
|
415 | 455 | end |
|
416 | 456 | |
|
417 | 457 | def self.limit_for(klass, attribute) |
@@ -542,7 +582,7 namespace :redmine do | |||
|
542 | 582 | |
|
543 | 583 | DEFAULT_PORTS = {'mysql' => 3306, 'postgresl' => 5432} |
|
544 | 584 | |
|
545 | prompt('Trac directory') {|directory| TracMigrate.set_trac_directory directory} | |
|
585 | prompt('Trac directory') {|directory| TracMigrate.set_trac_directory directory.strip} | |
|
546 | 586 | prompt('Trac database adapter (sqlite, sqlite3, mysql, postgresql)', :default => 'sqlite') {|adapter| TracMigrate.set_trac_adapter adapter} |
|
547 | 587 | unless %w(sqlite sqlite3).include?(TracMigrate.trac_adapter) |
|
548 | 588 | prompt('Trac database host', :default => 'localhost') {|host| TracMigrate.set_trac_db_host host} |
General Comments 0
You need to be logged in to leave comments.
Login now