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;
13 use Friendica\Model\GContact;
14 use Friendica\Model\GServer;
15 use Friendica\Util\DateTimeFormat;
16 use Friendica\Util\Strings;
21 * Updates global contacts
23 public static function execute()
25 if (!DI::config()->get('system', 'poco_completion')) {
29 Logger::info('Update global contacts');
33 $contacts = DBA::p("SELECT `url`, `created`, `updated`, `last_failure`, `last_contact`, `server_url`, `network` FROM `gcontact`
34 WHERE `last_contact` < UTC_TIMESTAMP - INTERVAL 1 MONTH AND
35 `last_failure` < UTC_TIMESTAMP - INTERVAL 1 MONTH AND
36 `network` IN (?, ?, ?, ?, ?, '') ORDER BY rand()",
37 Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED);
41 while ($contact = DBA::fetch($contacts)) {
42 $urlparts = parse_url($contact['url']);
43 if (empty($urlparts['scheme'])) {
44 DBA::update('gcontact', ['network' => Protocol::PHANTOM],
45 ['nurl' => Strings::normaliseLink($contact['url'])]);
49 if (in_array($urlparts['host'], ['twitter.com', 'identi.ca'])) {
50 $networks = ['twitter.com' => Protocol::TWITTER, 'identi.ca' => Protocol::PUMPIO];
52 DBA::update('gcontact', ['network' => $networks[$urlparts['host']]],
53 ['nurl' => Strings::normaliseLink($contact['url'])]);
57 $server_url = GContact::getBasepath($contact['url'], true);
58 $force_update = false;
60 if (!empty($contact['server_url'])) {
61 $force_update = (Strings::normaliseLink($contact['server_url']) != Strings::normaliseLink($server_url));
63 $server_url = $contact['server_url'];
66 if ((empty($server_url) && ($contact['network'] == Protocol::FEED)) || $force_update || GServer::check($server_url, $contact['network'])) {
67 Logger::info('Check profile', ['profile' => $contact['url']]);
68 Worker::add(PRIORITY_LOW, 'UpdateGContact', $contact['url'], 'force');
70 if (++$checked > 100) {
74 DBA::update('gcontact', ['last_failure' => DateTimeFormat::utcNow()],
75 ['nurl' => Strings::normaliseLink($contact['url'])]);
78 // Quit the loop after 3 minutes
79 if (time() > ($starttime + 180)) {