Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update to use ok/not_okay; check for (and ignore, for now) 1062 error…

…s importing faves; debugging
  • Loading branch information...
commit cdce3ecad8ca931614ac2a0c4381f1dda8fdcb7e 1 parent 9eab935
straup authored
View
7 www/flickr_faves_user.php
@@ -49,6 +49,13 @@
foreach ($faves['rows'] as $f){
$photo = flickr_photos_get_by_id($f['photo_id']);
+
+ # this shouldn't happen but does so...
+
+ if (! $photo){
+ continue;
+ }
+
$photo['owner'] = users_get_by_id($photo['user_id']);
# quick hack until perms are denormalized into the FlickrFaves table
View
1  www/include/lib_db.php
@@ -190,6 +190,7 @@ function _db_query($sql, $cluster, $k=null){
$error_code = mysql_errno($GLOBALS['db_conns'][$cluster_key]);
log_error("DB-$cluster_key: $error_code ".HtmlSpecialChars($error_msg));
+ # log_error("DB-$cluster_key: $error_code ".HtmlSpecialChars($sql));
$ret = array(
'ok' => 0,
View
24 www/include/lib_flickr_backups.php
@@ -5,6 +5,10 @@
loadlib("flickr_photos_import");
loadlib("flickr_faves_import");
+ # TO DO: add an optional flag that lets you offset the last mindate
+ # by (n) seconds in case you need to backfill but not all the way back
+ # to the start of time (20120105/straup)
+
#################################################################
function flickr_backups_type_map($string_keys=0){
@@ -51,10 +55,9 @@ function flickr_backups_create(&$user, $type_id){
$map = flickr_backups_type_map();
$backups = flickr_backups_for_user($user, $type_id);
- $rsp = array(
- 'ok' => 1,
+ $rsp = okay(array(
'backup' => $backups[$map[$type_id]],
- );
+ ));
}
else {}
@@ -130,10 +133,7 @@ function flickr_backups_get_photos(&$user){
if (! isset($backups['photos'])){
- return array(
- 'ok' => 0,
- 'error' => 'backups not registered',
- );
+ return not_okay("backups not registered");
}
#
@@ -188,10 +188,7 @@ function flickr_backups_get_faves(&$user){
if (! isset($backups['faves'])){
- return array(
- 'ok' => 0,
- 'error' => 'backups for faves not registered',
- );
+ return not_okay("backups for faves not registered");
}
#
@@ -236,10 +233,7 @@ function flickr_backups_get_contacts(&$user){
if (! isset($backups['contacts'])){
- return array(
- 'ok' => 0,
- 'error' => 'backups not registered',
- );
+ return not_okay("backups not registered");
}
$backup = $backups['contacts'];
View
13 www/include/lib_flickr_faves.php
@@ -32,6 +32,11 @@ function flickr_faves_for_user(&$user, $more=array()){
#################################################################
+ # TO DO: either suppress the 1062 errors or fetch the various
+ # rows below. It's not really a big deal except that the errors
+ # get spewed to STDOUT and are confusing and a bit angst-making
+ # (20120105/straup)
+
function flickr_faves_add_fave(&$viewer, &$photo, $date_faved=0){
if (! $date_faved){
@@ -55,7 +60,7 @@ function flickr_faves_add_fave(&$viewer, &$photo, $date_faved=0){
$rsp = db_insert_users($cluster_id, 'FlickrFaves', $insert);
- if (! $rsp['ok']){
+ if ((! $rsp['ok']) && ($rsp['error_code'] != 1062)){
return $rsp;
}
@@ -79,16 +84,14 @@ function flickr_faves_add_fave(&$viewer, &$photo, $date_faved=0){
$rsp = db_insert_users($cluster_id, 'FlickrFavesUsers', $insert);
- if (! $rsp['ok']){
+ if ((! $rsp['ok']) && ($rsp['error_code'] != 1062)){
return $rsp;
}
# TO DO: index/update the photo in solr and insert $viewer['id']
# into the faved_by column (20111123/straup)
- return array(
- 'ok' => 1
- );
+ return okay();
}
#################################################################
View
48 www/include/lib_flickr_photos.php
@@ -114,33 +114,34 @@ function flickr_photos_update_photo(&$photo, $update){
$rsp = db_update_users($cluster_id, 'FlickrPhotos', $hash, $where);
- if ($rsp['ok']){
+ if (! $rsp['ok']){
+ return $rsp;
+ }
- cache_unset($cache_key);
+ cache_unset($cache_key);
- if (($GLOBALS['cfg']['enable_feature_solr']) && ($solr_update)){
+ if (($GLOBALS['cfg']['enable_feature_solr']) && ($solr_update)){
- $photo = flickr_photos_get_by_id($photo['id']);
+ $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)
+ # 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');
+ loadlib("flickr_photos_metadata");
+ $meta = flickr_photos_metadata_fetch($photo, 'inflate');
- flickr_photos_search_index_photo($photo, $meta);
- }
+ flickr_photos_search_index_photo($photo, $meta);
}
return $rsp;
@@ -215,10 +216,11 @@ function flickr_photos_add_photo($photo){
$rsp = db_insert_users($cluster_id, 'FlickrPhotos', $insert);
- if ($rsp['ok']){
- $rsp['photo'] = $photo;
+ if (! $rsp['ok']){
+ return $rsp;
}
+ $rsp['photo'] = $photo;
return $rsp;
}
View
41 www/include/lib_flickr_photos_import.php
@@ -19,10 +19,7 @@ function flickr_photos_import_for_nsid($nsid){
$user = users_get_by_id($flickr_user['user_id']);
if (! $user){
- return array(
- 'ok' => 0,
- 'error' => 'not a valid user',
- );
+ return not_okay("not a valid user");
}
$method = 'flickr.photos.search';
@@ -53,10 +50,7 @@ function flickr_photos_import_for_nsid($nsid){
$photos = $rsp['rsp']['photos']['photo'];
if (! is_array($photos)){
- return array(
- 'ok' => 0,
- 'error' => 'no photos',
- );
+ return not_okay("no photos");
}
foreach ($photos as $photo){
@@ -82,20 +76,16 @@ function flickr_photos_import_photo($photo, $more=array()){
if ((! $user) || (! $user['id'])){
- return array(
- 'ok' => 0,
- 'error' => 'failed to retrieve user (photo owner)',
- );
+ return not_okay("failed to retrieve user (photo owner)");
}
$photo = _flickr_photos_import_prepare_photo($user, $photo);
# TO DO: error handling...
- echo "add photo {$photo['id']}\n";
-
if ($_photo = flickr_photos_get_by_id($photo['id'])){
+ echo "update photo {$photo['id']}\n";
# TO DO: make this less stupid...
unset($photo['id']);
@@ -105,7 +95,16 @@ function flickr_photos_import_photo($photo, $more=array()){
}
else {
- flickr_photos_add_photo($photo);
+
+ echo "add photo {$photo['id']}\n";
+
+ $rsp = flickr_photos_add_photo($photo);
+
+ if (! $rsp['ok']){
+ dumper("OMGWTF");
+ dumper($rsp);
+ }
+
flickr_photos_lookup_add($photo['id'], $photo['user_id']);
}
@@ -149,10 +148,9 @@ function flickr_photos_import_photo($photo, $more=array()){
# go!
- return array(
- 'ok' => 1,
+ return okay(array(
'photo' => $photo
- );
+ ));
}
#################################################################
@@ -299,8 +297,8 @@ function flickr_photos_import_photo_files(&$photo, $more=array()){
#################################################################
-
function flickr_photos_import_photo_files_s3(&$photo, $more=array()){
+
loadlib('storage_s3');
$flickr_urls = _flickr_photos_import_flickr_urls($photo, $more);
@@ -554,10 +552,9 @@ function flickr_photos_import_get_recent($nsid, $more=array()){
$args['page'] += 1;
}
- return array(
- 'ok' => 1,
+ return okay(array(
'count_imported' => $imported,
- );
+ ));
}
#################################################################
Please sign in to comment.
Something went wrong with that request. Please try again.