fix: persist and flush entity

This commit is contained in:
Maël Gangloff
2024-07-12 15:32:48 +02:00
parent dafa519fb7
commit 48972e5297

View File

@@ -33,20 +33,22 @@ use Symfony\Component\Routing\Attribute\Route;
class TestController extends AbstractController class TestController extends AbstractController
{ {
#[Route(path: '/test', name: 'test')] #[Route(path: '/test/{fqdn}', name: 'test')]
public function testRoute(EntityRepository $entityRepository, public function testRoute(
DomainRepository $domainRepository, string $fqdn,
DomainEventRepository $domainEventRepository, EntityRepository $entityRepository,
NameserverRepository $nameserverRepository, DomainRepository $domainRepository,
NameserverEntityRepository $nameserverEntityRepository, DomainEventRepository $domainEventRepository,
EntityEventRepository $entityEventRepository, NameserverRepository $nameserverRepository,
DomainEntityRepository $domainEntityRepository, NameserverEntityRepository $nameserverEntityRepository,
EntityManagerInterface $em EntityEventRepository $entityEventRepository,
DomainEntityRepository $domainEntityRepository,
EntityManagerInterface $em
): Response ): Response
{ {
$rdap = new RDAPClient(['domain' => 'https://rdap.nic.fr/domain/']); $rdap = new RDAPClient(['domain' => 'https://rdap.nic.fr/domain/']);
try { try {
$res = $rdap->domainLookup('maelgangloff.fr', RDAPClient::ARRAY_OUTPUT); $res = $rdap->domainLookup($fqdn, RDAPClient::ARRAY_OUTPUT);
} catch (RDAPWrongRequest $e) { } catch (RDAPWrongRequest $e) {
return new Response(null, Response::HTTP_BAD_REQUEST); return new Response(null, Response::HTTP_BAD_REQUEST);
} catch (ClientExceptionInterface $e) { } catch (ClientExceptionInterface $e) {
@@ -106,6 +108,7 @@ class TestController extends AbstractController
"domain" => $domain, "domain" => $domain,
"entity" => $entity "entity" => $entity
]); ]);
if ($domainEntity === null) $domainEntity = new DomainEntity(); if ($domainEntity === null) $domainEntity = new DomainEntity();
@@ -114,6 +117,8 @@ class TestController extends AbstractController
->setEntity($entity) ->setEntity($entity)
->setRoles(array_map(fn($str): DomainRole => DomainRole::from($str), $rdapEntity['roles']))); ->setRoles(array_map(fn($str): DomainRole => DomainRole::from($str), $rdapEntity['roles'])));
$em->persist($entity);
$em->flush();
} }
$em->persist($domain); $em->persist($domain);