1
1
Fork 0

Hopefully avoiding duplicated relay entries

This commit is contained in:
Michael 2019-07-13 23:53:15 +00:00
parent 2df17fc0c0
commit 5bba0e7d39

View file

@ -180,21 +180,25 @@ class Diaspora
public static function setRelayContact($server_url, array $network_fields = [])
{
$fields = ['created' => DateTimeFormat::utcNow(),
'name' => 'relay', 'nick' => 'relay',
'url' => $server_url, 'network' => Protocol::DIASPORA,
'name' => 'relay', 'nick' => 'relay', 'url' => $server_url,
'nurl' => Strings::normaliseLink($server_url),
'network' => Protocol::DIASPORA, 'uid' => 0,
'batch' => $server_url . '/receive/public',
'rel' => Contact::FOLLOWER, 'blocked' => false,
'pending' => false, 'writable' => true];
'pending' => false, 'writable' => true,
'baseurl' => $server_url, 'contact-type' => Contact::TYPE_RELAY];
$fields = array_merge($fields, $network_fields);
$condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url),
'contact-type' => Contact::TYPE_RELAY];
if (DBA::exists('contact', $condition)) {
$condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url)];
$relay = DBA::selectFirst('contact', ['id'], $condition);
if (DBA::isResult($relay)) {
unset($fields['created']);
$condition = ['id' => $relay['id']];
}
Logger::info('Set relay contact', ['fields' => $fields, 'condition' => $condition]);
DBA::update('contact', $fields, $condition, true);
}