Merge pull request #12482 from annando/fix-reachable
Fix delivery problems with "reachable" test
This commit is contained in:
commit
45ee7d55f0
|
@ -167,31 +167,43 @@ class GServer
|
||||||
/**
|
/**
|
||||||
* Checks if the given server is reachable
|
* Checks if the given server is reachable
|
||||||
*
|
*
|
||||||
* @param string $profile URL of the given profile
|
* @param array $contact Contact that should be checked
|
||||||
* @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.
|
|
||||||
*
|
*
|
||||||
* @return boolean 'true' if server seems vital
|
* @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 == '') {
|
if (!empty($contact['gsid'])) {
|
||||||
$contact = Contact::getByURL($profile, null, ['baseurl', 'network']);
|
$gsid = $contact['gsid'];
|
||||||
if (!empty($contact['baseurl'])) {
|
} elseif (!empty($contact['baseurl'])) {
|
||||||
$server = $contact['baseurl'];
|
$server = $contact['baseurl'];
|
||||||
} elseif ($contact['network'] == Protocol::DIASPORA) {
|
} elseif ($contact['network'] == Protocol::DIASPORA) {
|
||||||
$parts = parse_url($profile);
|
$parts = parse_url($contact['url']);
|
||||||
unset($parts['path']);
|
unset($parts['path']);
|
||||||
$server = (string)Uri::fromParts($parts);
|
$server = (string)Uri::fromParts($parts);
|
||||||
}
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
if ($server == '') {
|
|
||||||
return true;
|
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;
|
$uid = $target_id;
|
||||||
|
|
||||||
$condition = ['uid' => $target_id, 'self' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
|
$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 {
|
} else {
|
||||||
$post = Post::selectFirst(['id'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
|
$post = Post::selectFirst(['id'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
|
||||||
if (!DBA::isResult($post)) {
|
if (!DBA::isResult($post)) {
|
||||||
|
@ -426,7 +426,7 @@ class Notifier
|
||||||
if (!empty($networks)) {
|
if (!empty($networks)) {
|
||||||
$condition['network'] = $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 = [];
|
$conversants = [];
|
||||||
|
@ -438,7 +438,7 @@ class Notifier
|
||||||
if ($diaspora_delivery && !$unlisted) {
|
if ($diaspora_delivery && !$unlisted) {
|
||||||
$batch_delivery = true;
|
$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],
|
["`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']]);
|
['group_by' => ['batch', 'network', 'protocol']]);
|
||||||
|
|
||||||
|
@ -450,7 +450,7 @@ class Notifier
|
||||||
$condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false,
|
$condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false,
|
||||||
'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]];
|
'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);
|
$conversants = array_merge($contacts, $participants);
|
||||||
|
|
||||||
|
@ -564,7 +564,7 @@ class Notifier
|
||||||
continue;
|
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]);
|
Logger::info('Server is not reachable', ['id' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user