]> git.mxchange.org Git - friendica.git/commitdiff
Merge remote-tracking branch 'upstream/develop' into server-detection
authorMichael <heluecht@pirati.ca>
Sat, 16 Jul 2022 12:44:21 +0000 (12:44 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 16 Jul 2022 12:44:21 +0000 (12:44 +0000)
1  2 
src/Console/Relay.php
src/Model/APContact.php
src/Model/GServer.php
src/Util/Network.php
src/Util/ParseUrl.php

Simple merge
Simple merge
index 3ea07dbc6fb0c474de531cd4a68b2f9d97002d98,a48f6e4ca61d0b2aeaf9c181a0e3d5b32c99579c..1986e478317296c35813791797750a9b996fcc85
@@@ -30,7 -30,7 +30,6 @@@ use Friendica\Core\System
  use Friendica\Core\Worker;
  use Friendica\Database\Database;
  use Friendica\Database\DBA;
--use Friendica\Database\DBStructure;
  use Friendica\DI;
  use Friendica\Module\Register;
  use Friendica\Network\HTTPClient\Client\HttpClientAccept;
@@@ -283,8 -269,8 +282,8 @@@ class GServe
                $gserver = DBA::selectFirst('gserver', [], ['nurl' => Strings::normaliseLink($url)]);
                if (DBA::isResult($gserver)) {
                        $next_update = self::getNextUpdateDate(false, $gserver['created'], $gserver['last_contact']);
-                       DBA::update('gserver', ['url' => $url, 'failed' => true, 'last_failure' => DateTimeFormat::utcNow(),
 -                      self::update(['failed' => true, 'last_failure' => DateTimeFormat::utcNow(),
 -                      'next_contact' => $next_update, 'detection-method' => null],
++                      self::update(['url' => $url, 'failed' => true, 'last_failure' => DateTimeFormat::utcNow(),
 +                      'next_contact' => $next_update, 'network' => Protocol::PHANTOM, 'detection-method' => null],
                        ['nurl' => Strings::normaliseLink($url)]);
                        Logger::info('Set failed status for existing server', ['url' => $url]);
                        return;
         *
         * @return boolean 'true' if server could be detected
         */
-       public static function detect(string $url, string $network = '', bool $only_nodeinfo = false)
+       public static function detect(string $url, string $network = '', bool $only_nodeinfo = false): bool
        {
                Logger::info('Detect server type', ['server' => $url]);
 -              $serverdata = ['detection-method' => self::DETECT_MANUAL];
  
                $original_url = $url;
  
                $serverdata['last_contact'] = DateTimeFormat::utcNow();
                $serverdata['failed'] = false;
  
-               // Limit the length on incoming fields
-               $serverdata = DBStructure::getFieldsForTable('gserver', $serverdata);
 -              $gserver = DBA::selectFirst('gserver', ['network'], ['nurl' => $serverdata['nurl']]);
 +              $gserver = DBA::selectFirst('gserver', ['network'], ['nurl' => Strings::normaliseLink($url)]);
                if (!DBA::isResult($gserver)) {
                        $serverdata['created'] = DateTimeFormat::utcNow();
                        $ret = DBA::insert('gserver', $serverdata);
                                $contacts = DBA::count('contact', ["`uid` = ? AND `gsid` = ? AND NOT `failed` AND `last-item` > ?", 0, $id, DateTimeFormat::utc('now - 30 days')]);
                                if ($contacts > 0) {
                                        Logger::info('Update monthly users', ['id' => $id, 'url' => $serverdata['nurl'], 'monthly-users' => $contacts]);
-                                       DBA::update('gserver', ['active-month-users' => $contacts], ['id' => $id]);
+                                       self::update(['active-month-users' => $contacts], ['id' => $id]);
                                }
                        }
 -      
 +
                        if (empty($serverdata['active-halfyear-users'])) {
                                $contacts = DBA::count('contact', ["`uid` = ? AND `gsid` = ? AND NOT `failed` AND `last-item` > ?", 0, $id, DateTimeFormat::utc('now - 180 days')]);
                                if ($contacts > 0) {
         * Fetch server data from '/statistics.json' on the given server
         *
         * @param string $url URL of the given server
-        *
         * @return array server data
         */
 -      private static function fetchStatistics(string $url): array
 +      private static function fetchStatistics(string $url, array $serverdata)
        {
                $curlResult = DI::httpClient()->get($url . '/statistics.json', HttpClientAccept::JSON);
                if (!$curlResult->isSuccess()) {
         *
         * @param object $curlResult result of curl execution
         * @param array  $serverdata array with server data
 -       * @param string $url        Server URL
 +       *
         * @return array server data
         */
-        private static function analyseRootBody($curlResult, array $serverdata)
 -      private static function analyseRootBody($curlResult, array $serverdata, string $url): array
++       private static function analyseRootBody($curlResult, array $serverdata): array
        {
                if (empty($curlResult->getBody())) {
                        return $serverdata;
Simple merge
index 8d8329675862779ca3cf2e2b2c511bfd07dfeb49,ee171ea047e85ccf5111e14ce3392ead59ae3686..0183d6b14ae5be6785f90eaf5c16af01e6974de9
@@@ -57,22 -57,15 +57,22 @@@ class ParseUr
         * Fetch the content type of the given url
         * @param string $url    URL of the page
         * @param string $accept content-type to accept
 +       * @param int    $timeout
         * @return array content type
         */
-       public static function getContentType(string $url, string $accept = HttpClientAccept::DEFAULT, int $timeout = 0)
 -      public static function getContentType(string $url, string $accept = HttpClientAccept::DEFAULT): array
++      public static function getContentType(string $url, string $accept = HttpClientAccept::DEFAULT, int $timeout = 0): array
        {
 -              $curlResult = DI::httpClient()->head($url, [HttpClientOptions::ACCEPT_CONTENT => $accept]);
 +              if (!empty($timeout)) {
 +                      $options = [HttpClientOptions::TIMEOUT => $timeout];
 +              } else {
 +                      $options = [];
 +              }
 +
 +              $curlResult = DI::httpClient()->head($url, array_merge([HttpClientOptions::ACCEPT_CONTENT => $accept], $options));
  
 -              // Workaround for systems that can't handle a HEAD request
 -              if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
 -                      $curlResult = DI::httpClient()->get($url, $accept, [HttpClientOptions::CONTENT_LENGTH => 1000000]);
 +              // Workaround for systems that can't handle a HEAD request. Don't retry on timeouts.
 +              if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() >= 400) && !in_array($curlResult->getReturnCode(), [408, 504])) {
 +                      $curlResult = DI::httpClient()->get($url, $accept, array_merge([HttpClientOptions::CONTENT_LENGTH => 1000000], $options));
                }
  
                if (!$curlResult->isSuccess()) {