Hopefully avoiding duplicated relay entries
This commit is contained in:
parent
2df17fc0c0
commit
5bba0e7d39
1 changed files with 11 additions and 7 deletions
|
@ -180,21 +180,25 @@ class Diaspora
|
||||||
public static function setRelayContact($server_url, array $network_fields = [])
|
public static function setRelayContact($server_url, array $network_fields = [])
|
||||||
{
|
{
|
||||||
$fields = ['created' => DateTimeFormat::utcNow(),
|
$fields = ['created' => DateTimeFormat::utcNow(),
|
||||||
'name' => 'relay', 'nick' => 'relay',
|
'name' => 'relay', 'nick' => 'relay', 'url' => $server_url,
|
||||||
'url' => $server_url, 'network' => Protocol::DIASPORA,
|
'nurl' => Strings::normaliseLink($server_url),
|
||||||
|
'network' => Protocol::DIASPORA, 'uid' => 0,
|
||||||
'batch' => $server_url . '/receive/public',
|
'batch' => $server_url . '/receive/public',
|
||||||
'rel' => Contact::FOLLOWER, 'blocked' => false,
|
'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);
|
$fields = array_merge($fields, $network_fields);
|
||||||
|
|
||||||
$condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url),
|
$condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url)];
|
||||||
'contact-type' => Contact::TYPE_RELAY];
|
$relay = DBA::selectFirst('contact', ['id'], $condition);
|
||||||
|
if (DBA::isResult($relay)) {
|
||||||
if (DBA::exists('contact', $condition)) {
|
|
||||||
unset($fields['created']);
|
unset($fields['created']);
|
||||||
|
$condition = ['id' => $relay['id']];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger::info('Set relay contact', ['fields' => $fields, 'condition' => $condition]);
|
||||||
|
|
||||||
DBA::update('contact', $fields, $condition, true);
|
DBA::update('contact', $fields, $condition, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue