- private static function pollContacts() {
- $min_poll_interval = DI::config()->get('system', 'min_poll_interval');
-
- Addon::reload();
-
- $sql = "SELECT `contact`.`id`, `contact`.`nick`, `contact`.`name`, `contact`.`network`, `contact`.`archive`,
- `contact`.`last-update`, `contact`.`priority`, `contact`.`rel`, `contact`.`subhub`
- FROM `user`
- STRAIGHT_JOIN `contact`
- ON `contact`.`uid` = `user`.`uid` AND `contact`.`poll` != ''
- AND `contact`.`network` IN (?, ?, ?, ?, ?)
- AND NOT `contact`.`self` AND NOT `contact`.`blocked`
- AND `contact`.`rel` != ?
- WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed`";
-
- $parameters = [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL, Contact::FOLLOWER];
-
- // Only poll from those with suitable relationships,
- // and which have a polling address and ignore Diaspora since
- // we are unable to match those posts with a Diaspora GUID and prevent duplicates.
- $abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
- if ($abandon_days < 1) {
- $abandon_days = 0;
- }
-
- if (!empty($abandon_days)) {
- $sql .= " AND `user`.`login_date` > UTC_TIMESTAMP() - INTERVAL ? DAY";
- $parameters[] = $abandon_days;
- }
-
- $contacts = DBA::p($sql, $parameters);
-
- if (!DBA::isResult($contacts)) {
- return;
- }
-
- while ($contact = DBA::fetch($contacts)) {
- // Friendica and OStatus are checked once a day
- if (in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS])) {
- $contact['priority'] = 3;
- }
-
- // ActivityPub is checked once a week
- if ($contact['network'] == Protocol::ACTIVITYPUB) {
- $contact['priority'] = 4;
- }
-
- // Check archived contacts once a month
- if ($contact['archive']) {
- $contact['priority'] = 5;
- }
-
- if ($contact['priority'] >= 0) {
- $update = false;
-
- $t = $contact['last-update'];
-
- /*
- * Based on $contact['priority'], should we poll this site now? Or later?
- */
- switch ($contact['priority']) {
- case 5:
- if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 1 month")) {
- $update = true;
- }
- break;
- case 4:
- if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 1 week")) {
- $update = true;
- }
- break;
- case 3:
- if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 1 day")) {
- $update = true;
- }
- break;
- case 2:
- if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 12 hour")) {
- $update = true;
- }
- break;
- case 1:
- if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + 1 hour")) {
- $update = true;
- }
- break;
- case 0:
- default:
- if (DateTimeFormat::utcNow() > DateTimeFormat::utc($t . " + " . $min_poll_interval . " minute")) {
- $update = true;
- }
- break;
- }
- if (!$update) {
- continue;
- }
- }
-
- if ((($contact['network'] == Protocol::FEED) && ($contact['priority'] <= 3)) || ($contact['network'] == Protocol::MAIL)) {
- $priority = PRIORITY_MEDIUM;
- } elseif ($contact['archive']) {
- $priority = PRIORITY_NEGLIGIBLE;
- } else {
- $priority = PRIORITY_LOW;