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;
20 * Updates global contacts
22 public static function execute()
24 if (!Config::get('system', 'poco_completion')) {
28 Logger::info('Update global contacts');
32 $contacts = DBA::p("SELECT `url`, `created`, `updated`, `last_failure`, `last_contact`, `server_url`, `network` FROM `gcontact`
33 WHERE `last_contact` < UTC_TIMESTAMP - INTERVAL 1 MONTH AND
34 `last_failure` < UTC_TIMESTAMP - INTERVAL 1 MONTH AND
35 `network` IN (?, ?, ?, ?, ?, '') ORDER BY rand()",
36 Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED);
40 while ($contact = DBA::fetch($contacts)) {
41 $urlparts = parse_url($contact['url']);
42 if (empty($urlparts['scheme'])) {
43 DBA::update('gcontact', ['network' => Protocol::PHANTOM],
44 ['nurl' => Strings::normaliseLink($contact['url'])]);
48 if (in_array($urlparts['host'], ['twitter.com', 'identi.ca'])) {
49 $networks = ['twitter.com' => Protocol::TWITTER, 'identi.ca' => Protocol::PUMPIO];
51 DBA::update('gcontact', ['network' => $networks[$urlparts['host']]],
52 ['nurl' => Strings::normaliseLink($contact['url'])]);
56 $server_url = Contact::getBasepath($contact['url']);
57 $force_update = false;
59 if (!empty($contact['server_url'])) {
60 $force_update = (Strings::normaliseLink($contact['server_url']) != Strings::normaliseLink($server_url));
62 $server_url = $contact['server_url'];
65 if ((empty($server_url) && ($contact['network'] == Protocol::FEED)) || $force_update || GServer::check($server_url, $contact['network'])) {
66 Logger::info('Check profile', ['profile' => $contact['url']]);
67 Worker::add(PRIORITY_LOW, 'UpdateGContact', $contact['url'], 'force');
69 if (++$checked > 100) {
73 DBA::update('gcontact', ['last_failure' => DateTimeFormat::utcNow()],
74 ['nurl' => Strings::normaliseLink($contact['url'])]);
77 // Quit the loop after 3 minutes
78 if (time() > ($starttime + 180)) {