From: Michael Date: Sat, 13 Jul 2019 23:53:15 +0000 (+0000) Subject: Hopefully avoiding duplicated relay entries X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5bba0e7d3941ad87c4f3fd9e0d90b42e70850b2d;p=friendica.git Hopefully avoiding duplicated relay entries --- diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index a264398efd..5f37684ad6 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -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); }