import users into redmine from comma delinted text file

Added by Rene Salmon over 9 years ago

Hi,

Looked around the forum and wiki but could not find anything that would help. I basically have a comma delimited text file with user ids, names and email addresses. Its a big file many entries. How would I import this to redmine as registered users?

Can i just put them in the mysql database? Thanks

Rene

Replies (5)

RE: import users into redmine from comma delinted text file - Added by Joe Chin over 9 years ago

Hi Rene,
There are 2 ways to do this. One is using an import script and another is using mysql. In my case I didn't need to import users but I did need to import our projects from an excel spreadsheet. I've included the code I have

require 'csv'

# csv issues import for redmine
# Will convert a csv into a issues bulkloader into redmine
# Column names
# row[0]=Nb Number,row[1]=Product,row[2]=Element,row[3]=Type,row[4]=Queue,
# row[5]=KeyWord,row[6]=Responsible,row[7]=Case Descriptions,row[8]=Days,
# row[9]=Planned Delivery,row[10]=Version
#

desc <<-END_DESC
Bulk loading of issues from a CSV file.

Available options:
  * filepath    => path to the text file.
  * project     => id or identifier of project

Example:
  rake redmine:csv_import filepath="~/import.csv" project="test" 
END_DESC

namespace :redmine do
    task :csv_import => :environment do
    @firstrow = true
    @count = 1

    CSV.Open(ENV['filepath'],'r') do |row|
        if not firstrow
            @i = Issue.new
                @i.project => Project.find_by_name(ENV['project'])
                # If not a feature it's a bug
                if row[3].contains("SUG")
                    @i.tracker => Tracker.find_by_id(2)
                else
                    @i.tracker => Tracker.find_by_id(1)
                end

                if row[4].contains("TOP PRIORITY)
                    @i.priority => Enumeration.find_by_id(7)
                elseif row[4].contains("HIGH PRIORITY")
                    @i.priority => Enumeration.find_by_id(5)
                elseif row[4].contains("MEDIUM PRIORITY")
                    @i.priority => Enumeration.find_by_id(4)
                else
                    @i.priority => Enumeration.find_by_id(3)
                end

                @i.author => Users.find(5)
                @i.subject => truncate(row[4], 50)
                @i.description => row[4]
                @i.status => IssuesStatus.find_by_id(1)
            @i.save
            count += 1
        end
        firstrow = nil
    end
end

For the users table I did a mysql import (matching column names, matching enumerators, etc) and that also seemed to work. You'll need to find the properties for the user class and modify my script to match.

RE: import users into redmine from comma delinted text file - Added by Rene Salmon over 9 years ago

Great! That is just what I needed. Thank you

Rene

RE: import users into redmine from comma delinted text file - Added by Nanda P over 9 years ago

Joe,

I am looking for an csv importer like this. thank you very much.

Could you please post a sample CSV file?

Regards,
Nanda

RE: import users into redmine from comma delinted text file - Added by Nanda P over 9 years ago

When I ran the rake: (Windows XP)

C:\Program Files\redmine\current\script>rake redmine:csv_import filepath="C:\issues.csv" project="test01"  --trace                       
(in C:/Program Files/redmine/current)                                           
rake aborted!                                                                   
Don't know how to build task 'redmine:csv_import'                               
C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1728:in `[]'                                                                                C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2050:in `invoke_task'                                                                       C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'                                                                         C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'                                                                              C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'                                                                         C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'                                                       C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'                                                                         C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'                                                                               C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'                                                       C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'                                                                               C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31             C:/Program Files/Ruby/bin/rake:19:in `load'                                     C:/Program Files/Ruby/bin/rake:19                                                                                                          C:\Program Files\redmine\current\script>                                        

RE: import users into redmine from comma delinted text file - Added by Se Ri over 7 years ago

Hi Joe Chin,

Could you help to guide me for detailed steps ? I dont know how to run the script you gave.

Thanks,
Seri

(1-5/5)