Merge pull request #6608 from MrPetovan/bug/6386-fix-poco-discover-server-users

Fix poco discover server users
This commit is contained in:
Michael Vogel 2019-02-10 00:38:07 +01:00 committed by GitHub
commit ff2164ee85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 16 deletions

View File

@ -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.")],

View File

@ -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)) {
@ -1695,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);
}
}

View File

@ -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();