]> git.mxchange.org Git - friendica.git/commitdiff
Relocated functions
authorMichael <heluecht@pirati.ca>
Sat, 21 Dec 2019 06:39:22 +0000 (06:39 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 21 Dec 2019 06:39:22 +0000 (06:39 +0000)
src/Model/GContact.php
src/Model/GServer.php
src/Protocol/PortableContact.php
src/Worker/UpdateServerDirectory.php
src/Worker/UpdateServers.php

index 0ad6df688f4e0434727b6c956733917bf68716ca..61e44b4106dff1f1cc5147e817c34c8e4ed8925e 100644 (file)
@@ -783,7 +783,7 @@ class GContact
                        return;
                }
 
                        return;
                }
 
-               if (!$force && !PortableContact::updateNeeded($gcontact['created'], $gcontact['updated'], $gcontact['last_failure'], $gcontact['last_contact'])) {
+               if (!$force && !GServer::updateNeeded($gcontact['created'], $gcontact['updated'], $gcontact['last_failure'], $gcontact['last_contact'])) {
                        Logger::info("Don't update profile", ['url' => $data['url'], 'updated' => $gcontact['updated']]);
                        return;
                }
                        Logger::info("Don't update profile", ['url' => $data['url'], 'updated' => $gcontact['updated']]);
                        return;
                }
index 43aa92f33eec96abf4164f424eed5cd2732189b4..7f72302c90376eda5b27fd3b7fcf5d8ba25d871e 100644 (file)
@@ -49,6 +49,61 @@ class GServer
                return self::check($server, $network, $force);
        }
 
                return self::check($server, $network, $force);
        }
 
+       /**
+        * Decides if a server needs to be updated, based upon several date fields
+        * 
+        * @param date $created      Creation date of that server entry
+        * @param date $updated      When had the server entry be updated
+        * @param date $last_failure Last failure when contacting that server
+        * @param date $last_contact Last time the server had been contacted
+        * 
+        * @return boolean Does the server record needs an update?
+        */
+       public static function updateNeeded($created, $updated, $last_failure, $last_contact)
+       {
+               $now = strtotime(DateTimeFormat::utcNow());
+
+               if ($updated > $last_contact) {
+                       $contact_time = strtotime($updated);
+               } else {
+                       $contact_time = strtotime($last_contact);
+               }
+
+               $failure_time = strtotime($last_failure);
+               $created_time = strtotime($created);
+
+               // If there is no "created" time then use the current time
+               if ($created_time <= 0) {
+                       $created_time = $now;
+               }
+
+               // If the last contact was less than 24 hours then don't update
+               if (($now - $contact_time) < (60 * 60 * 24)) {
+                       return false;
+               }
+
+               // If the last failure was less than 24 hours then don't update
+               if (($now - $failure_time) < (60 * 60 * 24)) {
+                       return false;
+               }
+
+               // If the last contact was less than a week ago and the last failure is older than a week then don't update
+               //if ((($now - $contact_time) < (60 * 60 * 24 * 7)) && ($contact_time > $failure_time))
+               //      return false;
+
+               // If the last contact time was more than a week ago and the contact was created more than a week ago, then only try once a week
+               if ((($now - $contact_time) > (60 * 60 * 24 * 7)) && (($now - $created_time) > (60 * 60 * 24 * 7)) && (($now - $failure_time) < (60 * 60 * 24 * 7))) {
+                       return false;
+               }
+
+               // If the last contact time was more than a month ago and the contact was created more than a month ago, then only try once a month
+               if ((($now - $contact_time) > (60 * 60 * 24 * 30)) && (($now - $created_time) > (60 * 60 * 24 * 30)) && (($now - $failure_time) < (60 * 60 * 24 * 30))) {
+                       return false;
+               }
+
+               return true;
+       }
+
        /**
         * Checks the state of the given server.
         *
        /**
         * Checks the state of the given server.
         *
@@ -89,7 +144,7 @@ class GServer
                                $last_failure = DBA::NULL_DATETIME;
                        }
 
                                $last_failure = DBA::NULL_DATETIME;
                        }
 
-                       if (!$force && !PortableContact::updateNeeded($gserver['created'], '', $last_failure, $last_contact)) {
+                       if (!$force && !self::updateNeeded($gserver['created'], '', $last_failure, $last_contact)) {
                                Logger::info('No update needed', ['server' => $server_url]);
                                return ($last_contact >= $last_failure);
                        }
                                Logger::info('No update needed', ['server' => $server_url]);
                                return ($last_contact >= $last_failure);
                        }
@@ -1184,4 +1239,18 @@ class GServer
                }
                return $serverdata;
        }
                }
                return $serverdata;
        }
+
+       /**
+        * 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']);
+               }
+       }
 }
 }
index 1870f8f9b76b290fafaaa88395279defc9450852..d720910c5fb2ec82ab4af17ffab320c1ac135f10 100644 (file)
@@ -219,51 +219,6 @@ class PortableContact
                return(preg_match("=https?://.+/user/\d+=ism", $url, $matches));
        }
 
                return(preg_match("=https?://.+/user/\d+=ism", $url, $matches));
        }
 
-       public static function updateNeeded($created, $updated, $last_failure, $last_contact)
-       {
-               $now = strtotime(DateTimeFormat::utcNow());
-
-               if ($updated > $last_contact) {
-                       $contact_time = strtotime($updated);
-               } else {
-                       $contact_time = strtotime($last_contact);
-               }
-
-               $failure_time = strtotime($last_failure);
-               $created_time = strtotime($created);
-
-               // If there is no "created" time then use the current time
-               if ($created_time <= 0) {
-                       $created_time = $now;
-               }
-
-               // If the last contact was less than 24 hours then don't update
-               if (($now - $contact_time) < (60 * 60 * 24)) {
-                       return false;
-               }
-
-               // If the last failure was less than 24 hours then don't update
-               if (($now - $failure_time) < (60 * 60 * 24)) {
-                       return false;
-               }
-
-               // If the last contact was less than a week ago and the last failure is older than a week then don't update
-               //if ((($now - $contact_time) < (60 * 60 * 24 * 7)) && ($contact_time > $failure_time))
-               //      return false;
-
-               // If the last contact time was more than a week ago and the contact was created more than a week ago, then only try once a week
-               if ((($now - $contact_time) > (60 * 60 * 24 * 7)) && (($now - $created_time) > (60 * 60 * 24 * 7)) && (($now - $failure_time) < (60 * 60 * 24 * 7))) {
-                       return false;
-               }
-
-               // If the last contact time was more than a month ago and the contact was created more than a month ago, then only try once a month
-               if ((($now - $contact_time) > (60 * 60 * 24 * 30)) && (($now - $created_time) > (60 * 60 * 24 * 30)) && (($now - $failure_time) < (60 * 60 * 24 * 30))) {
-                       return false;
-               }
-
-               return true;
-       }
-
        /**
         * @brief Returns a list of all known servers
         * @return array List of server urls
        /**
         * @brief Returns a list of all known servers
         * @return array List of server urls
@@ -470,7 +425,7 @@ class PortableContact
 
                $last_update = date('c', time() - (60 * 60 * 24 * $requery_days));
 
 
                $last_update = date('c', time() - (60 * 60 * 24 * $requery_days));
 
-               $gservers = q("SELECT `id`, `url`, `nurl`, `network`
+               $gservers = q("SELECT `id`, `url`, `nurl`, `network`, `poco`
                        FROM `gserver`
                        WHERE `last_contact` >= `last_failure`
                        AND `poco` != ''
                        FROM `gserver`
                        WHERE `last_contact` >= `last_failure`
                        AND `poco` != ''
@@ -488,7 +443,7 @@ class PortableContact
                                }
 
                                Logger::log('Update directory from server ' . $gserver['url'] . ' with ID ' . $gserver['id'], Logger::DEBUG);
                                }
 
                                Logger::log('Update directory from server ' . $gserver['url'] . ' with ID ' . $gserver['id'], Logger::DEBUG);
-                               Worker::add(PRIORITY_LOW, 'UpdateServerDirectory', (int)$gserver['id']);
+                               Worker::add(PRIORITY_LOW, 'UpdateServerDirectory', $gserver);
 
                                if (!$complete && ( --$no_of_queries == 0)) {
                                        break;
 
                                if (!$complete && ( --$no_of_queries == 0)) {
                                        break;
index e2621073a5e81cc1336c36ec675d06132172c6c5..262da2d308196f87c1460c7fe1c600c8a719070f 100644 (file)
@@ -5,14 +5,13 @@
 namespace Friendica\Worker;
 
 use Friendica\Core\Logger;
 namespace Friendica\Worker;
 
 use Friendica\Core\Logger;
-use Friendica\Protocol\PortableContact;
+use Friendica\Model\GServer;
 
 class UpdateServerDirectory
 {
 
 class UpdateServerDirectory
 {
-       // Discover the given server id for their contacts
-       public static function execute($gserverid)
+       public static function execute($gserver)
        {
        {
-               PortableContact::discoverSingleServer($gserverid);
+               GServer::updateDirectory($gserver);
                return;
        }
 }
                return;
        }
 }
index 4097832989579be1d85c7aa249a20be842000b57..d3ce3fca77a8f6c03d89bd85dfc82c8b714a452f 100644 (file)
@@ -7,7 +7,7 @@ namespace Friendica\Worker;
 use Friendica\Core\Logger;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Core\Logger;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
-use Friendica\Protocol\PortableContact;
+use Friendica\Model\GServer;
 
 class UpdateServers
 {
 
 class UpdateServers
 {
@@ -25,7 +25,7 @@ class UpdateServers
                $updated = 0;
 
                while ($gserver = DBA::fetch($gservers)) {
                $updated = 0;
 
                while ($gserver = DBA::fetch($gservers)) {
-                       if (!PortableContact::updateNeeded($gserver['created'], '', $gserver['last_failure'], $gserver['last_contact'])) {
+                       if (!GServer::updateNeeded($gserver['created'], '', $gserver['last_failure'], $gserver['last_contact'])) {
                                continue;
                        }
                        Logger::info('Update server status', ['server' => $gserver['url']]);
                                continue;
                        }
                        Logger::info('Update server status', ['server' => $gserver['url']]);