3 * @copyright Copyright (C) 2010-2023, the Friendica project
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\Protocol\Feed;
30 use Friendica\Util\DateTimeFormat;
33 * Poll contacts for unreceived messages
37 public static function execute()
39 $abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
40 if ($abandon_days < 1) {
44 $condition = ['network' => [Protocol::FEED, Protocol::MAIL, Protocol::OSTATUS], 'self' => false, 'blocked' => false, 'archive' => false];
46 if (!empty($abandon_days)) {
47 $condition = DBA::mergeConditions($condition,
48 ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `blocked` AND NOT `account_expired` AND NOT `account_removed` AND `last-activity` > ?)", 0, DateTimeFormat::utc('now - ' . $abandon_days . ' days')]);
50 $condition = DBA::mergeConditions($condition,
51 ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `blocked` AND NOT `account_expired` AND NOT `account_removed`)", 0]);
54 $contacts = DBA::select('contact', ['id', 'nick', 'name', 'network', 'archive', 'last-update', 'priority', 'rating'], $condition);
55 if (!DBA::isResult($contacts)) {
59 while ($contact = DBA::fetch($contacts)) {
60 $interval = Feed::getPollInterval($contact);
65 $now = DateTimeFormat::utcNow();
66 $next_update = DateTimeFormat::utc($contact['last-update'] . ' + ' . $interval . ' minute');
68 if ($now < $next_update) {
69 Logger::debug('No update', ['cid' => $contact['id'], 'interval' => $interval, 'next' => $next_update, 'now' => $now]);
73 if ((($contact['network'] == Protocol::FEED) && ($contact['priority'] <= 3)) || ($contact['network'] == Protocol::MAIL)) {
74 $priority = Worker::PRIORITY_MEDIUM;
75 } elseif ($contact['archive']) {
76 $priority = Worker::PRIORITY_NEGLIGIBLE;
78 $priority = Worker::PRIORITY_LOW;
81 Logger::notice("Polling " . $contact["network"] . " " . $contact["id"] . " " . $contact['priority'] . " " . $contact["nick"] . " " . $contact["name"]);
83 Worker::add(['priority' => $priority, 'dont_fork' => true, 'force_priority' => true], 'OnePoll', (int)$contact['id']);
86 DBA::close($contacts);