3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Worker;
24 use Friendica\Core\Logger;
25 use Friendica\Core\Protocol;
26 use Friendica\Core\Worker;
27 use Friendica\Database\DBA;
29 use Friendica\Model\GContact;
30 use Friendica\Model\GServer;
31 use Friendica\Util\DateTimeFormat;
32 use Friendica\Util\Strings;
37 * Updates global contacts
39 public static function execute()
41 if (!DI::config()->get('system', 'poco_completion')) {
45 Logger::info('Update global contacts');
49 $contacts = DBA::p("SELECT `url`, `created`, `updated`, `last_failure`, `last_contact`, `server_url`, `network` FROM `gcontact`
50 WHERE `last_contact` < UTC_TIMESTAMP - INTERVAL 1 MONTH AND
51 `last_failure` < UTC_TIMESTAMP - INTERVAL 1 MONTH AND
52 `network` IN (?, ?, ?, ?, ?, '') ORDER BY rand()",
53 Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED);
57 while ($contact = DBA::fetch($contacts)) {
58 $urlparts = parse_url($contact['url']);
59 if (empty($urlparts['scheme'])) {
60 DBA::update('gcontact', ['network' => Protocol::PHANTOM],
61 ['nurl' => Strings::normaliseLink($contact['url'])]);
65 if (in_array($urlparts['host'], ['twitter.com', 'identi.ca'])) {
66 $networks = ['twitter.com' => Protocol::TWITTER, 'identi.ca' => Protocol::PUMPIO];
68 DBA::update('gcontact', ['network' => $networks[$urlparts['host']]],
69 ['nurl' => Strings::normaliseLink($contact['url'])]);
73 $server_url = GContact::getBasepath($contact['url'], true);
74 $force_update = false;
76 if (!empty($contact['server_url'])) {
77 $force_update = (Strings::normaliseLink($contact['server_url']) != Strings::normaliseLink($server_url));
79 $server_url = $contact['server_url'];
82 if ((empty($server_url) && ($contact['network'] == Protocol::FEED)) || $force_update || GServer::check($server_url, $contact['network'])) {
83 Logger::info('Check profile', ['profile' => $contact['url']]);
84 Worker::add(PRIORITY_LOW, 'UpdateGContact', $contact['url'], 'force');
86 if (++$checked > 100) {
90 DBA::update('gcontact', ['last_failure' => DateTimeFormat::utcNow()],
91 ['nurl' => Strings::normaliseLink($contact['url'])]);
94 // Quit the loop after 3 minutes
95 if (time() > ($starttime + 180)) {
99 DBA::close($contacts);