##// 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 def trac_fullpath
136 def trac_fullpath
137 attachment_type = read_attribute(:type)
137 attachment_type = read_attribute(:type)
138 trac_file = filename.gsub( /[^a-zA-Z0-9\-_\.!~*']/n ) {|x| sprintf('%%%02x', x[0]) }
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 end
140 end
141 end
141 end
142
142
@@ -350,19 +350,38 namespace :redmine do
350 def self.encoding(charset)
350 def self.encoding(charset)
351 @ic = Iconv.new('UTF-8', charset)
351 @ic = Iconv.new('UTF-8', charset)
352 rescue Iconv::InvalidEncoding
352 rescue Iconv::InvalidEncoding
353 return false
353 puts "Invalid encoding!"
354 return false
354 end
355 end
355
356
356 def self.trac_directory=(path)
357 def self.set_trac_directory(path)
357 @trac_directory = path if File.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 end
366 end
359
367
360 def self.trac_directory
368 def self.trac_directory
361 @trac_directory
369 @trac_directory
362 end
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 def self.target_project_identifier(identifier)
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 end
385 end
367
386
368 def self.establish_connection(params)
387 def self.establish_connection(params)
@@ -386,31 +405,24 namespace :redmine do
386 print "Are you sure you want to continue ? [y/N] "
405 print "Are you sure you want to continue ? [y/N] "
387 break unless STDIN.gets.match(/^y$/i)
406 break unless STDIN.gets.match(/^y$/i)
388 puts
407 puts
389
408
390 while true
409 def prompt(text, options = {}, &block)
391 print "Trac directory: "
410 default = options[:default] || ''
392 directory = STDIN.gets.chomp!
411 while true
393 TracMigrate.trac_directory = directory
412 print "#{text} [#{default}]: "
394 break if TracMigrate.trac_directory
413 value = STDIN.gets.chomp!
395 puts " This directory doesn't exist!"
414 value = default if value.blank?
396 end
415 break if yield value
397 while true
416 end
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 end
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 puts
422 puts
411
423
412 TracMigrate.establish_connection({:adapter => 'sqlite',
424 TracMigrate.establish_connection({:adapter => 'sqlite',
413 :database => "#{TracMigrate.trac_directory}/db/trac.db"})
425 :database => "#{TracMigrate.trac_db_path}"})
414 TracMigrate.migrate
426 TracMigrate.migrate
415 end
427 end
416 end
428 end
General Comments 0
You need to be logged in to leave comments. Login now