]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/GServer.php
Merge pull request #9146 from tobiasd/2020.09-CHANGELOG
[friendica.git] / src / Model / GServer.php
index 0f47146eb73705b67613bfa793f594d9ec3696a4..323a23f494522749263d46abb5b4d5194311a93d 100644 (file)
@@ -32,7 +32,6 @@ use Friendica\DI;
 use Friendica\Module\Register;
 use Friendica\Network\CurlResult;
 use Friendica\Protocol\Diaspora;
-use Friendica\Protocol\PortableContact;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
@@ -111,7 +110,10 @@ class GServer
        public static function reachable(string $profile, string $server = '', string $network = '', bool $force = false)
        {
                if ($server == '') {
-                       $server = GContact::getBasepath($profile);
+                       $contact = Contact::getByURL($profile, null, ['baseurl']);
+                       if (!empty($contact['baseurl'])) {
+                               $server = $contact['baseurl'];
+                       }
                }
 
                if ($server == '') {
@@ -471,10 +473,9 @@ class GServer
                }
 
                if (!empty($serverdata['network']) && !empty($id) && ($serverdata['network'] != Protocol::PHANTOM)) {
-                       $gcontacts = DBA::count('gcontact', ['gsid' => $id]);
                        $apcontacts = DBA::count('apcontact', ['gsid' => $id]);
                        $contacts = DBA::count('contact', ['uid' => 0, 'gsid' => $id]);
-                       $max_users = max($gcontacts, $apcontacts, $contacts, $registeredUsers);
+                       $max_users = max($apcontacts, $contacts, $registeredUsers);
                        if ($max_users > $registeredUsers) {
                                Logger::info('Update registered users', ['id' => $id, 'url' => $serverdata['nurl'], 'registered-users' => $max_users]);
                                DBA::update('gserver', ['registered-users' => $max_users], ['id' => $id]);
@@ -959,12 +960,6 @@ class GServer
        {
                $contacts = [];
 
-               $gcontacts = DBA::select('gcontact', ['url', 'nurl'], ['server_url' => [$url, $serverdata['nurl']]]);
-               while ($gcontact = DBA::fetch($gcontacts)) {
-                       $contacts[$gcontact['nurl']] = $gcontact['url'];
-               }
-               DBA::close($gcontacts);
-
                $apcontacts = DBA::select('apcontact', ['url'], ['baseurl' => [$url, $serverdata['nurl']]]);
                while ($apcontact = DBA::fetch($apcontacts)) {
                        $contacts[Strings::normaliseLink($apcontact['url'])] = $apcontact['url'];
@@ -1556,20 +1551,6 @@ class GServer
                return !strpos($body, '>');
        }
 
-       /**
-        * Update the user directory of a given gserver record
-        *
-        * @param array $gserver gserver record
-        */
-       public static function updateDirectory(array $gserver)
-       {
-               /// @todo Add Mastodon API directory
-
-               if (!empty($gserver['poco'])) {
-                       PortableContact::discoverSingleServer($gserver['id']);
-               }
-       }
-
        /**
         * Update GServer entries
         */
@@ -1588,12 +1569,12 @@ class GServer
 
                $last_update = date('c', time() - (60 * 60 * 24 * $requery_days));
 
-               $gservers = DBA::p("SELECT `id`, `url`, `nurl`, `network`, `poco`
+               $gservers = DBA::p("SELECT `id`, `url`, `nurl`, `network`, `poco`, `directory-type`
                        FROM `gserver`
                        WHERE NOT `failed`
-                       AND `poco` != ''
+                       AND `directory-type` != ?
                        AND `last_poco_query` < ?
-                       ORDER BY RAND()", $last_update
+                       ORDER BY RAND()", self::DT_NONE, $last_update
                );
 
                while ($gserver = DBA::fetch($gservers)) {
@@ -1604,9 +1585,15 @@ class GServer
                                continue;
                        }
 
+                       Logger::info('Update peer list', ['server' => $gserver['url'], 'id' => $gserver['id']]);
+                       Worker::add(PRIORITY_LOW, 'UpdateServerPeers', $gserver['url']);
+
                        Logger::info('Update directory', ['server' => $gserver['url'], 'id' => $gserver['id']]);
                        Worker::add(PRIORITY_LOW, 'UpdateServerDirectory', $gserver);
 
+                       $fields = ['last_poco_query' => DateTimeFormat::utcNow()];
+                       DBA::update('gserver', $fields, ['nurl' => $gserver['nurl']]);
+       
                        if (--$no_of_queries == 0) {
                                break;
                        }