]> git.mxchange.org Git - friendica.git/commitdiff
Relocated functions from PortableContact to GServer
authorMichael <heluecht@pirati.ca>
Wed, 1 Jan 2020 21:29:36 +0000 (21:29 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 1 Jan 2020 21:29:36 +0000 (21:29 +0000)
src/Core/Search.php
src/Model/GServer.php
src/Protocol/PortableContact.php
src/Worker/UpdateServerDirectories.php

index ab06a51a7d7d9c522d2a492257e8e4b60984ca02..c10b5f6d6ac02ef2521f4af5f3e19a77c7803e76 100644 (file)
@@ -205,10 +205,6 @@ class Search
                }
 
                while ($row = DBA::fetch($data)) {
-                       if (PortableContact::alternateOStatusUrl($row["nurl"])) {
-                               continue;
-                       }
-
                        $urlParts = parse_url($row["nurl"]);
 
                        // Ignore results that look strange.
index de8a3c1a1ab1221ea5579d979e0727bb747d4896..04488072486d1f5ba822c808d3b9ce89b31282f9 100644 (file)
@@ -1306,4 +1306,98 @@ class GServer
                        PortableContact::discoverSingleServer($gserver['id']);
                }
        }
+
+       /**
+        * Update GServer entries
+        */
+       public static function discover()
+       {
+               // Update the server list
+               self::discoverFederation();
+
+               $no_of_queries = 5;
+
+               $requery_days = intval(Config::get('system', 'poco_requery_days'));
+
+               if ($requery_days == 0) {
+                       $requery_days = 7;
+               }
+
+               $last_update = date('c', time() - (60 * 60 * 24 * $requery_days));
+
+               $gservers = DBA::p("SELECT `id`, `url`, `nurl`, `network`, `poco`
+                       FROM `gserver`
+                       WHERE `last_contact` >= `last_failure`
+                       AND `poco` != ''
+                       AND `last_poco_query` < ?
+                       ORDER BY RAND()", $last_update
+               );
+
+               while ($gserver = DBA::fetch($gservers)) {
+                       if (!GServer::check($gserver['url'], $gserver['network'])) {
+                               // The server is not reachable? Okay, then we will try it later
+                               $fields = ['last_poco_query' => DateTimeFormat::utcNow()];
+                               DBA::update('gserver', $fields, ['nurl' => $gserver['nurl']]);
+                               continue;
+                       }
+
+                       Logger::info('Update directory', ['server' => $gserver['url'], 'id' => $gserver['id']]);
+                       Worker::add(PRIORITY_LOW, 'UpdateServerDirectory', $gserver);
+
+                       if (--$no_of_queries == 0) {
+                               break;
+                       }
+               }
+
+               DBA::close($gservers);
+       }
+
+       /**
+        * Discover federated servers
+        */
+       private static function discoverFederation()
+       {
+               $last = Config::get('poco', 'last_federation_discovery');
+
+               if ($last) {
+                       $next = $last + (24 * 60 * 60);
+
+                       if ($next > time()) {
+                               return;
+                       }
+               }
+
+               // Discover federated servers
+               $curlResult = Network::fetchUrl("http://the-federation.info/pods.json");
+
+               if (!empty($curlResult)) {
+                       $servers = json_decode($curlResult, true);
+
+                       if (!empty($servers['pods'])) {
+                               foreach ($servers['pods'] as $server) {
+                                       Worker::add(PRIORITY_LOW, 'UpdateGServer', 'https://' . $server['host']);
+                               }
+                       }
+               }
+
+               // Disvover Mastodon servers
+               $accesstoken = Config::get('system', 'instances_social_key');
+
+               if (!empty($accesstoken)) {
+                       $api = 'https://instances.social/api/1.0/instances/list?count=0';
+                       $header = ['Authorization: Bearer '.$accesstoken];
+                       $curlResult = Network::curl($api, false, ['headers' => $header]);
+
+                       if ($curlResult->isSuccess()) {
+                               $servers = json_decode($curlResult->getBody(), true);
+
+                               foreach ($servers['instances'] as $server) {
+                                       $url = (is_null($server['https_score']) ? 'http' : 'https') . '://' . $server['name'];
+                                       Worker::add(PRIORITY_LOW, 'UpdateGServer', $url);
+                               }
+                       }
+               }
+
+               Config::set('poco', 'last_federation_discovery', time());
+       }
 }
index 49da85e6150eae01fd6f7fa4524feaa43c59ad1f..9ba6a4b9008b91eabe5e6691ec71d8ac629d2aba 100644 (file)
@@ -214,11 +214,6 @@ class PortableContact
                DBA::delete('glink', $condition);
        }
 
-       public static function alternateOStatusUrl($url)
-       {
-               return(preg_match("=https?://.+/user/\d+=ism", $url, $matches));
-       }
-
        /**
         * @brief Returns a list of all known servers
         * @return array List of server urls
@@ -275,69 +270,6 @@ class PortableContact
                }
        }
 
-       private static function discoverFederation()
-       {
-               $last = Config::get('poco', 'last_federation_discovery');
-
-               if ($last) {
-                       $next = $last + (24 * 60 * 60);
-
-                       if ($next > time()) {
-                               return;
-                       }
-               }
-
-               // Discover Friendica, Hubzilla and Diaspora servers
-               $curlResult = Network::fetchUrl("http://the-federation.info/pods.json");
-
-               if (!empty($curlResult)) {
-                       $servers = json_decode($curlResult, true);
-
-                       if (!empty($servers['pods'])) {
-                               foreach ($servers['pods'] as $server) {
-                                       Worker::add(PRIORITY_LOW, 'UpdateGServer', 'https://' . $server['host']);
-                               }
-                       }
-               }
-
-               // Disvover Mastodon servers
-               if (!Config::get('system', 'ostatus_disabled')) {
-                       $accesstoken = Config::get('system', 'instances_social_key');
-
-                       if (!empty($accesstoken)) {
-                               $api = 'https://instances.social/api/1.0/instances/list?count=0';
-                               $header = ['Authorization: Bearer '.$accesstoken];
-                               $curlResult = Network::curl($api, false, ['headers' => $header]);
-
-                               if ($curlResult->isSuccess()) {
-                                       $servers = json_decode($curlResult->getBody(), true);
-
-                                       foreach ($servers['instances'] as $server) {
-                                               $url = (is_null($server['https_score']) ? 'http' : 'https') . '://' . $server['name'];
-                                               Worker::add(PRIORITY_LOW, 'UpdateGServer', $url);
-                                       }
-                               }
-                       }
-               }
-
-               // Currently disabled, since the service isn't available anymore.
-               // It is not removed since I hope that there will be a successor.
-               // Discover GNU Social Servers.
-               //if (!Config::get('system','ostatus_disabled')) {
-               //      $serverdata = "http://gstools.org/api/get_open_instances/";
-
-               //      $curlResult = Network::curl($serverdata);
-               //      if ($curlResult->isSuccess()) {
-               //              $servers = json_decode($result->getBody(), true);
-
-               //              foreach($servers['data'] as $server)
-               //                      GServer::check($server['instance_address']);
-               //      }
-               //}
-
-               Config::set('poco', 'last_federation_discovery', time());
-       }
-
        public static function discoverSingleServer($id)
        {
                $server = DBA::selectFirst('gserver', ['poco', 'nurl', 'url', 'network'], ['id' => $id]);
@@ -410,48 +342,6 @@ class PortableContact
                }
        }
 
-       public static function discover($complete = false)
-       {
-               // Update the server list
-               self::discoverFederation();
-
-               $no_of_queries = 5;
-
-               $requery_days = intval(Config::get('system', 'poco_requery_days'));
-
-               if ($requery_days == 0) {
-                       $requery_days = 7;
-               }
-
-               $last_update = date('c', time() - (60 * 60 * 24 * $requery_days));
-
-               $gservers = q("SELECT `id`, `url`, `nurl`, `network`, `poco`
-                       FROM `gserver`
-                       WHERE `last_contact` >= `last_failure`
-                       AND `poco` != ''
-                       AND `last_poco_query` < '%s'
-                       ORDER BY RAND()", DBA::escape($last_update)
-               );
-
-               if (DBA::isResult($gservers)) {
-                       foreach ($gservers as $gserver) {
-                               if (!GServer::check($gserver['url'], $gserver['network'])) {
-                                       // The server is not reachable? Okay, then we will try it later
-                                       $fields = ['last_poco_query' => DateTimeFormat::utcNow()];
-                                       DBA::update('gserver', $fields, ['nurl' => $gserver['nurl']]);
-                                       continue;
-                               }
-
-                               Logger::log('Update directory from server ' . $gserver['url'] . ' with ID ' . $gserver['id'], Logger::DEBUG);
-                               Worker::add(PRIORITY_LOW, 'UpdateServerDirectory', $gserver);
-
-                               if (!$complete && ( --$no_of_queries == 0)) {
-                                       break;
-                               }
-                       }
-               }
-       }
-
        private static function discoverServerUsers(array $data, array $server)
        {
                if (!isset($data['entry'])) {
@@ -602,5 +492,4 @@ class PortableContact
                }
                return $success;
        }
-
 }
index 433685cb29deeb37d7ac42b3f6db295451b6ee0b..d651c9ae68d08cd3ee94361bbdc67bd656dcef84 100644 (file)
@@ -7,6 +7,7 @@ namespace Friendica\Worker;
 use Friendica\Core\Config;
 use Friendica\Core\Logger;
 use Friendica\Model\GContact;
+use Friendica\Model\GServer;
 use Friendica\Protocol\PortableContact;
 
 class UpdateServerDirectories
@@ -21,7 +22,7 @@ class UpdateServerDirectories
                }
 
                // Query Friendica and Hubzilla servers for their users
-               PortableContact::discover();
+               GServer::discover();
 
                // Query GNU Social servers for their users ("statistics" addon has to be enabled on the GS server)
                if (!Config::get('system', 'ostatus_disabled')) {