From 75f97db4ecfb84a4e52d2dbb5e3dc215f2725083 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 11 Apr 2018 18:56:22 +0000 Subject: [PATCH 1/2] Issue-4816: Avoid SQL errors / Unarchive living relais servers --- src/Model/Contact.php | 7 ++++++- src/Protocol/PortableContact.php | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 1354bbdb89..644662e4ec 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -345,9 +345,14 @@ class Contact extends BaseObject $fields = ['term-date' => NULL_DATE, 'archive' => false]; dba::update('contact', $fields, ['id' => $contact['id']]); - if ($contact['url'] != '') { + if (!empty($contact['url'])) { dba::update('contact', $fields, ['nurl' => normalise_link($contact['url'])]); } + + if (!empty($contact['batch'])) { + $condition = ['batch' => $contact['batch'], 'contact-type' => ACCOUNT_TYPE_RELAY]; + dba::update('contact', $fields, $condition); + } } /** diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index d5e9d8f8c6..20f5cb0b02 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -1418,7 +1418,13 @@ class PortableContact dba::delete('gserver-tag', ['gserver-id' => $gserver['id']]); if ($data->scope == 'tags') { + // Avoid duplicates + $tags = []; foreach ($data->tags as $tag) { + $tags[$tag] = $tag; + } + + foreach ($tags as $tag) { dba::insert('gserver-tag', ['gserver-id' => $gserver['id'], 'tag' => $tag]); } } From 4fd4d277f00b61ab413faf66758229e1dcd0ff09 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 12 Apr 2018 08:55:36 +0000 Subject: [PATCH 2/2] Store in lowercase to avoid duplicates --- src/Protocol/PortableContact.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index 20f5cb0b02..f7ea27d679 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -1421,6 +1421,7 @@ class PortableContact // Avoid duplicates $tags = []; foreach ($data->tags as $tag) { + $tag = strtolower($tag); $tags[$tag] = $tag; }