##// END OF EJS Templates
Trac importer now checks the existence of trac.db and attachments directory before processing....
Jean-Philippe Lang -
r681:a2439f3b34c3
parent child
Show More
@@ -136,7 +136,7 namespace :redmine do
136 136 def trac_fullpath
137 137 attachment_type = read_attribute(:type)
138 138 trac_file = filename.gsub( /[^a-zA-Z0-9\-_\.!~*']/n ) {|x| sprintf('%%%02x', x[0]) }
139 "#{TracMigrate.trac_directory}/attachments/#{attachment_type}/#{id}/#{trac_file}"
139 "#{TracMigrate.trac_attachments_directory}/#{attachment_type}/#{id}/#{trac_file}"
140 140 end
141 141 end
142 142
@@ -350,19 +350,38 namespace :redmine do
350 350 def self.encoding(charset)
351 351 @ic = Iconv.new('UTF-8', charset)
352 352 rescue Iconv::InvalidEncoding
353 puts "Invalid encoding!"
353 354 return false
354 355 end
355 356
356 def self.trac_directory=(path)
357 @trac_directory = path if File.directory?(path)
357 def self.set_trac_directory(path)
358 @trac_directory = path
359 raise "This directory doesn't exist!" unless File.directory?(path)
360 raise "#{trac_db_path} doesn't exist!" unless File.exist?(trac_db_path)
361 raise "#{trac_attachments_directory} doesn't exist!" unless File.directory?(trac_attachments_directory)
362 @trac_directory
363 rescue Exception => e
364 puts e
365 return false
358 366 end
359 367
360 368 def self.trac_directory
361 369 @trac_directory
362 370 end
363 371
372 def self.trac_db_path; "#{trac_directory}/db/trac.db" end
373 def self.trac_attachments_directory; "#{trac_directory}/attachments" end
374
364 375 def self.target_project_identifier(identifier)
365 @target_project = Project.find_by_identifier(identifier)
376 project = Project.find_by_identifier(identifier)
377 if !project
378 # create the target project
379 project = Project.new :name => identifier.humanize,
380 :description => identifier.humanize
381 project.identifier = identifier
382 puts "Unable to create a project with identifier '#{identifier}'!" unless project.save
383 end
384 @target_project = project.new_record? ? nil : project
366 385 end
367 386
368 387 def self.establish_connection(params)
@@ -387,30 +406,23 namespace :redmine do
387 406 break unless STDIN.gets.match(/^y$/i)
388 407 puts
389 408
409 def prompt(text, options = {}, &block)
410 default = options[:default] || ''
390 411 while true
391 print "Trac directory: "
392 directory = STDIN.gets.chomp!
393 TracMigrate.trac_directory = directory
394 break if TracMigrate.trac_directory
395 puts " This directory doesn't exist!"
412 print "#{text} [#{default}]: "
413 value = STDIN.gets.chomp!
414 value = default if value.blank?
415 break if yield value
396 416 end
397 while true
398 print "Database encoding [UTF-8]: "
399 encoding = STDIN.gets.chomp!
400 encoding = 'UTF-8' if encoding.blank?
401 break if TracMigrate.encoding encoding
402 puts " Invalid encoding!"
403 end
404 while true
405 print "Target project identifier: "
406 identifier = STDIN.gets.chomp!
407 break if TracMigrate.target_project_identifier identifier
408 puts " Project not found in Redmine database!"
409 417 end
418
419 prompt('Trac directory') {|directory| TracMigrate.set_trac_directory directory}
420 prompt('Database encoding', :default => 'UTF-8') {|encoding| TracMigrate.encoding encoding}
421 prompt('Target project identifier') {|identifier| TracMigrate.target_project_identifier identifier}
410 422 puts
411 423
412 424 TracMigrate.establish_connection({:adapter => 'sqlite',
413 :database => "#{TracMigrate.trac_directory}/db/trac.db"})
425 :database => "#{TracMigrate.trac_db_path}"})
414 426 TracMigrate.migrate
415 427 end
416 428 end
General Comments 0
You need to be logged in to leave comments. Login now