externals/discover: try up to 3 times to find a site that actually has content. Then give up until the next queue run.

This commit is contained in:
friendica 2014-03-28 15:58:58 -07:00
parent 6925cf9fe5
commit fc5f3f4800

View File

@ -9,51 +9,56 @@ function externals_run($argv, $argc){
cli_startup(); cli_startup();
$a = get_app(); $a = get_app();
$total = 0;
$attempts = 0;
// pull in some public posts // pull in some public posts
$arr = array('url' => '');
call_hooks('externals_url_select',$arr);
if($arr['url']) { while($total == 0 && $attempts < 3) {
$url = $arr['url']; $arr = array('url' => '');
} call_hooks('externals_url_select',$arr);
else {
$r = q("select site_url from site where site_url != '%s' and site_flags != %d order by rand() limit 1",
dbesc(z_root()),
intval(DIRECTORY_MODE_STANDALONE)
);
if($r)
$url = $r[0]['site_url'];
}
if($url) { if($arr['url']) {
logger('externals: pulling public content from ' . $url, LOGGER_DEBUG); $url = $arr['url'];
$days = get_config('externals','since_days'); }
if($days === false) else {
$days = 15; $r = q("select site_url from site where site_url != '%s' and site_flags != %d order by rand() limit 1",
dbesc(z_root()),
intval(DIRECTORY_MODE_STANDALONE)
);
if($r)
$url = $r[0]['site_url'];
}
$feedurl = $url . '/zotfeed?f=&mindate=' . urlencode(datetime_convert('','','now - ' . intval($days) . ' days')); $attempts ++;
logger('externals: pulling public content from ' . $feedurl, LOGGER_DEBUG); if($url) {
$x = z_fetch_url($feedurl); $days = get_config('externals','since_days');
if($days === false)
$days = 15;
if(($x) && ($x['success'])) { $feedurl = $url . '/zotfeed?f=&mindate=' . urlencode(datetime_convert('','','now - ' . intval($days) . ' days'));
$total = 0;
$j = json_decode($x['body'],true); logger('externals: pulling public content from ' . $feedurl, LOGGER_DEBUG);
if($j['success'] && $j['messages']) { $x = z_fetch_url($feedurl);
$sys = get_sys_channel();
foreach($j['messages'] as $message) { if(($x) && ($x['success'])) {
$results = process_delivery(array('hash' => 'undefined'), get_item_elements($message), $j = json_decode($x['body'],true);
array(array('hash' => $sys['xchan_hash'])), false, true); if($j['success'] && $j['messages']) {
$total ++; $sys = get_sys_channel();
foreach($j['messages'] as $message) {
$results = process_delivery(array('hash' => 'undefined'), get_item_elements($message),
array(array('hash' => $sys['xchan_hash'])), false, true);
$total ++;
}
logger('externals: import_public_posts: ' . $total . ' messages imported', LOGGER_DEBUG);
} }
logger('externals: import_public_posts: ' . $total . ' messages imported', LOGGER_DEBUG);
} }
} }
} }
} }
if (array_search(__file__,get_included_files())===0){ if (array_search(__file__,get_included_files())===0){