mirror of
https://github.com/friendica/friendica
synced 2024-12-22 23:20:16 +00:00
Merge pull request #12482 from annando/fix-reachable
Fix delivery problems with "reachable" test
This commit is contained in:
commit
45ee7d55f0
2 changed files with 35 additions and 23 deletions
|
@ -167,31 +167,43 @@ class GServer
|
|||
/**
|
||||
* Checks if the given server is reachable
|
||||
*
|
||||
* @param string $profile URL of the given profile
|
||||
* @param string $server URL of the given server (If empty, taken from profile)
|
||||
* @param string $network Network value that is used, when detection failed
|
||||
* @param boolean $force Force an update.
|
||||
* @param array $contact Contact that should be checked
|
||||
*
|
||||
* @return boolean 'true' if server seems vital
|
||||
*/
|
||||
public static function reachable(string $profile, string $server = '', string $network = '', bool $force = false): bool
|
||||
public static function reachable(array $contact): bool
|
||||
{
|
||||
if ($server == '') {
|
||||
$contact = Contact::getByURL($profile, null, ['baseurl', 'network']);
|
||||
if (!empty($contact['baseurl'])) {
|
||||
$server = $contact['baseurl'];
|
||||
} elseif ($contact['network'] == Protocol::DIASPORA) {
|
||||
$parts = parse_url($profile);
|
||||
unset($parts['path']);
|
||||
$server = (string)Uri::fromParts($parts);
|
||||
}
|
||||
}
|
||||
|
||||
if ($server == '') {
|
||||
if (!empty($contact['gsid'])) {
|
||||
$gsid = $contact['gsid'];
|
||||
} elseif (!empty($contact['baseurl'])) {
|
||||
$server = $contact['baseurl'];
|
||||
} elseif ($contact['network'] == Protocol::DIASPORA) {
|
||||
$parts = parse_url($contact['url']);
|
||||
unset($parts['path']);
|
||||
$server = (string)Uri::fromParts($parts);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
return self::check($server, $network, $force);
|
||||
if (!empty($gsid)) {
|
||||
$condition = ['id' => $gsid];
|
||||
} else {
|
||||
$condition = ['nurl' => Strings::normaliseLink($server)];
|
||||
}
|
||||
|
||||
$gserver = DBA::selectFirst('gserver', ['url', 'next_contact', 'failed'], $condition);
|
||||
if (empty($gserver)) {
|
||||
$reachable = true;
|
||||
} else {
|
||||
$reachable = !$gserver['failed'];
|
||||
$server = $gserver['url'];
|
||||
}
|
||||
|
||||
if (!empty($server) && (empty($gserver) || strtotime($gserver['next_contact']) < time())) {
|
||||
Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $server, false);
|
||||
}
|
||||
|
||||
return $reachable;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -100,7 +100,7 @@ class Notifier
|
|||
$uid = $target_id;
|
||||
|
||||
$condition = ['uid' => $target_id, 'self' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
|
||||
$delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'addr', 'network', 'protocol', 'baseurl', 'batch'], $condition);
|
||||
$delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'addr', 'network', 'protocol', 'baseurl', 'gsid', 'batch'], $condition);
|
||||
} else {
|
||||
$post = Post::selectFirst(['id'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
|
||||
if (!DBA::isResult($post)) {
|
||||
|
@ -426,7 +426,7 @@ class Notifier
|
|||
if (!empty($networks)) {
|
||||
$condition['network'] = $networks;
|
||||
}
|
||||
$delivery_contacts_stmt = DBA::select('contact', ['id', 'addr', 'url', 'network', 'protocol', 'baseurl', 'batch'], $condition);
|
||||
$delivery_contacts_stmt = DBA::select('contact', ['id', 'addr', 'url', 'network', 'protocol', 'baseurl', 'gsid', 'batch'], $condition);
|
||||
}
|
||||
|
||||
$conversants = [];
|
||||
|
@ -438,7 +438,7 @@ class Notifier
|
|||
if ($diaspora_delivery && !$unlisted) {
|
||||
$batch_delivery = true;
|
||||
|
||||
$participants = DBA::selectToArray('contact', ['batch', 'network', 'protocol', 'baseurl', 'id', 'url', 'name'],
|
||||
$participants = DBA::selectToArray('contact', ['batch', 'network', 'protocol', 'baseurl', 'gsid', 'id', 'url', 'name'],
|
||||
["`network` = ? AND `batch` != '' AND `uid` = ? AND `rel` != ? AND NOT `blocked` AND NOT `pending` AND NOT `archive`", Protocol::DIASPORA, $owner['uid'], Contact::SHARING],
|
||||
['group_by' => ['batch', 'network', 'protocol']]);
|
||||
|
||||
|
@ -450,7 +450,7 @@ class Notifier
|
|||
$condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false,
|
||||
'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]];
|
||||
|
||||
$contacts = DBA::selectToArray('contact', ['id', 'url', 'addr', 'name', 'network', 'protocol', 'baseurl'], $condition);
|
||||
$contacts = DBA::selectToArray('contact', ['id', 'url', 'addr', 'name', 'network', 'protocol', 'baseurl', 'gsid'], $condition);
|
||||
|
||||
$conversants = array_merge($contacts, $participants);
|
||||
|
||||
|
@ -564,7 +564,7 @@ class Notifier
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!GServer::reachable($contact['url'], $contact['baseurl'], $contact['network'])) {
|
||||
if (!GServer::reachable($contact)) {
|
||||
Logger::info('Server is not reachable', ['id' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact]);
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue