Skip to content

Commit

Permalink
update to use ok/not_okay; check for (and ignore, for now) 1062 error…
Browse files Browse the repository at this point in the history
…s importing faves; debugging
  • Loading branch information
thisisaaronland committed Jan 5, 2012
1 parent 9eab935 commit cdce3ec
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 65 deletions.
7 changes: 7 additions & 0 deletions www/flickr_faves_user.php
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions www/include/lib_db.php
Expand Up @@ -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,
Expand Down
24 changes: 9 additions & 15 deletions www/include/lib_flickr_backups.php
Expand Up @@ -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){
Expand Down Expand Up @@ -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 {}
Expand Down Expand Up @@ -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");
}

#
Expand Down Expand Up @@ -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");
}

#
Expand Down Expand Up @@ -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'];
Expand Down
13 changes: 8 additions & 5 deletions www/include/lib_flickr_faves.php
Expand Up @@ -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){
Expand All @@ -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;
}

Expand All @@ -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();
}

#################################################################
Expand Down
48 changes: 25 additions & 23 deletions www/include/lib_flickr_photos.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
41 changes: 19 additions & 22 deletions www/include/lib_flickr_photos_import.php
Expand Up @@ -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';
Expand Down Expand Up @@ -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){
Expand All @@ -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']);
Expand All @@ -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']);
}

Expand Down Expand Up @@ -149,10 +148,9 @@ function flickr_photos_import_photo($photo, $more=array()){

# go!

return array(
'ok' => 1,
return okay(array(
'photo' => $photo
);
));
}

#################################################################
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
);
));
}

#################################################################
Expand Down

0 comments on commit cdce3ec

Please sign in to comment.