Permalink
Browse files

add import/export f users

  • Loading branch information...
1 parent b24f679 commit db97375c84a569aa5071baceaa20042ae64e760b @geraldb geraldb committed Dec 11, 2012
Showing with 45 additions and 12 deletions.
  1. +0 −6 app/controllers/admin/jobs_controller.rb
  2. +35 −4 lib/backup.rb
  3. +1 −0 lib/tasks/load_uss_others.rake
  4. +9 −2 lib/tasks/recalc.rake
@@ -216,12 +216,6 @@ def export
txt = ">> Export (#{Time.now}):\r\n\r\n"
- ## export users first
- User.all.each do |user|
- txt << "user-#{user.id},#{user.key},#{user.name},#{user.email},#{user.password_digest},#{user.admin},#{user.guest},#{user.active}"
- txt << "\r\n"
- end
-
Play.all.each do |play|
## always export all plays for now
View
@@ -1,4 +1,19 @@
+def export_users
+
+ ## NB: use rake export_users (see lib/tasks or rake -T)
+
+ puts "## Users"
+ puts ""
+
+ User.all.each do |user|
+ puts "user-#{user.id},#{user.key},#{user.name},#{user.email},#{user.password_digest},#{user.admin},#{user.guest},#{user.active}"
+ end
+
+ puts "DONE - - #{User.count} Users."
+
+end
+
def update_import_export_keys
@@ -35,9 +50,9 @@ def update_import_export_keys
puts "<< DONE - #{User.count} Users, #{Game.count} Games, #{Pool.count} Pools."
end
-
def import_backup_data( data ) # data as all-in-one string
+ user_count = 0
tip_count = 0
play_count = 0
@@ -58,7 +73,15 @@ def import_backup_data( data ) # data as all-in-one string
puts "#{i+1}: $#{line}$"
puts " $#{fields.join('|')}$"
- if fields[0].starts_with?( 'play' )
+ if fields[0].starts_with?( 'user' )
+ user = User.find_by_key!( fields[1] )
+ # 2 - name
+ # 3 - email
+ user.password_digest = fields[4]
+ user.save!
+
+ user_count += 1
+ elsif fields[0].starts_with?( 'play' )
user = User.find_by_key!( fields[1] )
pool = Pool.find_by_key!( fields[2] )
@@ -80,7 +103,15 @@ def import_backup_data( data ) # data as all-in-one string
elsif fields[0].starts_with?( 'tip' )
user = User.find_by_key!( fields[1] )
pool = Pool.find_by_key!( fields[2] )
- game = Game.find_by_key!( fields[3] )
+
+ ## nb: import hack for world.quali.euro.2012/13 - ignore round; just use teams for lookup
+ if fields[3] =~ /world.quali.euro.2012\/13.+\+([a-z]{3})\+([a-z]{3})/
+ team1 = Team.find_by_key!( $1 )
+ team2 = Team.find_by_key!( $2 )
+ game = Game.find_by_team1_id_and_team2_id!( team1.id, team2.id )
+ else
+ game = Game.find_by_key!( fields[3] )
+ end
tip = Tip.find_by_user_id_and_pool_id_and_game_id( user.id, pool.id, game.id )
if tip.nil?
@@ -113,6 +144,6 @@ def import_backup_data( data ) # data as all-in-one string
end # each lines
puts ""
- puts "<< DONE - #{play_count} Plays, #{tip_count} Tips."
+ puts "<< DONE - #{play_count} Plays, #{tip_count} Tips, #{user_count} Users."
end # method import_backup_data
@@ -103,3 +103,4 @@ task :load_uss_others_data => [:environment] do |t|
Prop.create!( :key => 'db.data.uss.others.version', :value => '1' )
end
+
View
@@ -1,7 +1,14 @@
-desc "wettpool: recalc points for all pools"
+desc "sportbook: recalc points for all pools"
task :recalc => [:environment] do |t|
recalc()
-end
+end
+
+desc "sportbook: export all users"
+task :export_users => [:environment] do |t|
+
+ export_users()
+
+end

0 comments on commit db97375

Please sign in to comment.