Index: /Library/WebServer/Documents/redmine/lib/tasks/migrate_from_trac.rake =================================================================== --- /Library/WebServer/Documents/redmine/lib/tasks/migrate_from_trac.rake (revision 3757) +++ /Library/WebServer/Documents/redmine/lib/tasks/migrate_from_trac.rake (working copy) @@ -68,6 +68,8 @@ ROLE_MAPPING = {'admin' => manager_role, 'developer' => developer_role } + + PROJECT_CUSTOM_FIELD_VALUES = {} class ::Time class << self @@ -657,6 +659,17 @@ @@trac_db_schema = schema end + def self.set_project_custom_field_value(custom_field, val) + PROJECT_CUSTOM_FIELD_VALUES[custom_field.id] = val + + # validate input + v = CustomValue.new(:custom_field => custom_field.clone, :value => val, :customized => nil) + + # Return false if value is not valid + v.errors.each_full { |msg| puts msg } if !v.valid? + v.valid? + end + mattr_reader :trac_directory, :trac_adapter, :trac_db_host, :trac_db_port, :trac_db_name, :trac_db_schema, :trac_db_username, :trac_db_password def self.trac_db_path; "#{trac_directory}/db/trac.db" end @@ -668,10 +681,15 @@ # create the target project project = Project.new :name => identifier.humanize, :description => '' + project.custom_field_values = PROJECT_CUSTOM_FIELD_VALUES project.identifier = identifier - puts "Unable to create a project with identifier '#{identifier}'!" unless project.save - # enable issues and wiki for the created project - project.enabled_module_names = ['issue_tracking', 'wiki'] + if project.save + # enable issues and wiki for the created project + project.enabled_module_names = ['issue_tracking', 'wiki'] + else + puts "Unable to create a project with identifier '#{identifier}'!" + project.errors.each_full { |msg| puts msg } + end else puts puts "This project already exists in your Redmine database." @@ -756,6 +774,21 @@ prompt('Trac database password') {|password| TracMigrate.set_trac_db_password password} end prompt('Trac database encoding', :default => 'UTF-8') {|encoding| TracMigrate.encoding encoding} + + Project.new.custom_field_values.each do |custom_field_value| + custom_field = custom_field_value.custom_field + + name = custom_field.name + options = {} + + name += '*' if custom_field.is_required + options[:default] = custom_field.default_value if custom_field.default_value + + prompt(name, options) do |val| + TracMigrate.set_project_custom_field_value custom_field, val + end + end + prompt('Target project identifier') {|identifier| TracMigrate.target_project_identifier identifier} puts