Created
November 24, 2011 01:20
-
-
Save zackham/1390419 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Set best for based on description from tom (cycling and walking only)' | |
task :batch_set_initial_best_for => :environment do | |
modified = [] | |
unmodified = 0 | |
[ | |
[ | |
# walking types | |
[11, 27, 28, 18], | |
# walking best for | |
11, | |
], | |
[ | |
# cycling types | |
[25, 21, 22], | |
# cycling best for | |
25 | |
] | |
].each do |(best_for_types,best_for)| | |
route_ids = ActiveRecord::Base.connection.select_rows("SELECT DISTINCT route_id FROM recreation_types_routes WHERE recreation_type_id IN (#{best_for_types.join(',')})").map(&:first) | |
Route.find(route_ids).each do |r| | |
begin | |
if r.mongoid_route.best_for_id | |
puts "route #{r.id} already has best for: #{r.mongoid_route.best_for_id}" | |
unmodified += 1 | |
else | |
r.mongoid_route.best_for_id = best_for | |
r.mongoid_route.save | |
modified << r.id | |
end | |
rescue | |
puts "Working on route #{r.id} threw an exception, skipping" | |
end | |
end | |
end | |
puts "Unmodified: #{unmodified}" | |
puts "Successfully modified: #{modified.size}" | |
puts "IDs of routes modified: #{modified.join(',')}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment