From 066ad8c01b25b7101ad6fb36878d85c97db51a6f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 8 Feb 2019 08:38:13 -0500 Subject: [PATCH 1/2] Add PortableContact constants - Fix typo in mod/admin - Replace deprecated Logger::log calls --- mod/admin.php | 13 +++++++------ src/Protocol/PortableContact.php | 17 ++++++++++------- src/Worker/DiscoverPoCo.php | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index 39f7502188..fcca69644e 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -29,6 +29,7 @@ use Friendica\Model\User; use Friendica\Module; use Friendica\Module\Login; use Friendica\Module\Tos; +use Friendica\Protocol\PortableContact; use Friendica\Util\Arrays; use Friendica\Util\BasePath; use Friendica\Util\DateTimeFormat; @@ -1155,7 +1156,7 @@ function admin_page_site_post(App $a) $optimize_fragmentation = (!empty($_POST['optimize_fragmentation']) ? intval(trim($_POST['optimize_fragmentation'])) : 30); $poco_completion = (!empty($_POST['poco_completion']) ? intval(trim($_POST['poco_completion'])) : false); $poco_requery_days = (!empty($_POST['poco_requery_days']) ? intval(trim($_POST['poco_requery_days'])) : 7); - $poco_discovery = (!empty($_POST['poco_discovery']) ? intval(trim($_POST['poco_discovery'])) : 0); + $poco_discovery = (!empty($_POST['poco_discovery']) ? intval(trim($_POST['poco_discovery'])) : PortableContact::DISABLED); $poco_discovery_since = (!empty($_POST['poco_discovery_since']) ? intval(trim($_POST['poco_discovery_since'])) : 30); $poco_local_search = !empty($_POST['poco_local_search']); $nodeinfo = !empty($_POST['nodeinfo']); @@ -1477,10 +1478,10 @@ function admin_page_site(App $a) ]; $poco_discovery_choices = [ - "0" => L10n::t("Disabled"), - "1" => L10n::t("Users"), - "2" => L10n::t("Users, Global Contacts"), - "3" => L10n::t("Users, Global Contacts/fallback"), + PortableContact::DISABLED => L10n::t("Disabled"), + PortableContact::USERS => L10n::t("Users"), + PortableContact::USERS_GCONTACTS => L10n::t("Users, Global Contacts"), + PortableContact::USERS_GCONTACTS_FALLBACK => L10n::t("Users, Global Contacts/fallback"), ]; $poco_discovery_since_choices = [ @@ -1656,7 +1657,7 @@ function admin_page_site(App $a) '$poco_completion' => ['poco_completion', L10n::t("Periodical check of global contacts"), Config::get('system', 'poco_completion'), L10n::t("If enabled, the global contacts are checked periodically for missing or outdated data and the vitality of the contacts and servers.")], '$poco_requery_days' => ['poco_requery_days', L10n::t("Days between requery"), Config::get('system', 'poco_requery_days'), L10n::t("Number of days after which a server is requeried for his contacts.")], - '$poco_discovery' => ['poco_discovery', L10n::t("Discover contacts from other servers"), (string)intval(Config::get('system', 'poco_discovery')), L10n::t("Periodically query other servers for contacts. You can choose between 'users': the users on the remote system, 'Global Contacts': active contacts that are known on the system. The fallback is meant for Redmatrix servers and older friendica servers, where global contacts weren't available. The fallback increases the server load, so the recommened setting is 'Users, Global Contacts'."), $poco_discovery_choices], + '$poco_discovery' => ['poco_discovery', L10n::t("Discover contacts from other servers"), (string)intval(Config::get('system', 'poco_discovery')), L10n::t("Periodically query other servers for contacts. You can choose between 'users': the users on the remote system, 'Global Contacts': active contacts that are known on the system. The fallback is meant for Redmatrix servers and older friendica servers, where global contacts weren't available. The fallback increases the server load, so the recommended setting is 'Users, Global Contacts'."), $poco_discovery_choices], '$poco_discovery_since' => ['poco_discovery_since', L10n::t("Timeframe for fetching global contacts"), (string)intval(Config::get('system', 'poco_discovery_since')), L10n::t("When the discovery is activated, this value defines the timeframe for the activity of the global contacts that are fetched from other servers."), $poco_discovery_since_choices], '$poco_local_search' => ['poco_local_search', L10n::t("Search the local directory"), Config::get('system', 'poco_local_search'), L10n::t("Search the local directory instead of the global directory. When searching locally, every search will be executed on the global directory in the background. This improves the search results when the search is repeated.")], diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index 0bc17d3dce..5b5cd6fb1a 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -29,6 +29,11 @@ use Friendica\Util\XML; class PortableContact { + const DISABLED = 0; + const USERS = 1; + const USERS_GCONTACTS = 2; + const USERS_GCONTACTS_FALLBACK = 3; + /** * @brief Fetch POCO data * @@ -1645,21 +1650,19 @@ class PortableContact public static function discoverSingleServer($id) { - $r = q("SELECT `poco`, `nurl`, `url`, `network` FROM `gserver` WHERE `id` = %d", intval($id)); + $server = DBA::selectFirst('gserver', ['poco', 'nurl', 'url', 'network'], ['id' => $id]); - if (!DBA::isResult($r)) { + if (!DBA::isResult($server)) { return false; } - $server = $r[0]; - // Discover new servers out there (Works from Friendica version 3.5.2) self::fetchServerlist($server["poco"]); // Fetch all users from the other server $url = $server["poco"] . "/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; - Logger::log("Fetch all users from the server " . $server["url"], Logger::DEBUG); + Logger::info("Fetch all users from the server " . $server["url"]); $curlResult = Network::curl($url); @@ -1670,7 +1673,7 @@ class PortableContact self::discoverServer($data, 2); } - if (Config::get('system', 'poco_discovery') > 1) { + if (Config::get('system', 'poco_discovery') >= self::USERS_GCONTACTS) { $timeframe = Config::get('system', 'poco_discovery_since'); if ($timeframe == 0) { @@ -1687,7 +1690,7 @@ class PortableContact $curlResult = Network::curl($url); if ($curlResult->isSuccess() && !empty($curlResult->getBody())) { - Logger::log("Fetch all global contacts from the server " . $server["nurl"], Logger::DEBUG); + Logger::info("Fetch all global contacts from the server " . $server["nurl"]); $data = json_decode($curlResult->getBody(), true); if (!empty($data)) { diff --git a/src/Worker/DiscoverPoCo.php b/src/Worker/DiscoverPoCo.php index c2a81e7e72..e8f5055c86 100644 --- a/src/Worker/DiscoverPoCo.php +++ b/src/Worker/DiscoverPoCo.php @@ -99,7 +99,7 @@ class DiscoverPoCo } elseif (($mode == 1) && ($search != "") && Config::get('system', 'poco_local_search')) { self::discoverDirectory($search); self::gsSearchUser($search); - } elseif (($mode == 0) && ($search == "") && (Config::get('system', 'poco_discovery') > 0)) { + } elseif (($mode == 0) && ($search == "") && (Config::get('system', 'poco_discovery') != PortableContact::DISABLED)) { // Query Friendica and Hubzilla servers for their users PortableContact::discover(); From 1eb607b351bf5a63711745adc6e2e74f500cc1bb Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 8 Feb 2019 09:23:22 -0500 Subject: [PATCH 2/2] Add missing non-empty data condition to Protocol\PortableContact --- src/Protocol/PortableContact.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index 5b5cd6fb1a..7900ff540b 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -1698,8 +1698,8 @@ class PortableContact } } - if (!$success && (Config::get('system', 'poco_discovery') > 2)) { - Logger::log("Fetch contacts from users of the server " . $server["nurl"], Logger::DEBUG); + if (!$success && !empty($data) && Config::get('system', 'poco_discovery') >= self::USERS_GCONTACTS_FALLBACK) { + Logger::info("Fetch contacts from users of the server " . $server["nurl"]); self::discoverServerUsers($data, $server); } }