Commit 47e920d678c6e6800db783568c0a6162b4bbdd14
1 parent
e7dc0a3b
Exists in
master
and in
1 other branch
Pruning errant skips caused by bug
Showing
1 changed file
with
31 additions
and
1 deletions
Show diff stats
lib/tasks/prune_db.rake
| @@ -30,7 +30,37 @@ namespace :prune_db do | @@ -30,7 +30,37 @@ namespace :prune_db do | ||
| 30 | else | 30 | else |
| 31 | puts "Could not find any bad votes. Yay." | 31 | puts "Could not find any bad votes. Yay." |
| 32 | end | 32 | end |
| 33 | - | 33 | + end |
| 34 | + | ||
| 35 | + task(:associate_skips_with_appearances => :environment) do | ||
| 36 | + skips_to_fix = Skip.find(:all, :conditions => {:appearance_id => nil}) | ||
| 37 | + skips_to_fix.each do |skip| | ||
| 38 | + puts "Skip #{skip.id} : " | ||
| 39 | + possible_appearances = skip.skipper.appearances.find(:all, :conditions => {:prompt_id => skip.prompt_id}) | ||
| 40 | + if possible_appearances.nil? || possible_appearances.empty? | ||
| 41 | + puts " I couldn't find any matches!" | ||
| 42 | + skip.delete | ||
| 43 | + next | ||
| 44 | + end | ||
| 45 | + if possible_appearances.size > 1 | ||
| 46 | + puts " More than one possible appearance" | ||
| 47 | + possible_appearances.delete_if{|a| a.answered?} | ||
| 48 | + if possible_appearances.size > 1 || possible_appearances.size == 0 | ||
| 49 | + puts" And I couldn't narrow it down.... moving on" | ||
| 50 | + skip.delete | ||
| 51 | + next | ||
| 52 | + end | ||
| 53 | + end | ||
| 54 | + possible_appearance = possible_appearances.first | ||
| 55 | + if possible_appearance.answered? | ||
| 56 | + puts " This appearance has been answered already! Moving on" | ||
| 57 | + skip.delete | ||
| 58 | + else | ||
| 59 | + puts " MATCH" | ||
| 60 | + skip.appearance_id = possible_appearance.id | ||
| 61 | + skip.save! | ||
| 62 | + end | ||
| 63 | + end | ||
| 34 | end | 64 | end |
| 35 | 65 | ||
| 36 | end | 66 | end |