3 * @file src/Worker/UpdateGContacts.php
5 namespace Friendica\Worker;
7 use Friendica\Core\Config;
8 use Friendica\Core\Logger;
9 use Friendica\Core\Protocol;
10 use Friendica\Core\Worker;
11 use Friendica\Database\DBA;
12 use Friendica\Model\Contact;
13 use Friendica\Model\GServer;
14 use Friendica\Util\DateTimeFormat;
15 use Friendica\Util\Strings;
19 // Updates gcontact entries
20 public static function execute()
22 if (!Config::get('system', 'poco_completion')) {
26 Logger::info('Discover contacts');
30 $contacts = DBA::p("SELECT `url`, `created`, `updated`, `last_failure`, `last_contact`, `server_url`, `network` FROM `gcontact`
31 WHERE `last_contact` < UTC_TIMESTAMP - INTERVAL 1 MONTH AND
32 `last_failure` < UTC_TIMESTAMP - INTERVAL 1 MONTH AND
33 `network` IN (?, ?, ?, ?, '') ORDER BY rand()",
34 Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED);
38 while ($contact = DBA::fetch($contacts)) {
39 $urlparts = parse_url($contact['url']);
40 if (empty($urlparts['scheme'])) {
41 DBA::update('gcontact', ['network' => Protocol::PHANTOM],
42 ['nurl' => Strings::normaliseLink($contact['url'])]);
46 if (in_array($urlparts['host'], ['twitter.com', 'identi.ca'])) {
47 $networks = ['twitter.com' => Protocol::TWITTER, 'identi.ca' => Protocol::PUMPIO];
49 DBA::update('gcontact', ['network' => $networks[$urlparts['host']]],
50 ['nurl' => Strings::normaliseLink($contact['url'])]);
54 $server_url = Contact::getBasepath($contact['url']);
55 $force_update = false;
57 if (!empty($contact['server_url'])) {
58 $force_update = (Strings::normaliseLink($contact['server_url']) != Strings::normaliseLink($server_url));
60 $server_url = $contact['server_url'];
63 if ((empty($server_url) && ($contact['network'] == Protocol::FEED)) || $force_update || GServer::check($server_url, $contact['network'])) {
64 Logger::info('Check profile', ['profile' => $contact['url']]);
65 Worker::add(PRIORITY_LOW, 'UpdateGContact', $contact['url'], 'force');
67 if (++$checked > 100) {
71 DBA::update('gcontact', ['last_failure' => DateTimeFormat::utcNow()],
72 ['nurl' => Strings::normaliseLink($contact['url'])]);
75 // Quit the loop after 3 minutes
76 if (time() > ($starttime + 180)) {