From 0e98b7d0c1926bb24db83ac17567e212fc2e0b79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Mon, 9 Sep 2024 11:53:54 +0200 Subject: [PATCH] fix: duplicate key value violates unique constraint error --- src/Service/RDAPService.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Service/RDAPService.php b/src/Service/RDAPService.php index 5bd9587..6c353ec 100644 --- a/src/Service/RDAPService.php +++ b/src/Service/RDAPService.php @@ -307,12 +307,17 @@ readonly class RDAPService if (array_key_exists('nameservers', $res) && is_array($res['nameservers'])) { $domain->getNameservers()->clear(); - $this->em->persist($domain); foreach ($res['nameservers'] as $rdapNameserver) { $nameserver = $this->nameserverRepository->findOneBy([ 'ldhName' => strtolower($rdapNameserver['ldhName']), ]); + + $domainNS = $domain->getNameservers()->findFirst(fn (Nameserver $ns) => $ns->getLdhName() === $rdapNameserver['ldhName']); + + if (null !== $domainNS) { + $nameserver = $domainNS; + } if (null === $nameserver) { $nameserver = new Nameserver(); }