fix: update RDAPService parser

This commit is contained in:
Maël Gangloff
2024-07-23 03:05:35 +02:00
parent 7c68919252
commit 1ef8a98586
5 changed files with 36 additions and 37 deletions

View File

@@ -23,7 +23,7 @@ class DomainEntity
#[Groups(['domain-entity:entity'])] #[Groups(['domain-entity:entity'])]
private ?Entity $entity = null; private ?Entity $entity = null;
#[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainRole::class)] #[ORM\Column(type: Types::SIMPLE_ARRAY)]
#[Groups(['domain-entity:entity', 'domain-entity:domain'])] #[Groups(['domain-entity:entity', 'domain-entity:domain'])]
private array $roles = []; private array $roles = [];

View File

@@ -15,9 +15,9 @@ class Event
#[ORM\Column] #[ORM\Column]
private ?int $id = null; private ?int $id = null;
#[ORM\Column(enumType: EventAction::class)] #[ORM\Column(length: 255)]
#[Groups(['event:list'])] #[Groups(['event:list'])]
private ?EventAction $action = null; private ?string $action = null;
#[ORM\Column(type: 'datetime_immutable')] #[ORM\Column(type: 'datetime_immutable')]
#[Groups(['event:list'])] #[Groups(['event:list'])]
@@ -29,12 +29,12 @@ class Event
return $this->id; return $this->id;
} }
public function getAction(): ?EventAction public function getAction(): ?string
{ {
return $this->action; return $this->action;
} }
public function setAction(EventAction $action): static public function setAction(string $action): static
{ {
$this->action = $action; $this->action = $action;

View File

@@ -24,7 +24,7 @@ class NameserverEntity
private ?Entity $entity = null; private ?Entity $entity = null;
#[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainRole::class)] #[ORM\Column(type: Types::SIMPLE_ARRAY)]
#[Groups(['nameserver-entity:entity', 'nameserver-entity:nameserver'])] #[Groups(['nameserver-entity:entity', 'nameserver-entity:nameserver'])]
private array $roles = []; private array $roles = [];

View File

@@ -12,9 +12,9 @@ use Symfony\Component\Serializer\Attribute\Groups;
class WatchListTrigger class WatchListTrigger
{ {
#[ORM\Id] #[ORM\Id]
#[ORM\Column(enumType: EventAction::class)] #[ORM\Column(length: 255)]
#[Groups(['watchlist:item', 'watchlist:create', 'watchlist:update'])] #[Groups(['watchlist:item', 'watchlist:create', 'watchlist:update'])]
private ?EventAction $event = null; private ?string $event = null;
#[ORM\Id] #[ORM\Id]
#[ORM\ManyToOne(targetEntity: WatchList::class, inversedBy: 'watchListTriggers')] #[ORM\ManyToOne(targetEntity: WatchList::class, inversedBy: 'watchListTriggers')]
@@ -26,12 +26,12 @@ class WatchListTrigger
#[Groups(['watchlist:item', 'watchlist:create', 'watchlist:update'])] #[Groups(['watchlist:item', 'watchlist:create', 'watchlist:update'])]
private ?TriggerAction $action = null; private ?TriggerAction $action = null;
public function getEvent(): ?EventAction public function getEvent(): ?string
{ {
return $this->event; return $this->event;
} }
public function setEvent(EventAction $event): static public function setEvent(string $event): static
{ {
$this->event = $event; $this->event = $event;

View File

@@ -3,7 +3,6 @@
namespace App\Service; namespace App\Service;
use App\Config\DomainRole;
use App\Config\EventAction; use App\Config\EventAction;
use App\Entity\Domain; use App\Entity\Domain;
use App\Entity\DomainEntity; use App\Entity\DomainEntity;
@@ -99,18 +98,17 @@ readonly class RDAPService
$this->em->flush(); $this->em->flush();
foreach ($res['events'] as $rdapEvent) { foreach ($res['events'] as $rdapEvent) {
$eventAction = EventAction::from($rdapEvent['eventAction']); if ($rdapEvent['eventAction'] === EventAction::LastUpdateOfRDAPDatabase->value) continue;
if ($eventAction === EventAction::LastUpdateOfRDAPDatabase) continue;
$event = $this->domainEventRepository->findOneBy([ $event = $this->domainEventRepository->findOneBy([
"action" => $eventAction, "action" => $rdapEvent['eventAction'],
"date" => new DateTimeImmutable($rdapEvent["eventDate"]), "date" => new DateTimeImmutable($rdapEvent["eventDate"]),
"domain" => $domain "domain" => $domain
]); ]);
if ($event === null) $event = new DomainEvent(); if ($event === null) $event = new DomainEvent();
$domain->addEvent($event $domain->addEvent($event
->setAction($eventAction) ->setAction($rdapEvent['eventAction'])
->setDate(new DateTimeImmutable($rdapEvent['eventDate']))); ->setDate(new DateTimeImmutable($rdapEvent['eventDate'])));
} }
@@ -130,20 +128,20 @@ readonly class RDAPService
if ($domainEntity === null) $domainEntity = new DomainEntity(); if ($domainEntity === null) $domainEntity = new DomainEntity();
$roles = array_merge( $roles = array_map(
...array_map( fn($e) => $e['roles'],
fn(array $e): array => $e['roles'], array_filter(
array_filter( $res['entities'],
$res['entities'], fn($e) => array_key_exists('handle', $e) && $e['handle'] === $rdapEntity['handle']
fn($e) => array_key_exists('handle', $e) && $e['handle'] === $rdapEntity['handle']
)
) )
); );
if (count($roles) !== count($roles, COUNT_RECURSIVE)) $roles = array_merge(...$roles);
$domain->addDomainEntity($domainEntity $domain->addDomainEntity($domainEntity
->setDomain($domain) ->setDomain($domain)
->setEntity($entity) ->setEntity($entity)
->setRoles(array_map(fn($str): DomainRole => DomainRole::from($str), $roles))); ->setRoles($roles));
$this->em->persist($domainEntity); $this->em->persist($domainEntity);
$this->em->flush(); $this->em->flush();
@@ -191,7 +189,7 @@ readonly class RDAPService
->setNameserver($nameserver) ->setNameserver($nameserver)
->setEntity($entity) ->setEntity($entity)
->setStatus($rdapNameserver['status']) ->setStatus($rdapNameserver['status'])
->setRoles(array_map(fn($str): DomainRole => DomainRole::from($str), $roles))); ->setRoles($roles));
} }
$domain->addNameserver($nameserver); $domain->addNameserver($nameserver);
@@ -232,27 +230,28 @@ readonly class RDAPService
$entity->setHandle($rdapEntity['handle']); $entity->setHandle($rdapEntity['handle']);
if (empty($entity->getJCard())) { if (array_key_exists('vcardArray', $rdapEntity)) {
$entity->setJCard($rdapEntity['vcardArray']); if (empty($entity->getJCard())) {
} else { $entity->setJCard($rdapEntity['vcardArray']);
$properties = []; } else {
foreach ($rdapEntity['vcardArray'][1] as $prop) { $properties = [];
$properties[$prop[0]] = $prop; foreach ($rdapEntity['vcardArray'][1] as $prop) {
$properties[$prop[0]] = $prop;
}
foreach ($entity->getJCard()[1] as $prop) {
$properties[$prop[0]] = $prop;
}
$entity->setJCard(["vcard", array_values($properties)]);
} }
foreach ($entity->getJCard()[1] as $prop) {
$properties[$prop[0]] = $prop;
}
$entity->setJCard(["vcard", array_values($properties)]);
} }
if (!array_key_exists('events', $rdapEntity)) return $entity; if (!array_key_exists('events', $rdapEntity)) return $entity;
foreach ($rdapEntity['events'] as $rdapEntityEvent) { foreach ($rdapEntity['events'] as $rdapEntityEvent) {
$eventAction = $rdapEntityEvent["eventAction"]; $eventAction = $rdapEntityEvent["eventAction"];
if ($eventAction === EventAction::LastChanged->value || $eventAction === EventAction::LastUpdateOfRDAPDatabase->value) continue; if ($eventAction === EventAction::LastChanged->value || $eventAction === EventAction::LastUpdateOfRDAPDatabase->value) continue;
$event = $this->entityEventRepository->findOneBy([ $event = $this->entityEventRepository->findOneBy([
"action" => EventAction::from($rdapEntityEvent["eventAction"]), "action" => $rdapEntityEvent["eventAction"],
"date" => new DateTimeImmutable($rdapEntityEvent["eventDate"]) "date" => new DateTimeImmutable($rdapEntityEvent["eventDate"])
]); ]);
@@ -260,7 +259,7 @@ readonly class RDAPService
$entity->addEvent( $entity->addEvent(
(new EntityEvent()) (new EntityEvent())
->setEntity($entity) ->setEntity($entity)
->setAction(EventAction::from($rdapEntityEvent['eventAction'])) ->setAction($rdapEntityEvent["eventAction"])
->setDate(new DateTimeImmutable($rdapEntityEvent['eventDate']))); ->setDate(new DateTimeImmutable($rdapEntityEvent['eventDate'])));
} }