diff options
author | friendica <info@friendica.com> | 2014-03-28 15:58:58 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2014-03-28 15:58:58 -0700 |
commit | fc5f3f480092f6c9d48db45230ed99ece97e5ccf (patch) | |
tree | 3b4ce332cf1e9fc77cac4db5669254abd0767e35 /include/externals.php | |
parent | 6925cf9fe55e5a420fbe7385dd170d8dd7a65d57 (diff) | |
download | volse-hubzilla-fc5f3f480092f6c9d48db45230ed99ece97e5ccf.tar.gz volse-hubzilla-fc5f3f480092f6c9d48db45230ed99ece97e5ccf.tar.bz2 volse-hubzilla-fc5f3f480092f6c9d48db45230ed99ece97e5ccf.zip |
externals/discover: try up to 3 times to find a site that actually has content. Then give up until the next queue run.
Diffstat (limited to 'include/externals.php')
-rw-r--r-- | include/externals.php | 77 |
1 files changed, 41 insertions, 36 deletions
diff --git a/include/externals.php b/include/externals.php index 290f93a68..2ae78c11a 100644 --- a/include/externals.php +++ b/include/externals.php @@ -9,51 +9,56 @@ function externals_run($argv, $argc){ cli_startup(); $a = get_app(); + + $total = 0; + $attempts = 0; // pull in some public posts - $arr = array('url' => ''); - call_hooks('externals_url_select',$arr); - - if($arr['url']) { - $url = $arr['url']; - } - 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) { - logger('externals: pulling public content from ' . $url, LOGGER_DEBUG); - $days = get_config('externals','since_days'); - if($days === false) - $days = 15; - - $feedurl = $url . '/zotfeed?f=&mindate=' . urlencode(datetime_convert('','','now - ' . intval($days) . ' days')); - - logger('externals: pulling public content from ' . $feedurl, LOGGER_DEBUG); - $x = z_fetch_url($feedurl); - - if(($x) && ($x['success'])) { - $total = 0; - $j = json_decode($x['body'],true); - if($j['success'] && $j['messages']) { - $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 ++; + while($total == 0 && $attempts < 3) { + $arr = array('url' => ''); + call_hooks('externals_url_select',$arr); + + if($arr['url']) { + $url = $arr['url']; + } + 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']; + } + + $attempts ++; + + if($url) { + $days = get_config('externals','since_days'); + if($days === false) + $days = 15; + + $feedurl = $url . '/zotfeed?f=&mindate=' . urlencode(datetime_convert('','','now - ' . intval($days) . ' days')); + + logger('externals: pulling public content from ' . $feedurl, LOGGER_DEBUG); + $x = z_fetch_url($feedurl); + + if(($x) && ($x['success'])) { + $j = json_decode($x['body'],true); + if($j['success'] && $j['messages']) { + $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){ |