Permalink
Browse files

store hasexif flag in the db; update everything else accordingly

  • Loading branch information...
1 parent 2c86b91 commit 8237569747e386e382889ac933c7b768f2dc9f2d straup committed Nov 21, 2011
@@ -0,0 +1,39 @@
+<?php
+
+ $root = dirname(dirname(__FILE__));
+ ini_set("include_path", "{$root}/www:{$root}/www/include");
+
+ set_time_limit(0);
+
+ #
+
+ include("include/init.php");
+
+ loadlib("backfill");
+ loadlib("flickr_photos");
+ loadlib("flickr_photos_exif");
+
+ function check_photo($row, $more=array()){
+
+ $photo = flickr_photos_get_by_id($row['id']);
+ $more = array('force' => 1);
+
+ $hasexif = flickr_photos_exif_has_exif($photo, $more);
+ # echo "photo {$photo['id']} has exif: {$hasexif}\n";
+
+ if ($hasexif){
+
+ $update = array('hasexif' => 1);
+ $rsp = flickr_photos_update_photo($photo, $update);
+
+ if (! $rsp['ok']){
+ echo "ack! failed to update {$photo['id']}: {$rsp['error']}\n";
+ }
+ }
+ }
+
+ $sql = "SELECT * FROM FlickrPhotos";
+ backfill_db_users($sql, 'check_photo');
+
+ exit();
+?>
@@ -0,0 +1 @@
+ALTER TABLE `FlickrPhotos` ADD `hasexif` TINYINT(3) UNSIGNED NOT NULL;
View
@@ -1 +1,3 @@
-These are database alters for an already running instance of parallel-flickr.
+These are database alters for an already running instance of
+parallel-flickr. You should check the date prefixes on these files against the
+date you set up your copy (of parallel-flickr).
View
@@ -16,6 +16,7 @@ CREATE TABLE `FlickrPhotos` (
`datetaken` DATETIME,
`datetakengranularity` TINYINT(3) UNSIGNED NOT NULL,
`hasgeo` TINYINT(3) UNSIGNED NOT NULL,
+ `hasexif` TINYINT(3) UNSIGNED NOT NULL,
`latitude` DECIMAL(9,6) DEFAULT NULL,
`longitude` DECIMAL(9,6) DEFAULT NULL,
`accuracy` TINYINT(3) UNSIGNED NOT NULL,
View
@@ -4,7 +4,6 @@
loadlib("flickr_photos");
loadlib("flickr_photos_metadata");
- loadlib("flickr_photos_exif");
loadlib("flickr_photos_permissions");
loadlib("flickr_geo_permissions");
@@ -51,11 +50,6 @@
# $meta = flickr_photos_metadata_load($photo);
# $GLOBALS['smarty']->assign_by_ref("metadata", $meta['data']);
- if ($is_own){
-
- $photo['has_exif'] = flickr_photos_exif_has_exif($photo);
- }
-
$photo['can_view_geo'] = ($photo['hasgeo'] && flickr_geo_permissions_can_view_photo($photo, $GLOBALS['cfg']['user']['id'])) ? 1 : 0;
if ($photo['can_view_geo']){
@@ -7,12 +7,11 @@
#################################################################
- function flickr_photos_exif_has_exif(&$photo){
+ function flickr_photos_exif_has_exif(&$photo, $more=array()){
- # THIS IS NOT IDEAL. Maybe store a hasexif flag against
- # the database on import? (20111118/straup) Anyway, for
- # now it's just for photo owners. Or at least caching or
- # something...
+ if ((isset($photo['hasexif'])) && (! isset($more['force']))){
+ return $photo['hasexif'];
+ }
$rsp = flickr_photos_exif_read($photo);
return $rsp['ok'];
@@ -76,9 +76,6 @@ function flickr_photos_import_for_nsid($nsid){
function flickr_photos_import_photo($photo, $more=array()){
- # TO DO (maybe?) : check to see whether the photo has
- # EXIF and set $photo['hasexif'] ... (201111/18/straup)
-
$user = flickr_users_ensure_user_account($photo['owner'], $photo['ownername']);
if ((! $user) || (! $user['id'])){
@@ -112,6 +109,30 @@ function flickr_photos_import_photo($photo, $more=array()){
flickr_photos_import_photo_files($photo, $more);
+ # exif data
+
+ $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);
}
@@ -123,6 +144,8 @@ function flickr_photos_import_photo($photo, $more=array()){
}
}
+ # go!
+
return array(
'ok' => 1,
'photo' => $photo
@@ -501,9 +524,6 @@ function _flickr_photos_import_prepare_photo(&$user, $photo){
unset($photo['date_faved']);
}
- # TO DO: check for EXIF data and set $photo['hasexif']
- # required db alter (20111121/straup)
-
return $photo;
}
@@ -48,7 +48,7 @@ by <a href="{$owner|@flickr_urls_photos_user}">{if $is_own}you{else}{$owner.user
<h3>Details</h3>
<ul>
-{if $photo.has_exif}<li>This photo has <a href="{$photo|@flickr_urls_photo_page}exif/">EXIF data</a>.</li>{/if}
+{if $is_own and $photo.hasexif}<li>This photo has <a href="{$photo|@flickr_urls_photo_page}exif/">EXIF data</a>.</li>{/if}
</ul>
</div>

0 comments on commit 8237569

Please sign in to comment.