function flickr_photos_import_photo($photo, $more = array()) { log_info("get ready to import a photo..."); $user = flickr_users_ensure_user_account($photo['owner'], $photo['ownername']); if (!$user || !$user['id']) { return not_okay("failed to retrieve user (photo owner)"); } $photo = _flickr_photos_import_prepare_photo($user, $photo); # log_info("photo..." . var_export($photo, 1)); # TO DO: error handling... if ($_photo = flickr_photos_get_by_id($photo['id'])) { log_info("update photo {$photo['id']}"); # TO DO: make this less stupid... unset($photo['id']); flickr_photos_update_photo($_photo, $photo); $photo = flickr_photos_get_by_id($_photo['id']); } else { log_info("add photo {$photo['id']}"); $rsp = flickr_photos_add_photo($photo); if (!$rsp['ok']) { log_info("FAILED to add photo {$photo['id']} :" . var_export($rsp, 1)); return $rsp; } flickr_photos_lookup_add($photo['id'], $photo['user_id']); } flickr_photos_import_photo_files($photo, $more); # exif data # why did I do this? (20111206/straup) # $more = array( # 'force' => 1, # ); if ($hasexif = flickr_photos_exif_has_exif($photo, $more)) { $update = array('hasexif' => 1); $rsp = flickr_photos_update_photo($photo, $update); # technically we'll have the old last_update date # but that shouldn't be a problem (20111121/straup) if ($rsp['ok']) { $photo = array_merge($photo, $update); } } # things that depend on solr (move to a separate function?) if ($GLOBALS['cfg']['enable_feature_solr']) { flickr_photos_search_index_photo($photo); } if ($GLOBALS['cfg']['enable_feature_solr'] && $GLOBALS['cfg']['enable_feature_places']) { if ($photo['woeid'] && $GLOBALS['cfg']['places_prefetch_data']) { flickr_places_get_by_woeid($photo['woeid']); } } # go! return okay(array('photo' => $photo)); }
function index_photo($row, $more = array()) { $photo = flickr_photos_get_by_id($row['id']); $rsp = flickr_photos_search_index_photo($photo); }
function flickr_photos_update_photo(&$photo, $update) { $cache_key = "photo_{$photo['id']}"; # $lookup = flickr_photos_lookup_photo($photo['id']); if (!$lookup) { return; } $user = users_get_by_id($lookup['user_id']); $cluster_id = $user['cluster_id']; $enc_id = AddSlashes($photo['id']); $where = "id={$enc_id}"; # see also: git:parallel-flickr/solr/conf/schema.xml $solr_fields = array('perms', 'geoperms', 'geocontext', 'media', 'latitude', 'longitude', 'accuracy', 'woeid', 'datetaken', 'dateupload', 'title', 'description'); $solr_update = 0; $hash = array(); foreach ($update as $k => $v) { $hash[$k] = AddSlashes($v); if (in_array($k, $solr_fields)) { $solr_update++; } } $rsp = db_update_users($cluster_id, 'FlickrPhotos', $hash, $where); if (!$rsp['ok']) { return $rsp; } cache_unset($cache_key); if ($GLOBALS['cfg']['enable_feature_solr'] && $solr_update) { $photo = flickr_photos_get_by_id($photo['id']); # This is a quick hack that may become permanent. Basically # we need to refetch the data in flickr.photos.getInfo in # order to update the solr db. Normally the _index_photo pulls # this information from disk; the files having been written # by the bin/backup_photos.php script. As I write this the www # server does not have write permissions on the static photos # directory. If it did, this whole problem would go away and in # the end that may be the simplest possible solution. Until then # we'll fetch the (meta) data directly from the API and force # feed it to the search indexer. If you're wondering: Yes, it means # that the local solr db and the actual JSON dump of photos.getInfo # will be out of sync but that will sort itself out the next # time bin/backup_photos.php is run (20111231/straup) loadlib("flickr_photos_metadata"); $meta = flickr_photos_metadata_fetch($photo, 'inflate'); flickr_photos_search_index_photo($photo, $meta); } return $rsp; }