]> git.mxchange.org Git - friendica.git/commitdiff
New "Defunct" check
authorMichael <heluecht@pirati.ca>
Sat, 31 Dec 2022 16:01:40 +0000 (16:01 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 31 Dec 2022 16:01:40 +0000 (16:01 +0000)
src/Model/GServer.php
src/Worker/Notifier.php

index 98acc9b67d22bf96090c75d85a90606c41c4a900..8adabf847e5cfa2c13e18c8efbec409deb64dcb5 100644 (file)
@@ -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;
 
index 0dd144a4858ec85c29c6e3b2ef188ba793053334..b9b9441003c57c4e1c7922988db8138af3b27d32 100644 (file)
@@ -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) {