Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace :db do
- desc "Import maps from userlevel format. When passing the file path argument, escape the [] with \."
- task :import_userlevels, :file, :needs => :environment do |t, args|
- path = "#{Rails.root}/#{args["file"]}"
- unless File.exist?(path)
- puts "That file could not be found. (Looking for #{path})"
- exit
- else
- f = File.new(path).read
- maps = f.split(/[\$]/).map{|x|x.split("#")}
- for m in maps[1..maps.length] do
- map = Map.create(:title => m[0], :mapdata => m[3])
- map.tag_list = m[2]
- if((user = User.where(:login => m[1])[0]).nil?)
- puts "Couldn't find user #{m[1]} in the database, creating."
- user = User.create(:login => m[1], :crypted_password => "", :password_salt => "")
- user.persistence_token = ""
- user.save(false)
- end
- map.users << user
- map.save
- end
- puts "All imported."
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement