convert mod/follow to associative json and add more logging for when things go wrong

This commit is contained in:
friendica 2013-01-29 02:04:07 -08:00
parent 3cf3f7437e
commit b2d03eb55c
2 changed files with 25 additions and 15 deletions

View File

@ -37,14 +37,26 @@ function new_contact($uid,$url,$channel,$interactive = false) {
$ret = zot_finger($url,$channel); $ret = zot_finger($url,$channel);
if($ret['success']) { if($ret['success']) {
$j = json_decode($ret['body']); $j = json_decode($ret['body'],true);
}
else {
$result['message'] = t('Channel discovery failed. Website may be down or misconfigured.');
logger('mod_follow: ' . $result['message']);
return $result;
} }
logger('follow: ' . $url . ' ' . print_r($j,true)); logger('follow: ' . $url . ' ' . print_r($j,true));
if(! ($j->success && $j->guid)) { if(! $j) {
$result['message'] = t('Unable to communicate with requested channel.'); $result['message'] = t('Response from remote channel was not understood.');
logger('mod_follow: ' . $result['message']);
return $result;
}
if(! ($j['success'] && $j['guid'])) {
$result['message'] = t('Response from remote channel was incomplete.');
logger('mod_follow: ' . $result['message']);
return $result; return $result;
} }
@ -66,7 +78,7 @@ function new_contact($uid,$url,$channel,$interactive = false) {
// do we have an xchan and hubloc? // do we have an xchan and hubloc?
// If not, create them. // If not, create them.
$x = import_xchan_from_json($j); $x = import_xchan($j);
if(! $x['success']) if(! $x['success'])
return $x; return $x;
@ -78,18 +90,18 @@ function new_contact($uid,$url,$channel,$interactive = false) {
$global_perms = get_perms(); $global_perms = get_perms();
if($j->permissions->data) { if( array_key_exists('permissions',$j) && array_key_exists('data',$j['permissions'])) {
$permissions = aes_unencapsulate(array( $permissions = aes_unencapsulate(array(
'data' => $j->permissions->data, 'data' => $j['permissions']['data'],
'key' => $j->permissions->key, 'key' => $j['permissions']['key'],
'iv' => $j->permissions->iv), 'iv' => $j['permissions']['iv']),
$channel['channel_prvkey']); $channel['channel_prvkey']);
if($permissions) if($permissions)
$permissions = json_decode($permissions); $permissions = json_decode($permissions,true);
logger('decrypted permissions: ' . print_r($permissions,true), LOGGER_DATA); logger('decrypted permissions: ' . print_r($permissions,true), LOGGER_DATA);
} }
else else
$permissions = $j->permissions; $permissions = $j['permissions'];
foreach($permissions as $k => $v) { foreach($permissions as $k => $v) {
if($v) { if($v) {

View File

@ -38,7 +38,7 @@ function onepoll_run($argv, $argc){
FROM abook LEFT JOIN account on abook_account = account_id left join xchan on xchan_hash = abook_xchan FROM abook LEFT JOIN account on abook_account = account_id left join xchan on xchan_hash = abook_xchan
where abook_id = %d where abook_id = %d
AND (( abook_flags = %d ) OR ( abook_flags = %d )) AND (( abook_flags = %d ) OR ( abook_flags = %d ))
AND (( account_flags = %d ) OR ( account_flags = %d )) ORDER BY RAND()", AND (( account_flags = %d ) OR ( account_flags = %d )) limit 1",
intval($contact_id), intval($contact_id),
intval(ABOOK_FLAG_HIDDEN), intval(ABOOK_FLAG_HIDDEN),
intval(0), intval(0),
@ -47,12 +47,10 @@ function onepoll_run($argv, $argc){
); );
if(! $contacts) { if(! $contacts) {
logger('onepoll: abook_id not found: ' . $contact_id);
return; return;
} }
if(! $contacts)
return;
$contact = $contacts[0]; $contact = $contacts[0];
$t = $contact['abook_updated']; $t = $contact['abook_updated'];