diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 2866c1549..57b10e5d8 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -88,7 +88,7 @@ class PhotosController < ApplicationController photo = Photo.find_by(flickr_photo_id: flickr_photo_id_param) photo ||= Photo.new(photo_params) photo.owner_id = current_member.id - photo.set_flickr_metadata + photo.set_flickr_metadata! photo end diff --git a/app/models/photo.rb b/app/models/photo.rb index a73d28825..07531672b 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -50,7 +50,11 @@ class Photo < ActiveRecord::Base end end - def set_flickr_metadata + def set_flickr_metadata! update_attributes(flickr_metadata) end + + def to_s + "#{title} by #{owner.login_name}" + end end diff --git a/db/migrate/20180118112809_add_datetaken_to_photos.rb b/db/migrate/20180118112809_add_datetaken_to_photos.rb index 42afaf23b..48fb49e51 100644 --- a/db/migrate/20180118112809_add_datetaken_to_photos.rb +++ b/db/migrate/20180118112809_add_datetaken_to_photos.rb @@ -1,5 +1,10 @@ class AddDatetakenToPhotos < ActiveRecord::Migration def change add_column :photos, :date_taken, :datetime + # Fetch from flickr, the photos updated the longest ago will be fetched first + Photo.all.order(:updated_at).each do |photo| + say "Fetch flickr data for #{photo}" + photo.set_flickr_metadata! + end end end