diff --git a/src/Model/GServer.php b/src/Model/GServer.php index 98acc9b67..8adabf847 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -164,6 +164,39 @@ class GServer return DI::dba()->toArray($stmt); } + /** + * Checks if the given server array is unreachable for a long time now + * + * @param integer $gsid + * @return boolean + */ + private static function defunctByArray(array $gserver): bool + { + return ($gserver['failed'] || in_array($gserver['network'], Protocol::FEDERATED)) && + ($gserver['last_contact'] >= $gserver['created']) && + ($gserver['last_contact'] < $gserver['last_failure']) && + ($gserver['last_contact'] < DateTimeFormat::utc('now - 90 days')); + } + + /** + * Checks if the given server id is unreachable for a long time now + * + * @param integer $gsid + * @return boolean + */ + public static function defunct(int $gsid): bool + { + $gserver = DBA::selectFirst('gserver', ['url', 'next_contact', 'last_contact', 'last_failure', 'created', 'failed', 'network'], ['id' => $gsid]); + if (empty($gserver)) { + return false; + } else { + if (strtotime($gserver['next_contact']) < time()) { + Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $gserver['url'], false); + } + return self::defunctByArray($gserver); + } + } + /** * Checks if the given server id is reachable * @@ -374,6 +407,9 @@ class GServer 'next_contact' => $next_update, 'network' => Protocol::PHANTOM, 'detection-method' => null], ['nurl' => Strings::normaliseLink($url)]); Logger::info('Set failed status for existing server', ['url' => $url]); + if (self::defunctByArray($gserver)) { + Contact::update(['archive' => true], ['gsid' => $gserver['id']]); + } return; } self::insert(['url' => $url, 'nurl' => Strings::normaliseLink($url), @@ -617,6 +653,11 @@ class GServer $serverdata = self::detectNetworkViaContacts($url, $serverdata); } + if (($serverdata['network'] == Protocol::PHANTOM) && in_array($serverdata['detection-method'], [self::DETECT_MANUAL, self::DETECT_BODY])) { + self::setFailure($url); + return false; + } + // Detect the directory type $serverdata['directory-type'] = self::DT_NONE; diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 0dd144a48..b9b944100 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -570,8 +570,7 @@ class Notifier } elseif (!DI::config()->get('system', 'bulk_delivery')) { $reachable = !GServer::reachableById($contact['gsid']); } else { - // On bulk delivery we don't check the server status at this point - $reachable = true; + $reachable = !GServer::defunct($contact['gsid']); } if (!$reachable) {