diff --git a/migrations/Version20240713135242.php b/migrations/Version20240713145845.php similarity index 86% rename from migrations/Version20240713135242.php rename to migrations/Version20240713145845.php index c0b5b55..226f47e 100644 --- a/migrations/Version20240713135242.php +++ b/migrations/Version20240713145845.php @@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration; /** * Auto-generated Migration: Please modify to your needs! */ -final class Version20240713135242 extends AbstractMigration +final class Version20240713145845 extends AbstractMigration { public function getDescription(): string { @@ -25,22 +25,22 @@ final class Version20240713135242 extends AbstractMigration $this->addSql('CREATE TABLE domain_nameservers (domain_ldh_name VARCHAR(255) NOT NULL, nameserver_ldh_name VARCHAR(255) NOT NULL, PRIMARY KEY(domain_ldh_name, nameserver_ldh_name), CONSTRAINT FK_B6E6B63AAF923913 FOREIGN KEY (domain_ldh_name) REFERENCES domain (ldh_name) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_B6E6B63AA6496BFE FOREIGN KEY (nameserver_ldh_name) REFERENCES nameserver (ldh_name) NOT DEFERRABLE INITIALLY IMMEDIATE)'); $this->addSql('CREATE INDEX IDX_B6E6B63AAF923913 ON domain_nameservers (domain_ldh_name)'); $this->addSql('CREATE INDEX IDX_B6E6B63AA6496BFE ON domain_nameservers (nameserver_ldh_name)'); - $this->addSql('CREATE TABLE domain_entity (domain_id VARCHAR(255) NOT NULL, entity_id INTEGER NOT NULL, roles CLOB NOT NULL --(DC2Type:simple_array) - , PRIMARY KEY(domain_id, entity_id), CONSTRAINT FK_614B48A1115F0EE5 FOREIGN KEY (domain_id) REFERENCES domain (ldh_name) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_614B48A181257D5D FOREIGN KEY (entity_id) REFERENCES entity (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('CREATE TABLE domain_entity (domain_id VARCHAR(255) NOT NULL, entity_id VARCHAR(255) NOT NULL, roles CLOB NOT NULL --(DC2Type:simple_array) + , PRIMARY KEY(domain_id, entity_id), CONSTRAINT FK_614B48A1115F0EE5 FOREIGN KEY (domain_id) REFERENCES domain (ldh_name) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_614B48A181257D5D FOREIGN KEY (entity_id) REFERENCES entity (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)'); $this->addSql('CREATE INDEX IDX_614B48A1115F0EE5 ON domain_entity (domain_id)'); $this->addSql('CREATE INDEX IDX_614B48A181257D5D ON domain_entity (entity_id)'); $this->addSql('CREATE TABLE domain_event (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, domain_id VARCHAR(255) NOT NULL, "action" VARCHAR(255) NOT NULL, date DATETIME NOT NULL --(DC2Type:datetime_immutable) , CONSTRAINT FK_E8D52271115F0EE5 FOREIGN KEY (domain_id) REFERENCES domain (ldh_name) NOT DEFERRABLE INITIALLY IMMEDIATE)'); $this->addSql('CREATE INDEX IDX_E8D52271115F0EE5 ON domain_event (domain_id)'); - $this->addSql('CREATE TABLE entity (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, handle VARCHAR(255) NOT NULL, tld VARCHAR(255) NOT NULL, j_card CLOB NOT NULL --(DC2Type:json) - )'); - $this->addSql('CREATE TABLE entity_event (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, entity_id INTEGER NOT NULL, "action" VARCHAR(255) NOT NULL, date DATETIME NOT NULL --(DC2Type:datetime_immutable) - , CONSTRAINT FK_975A3F5E81257D5D FOREIGN KEY (entity_id) REFERENCES entity (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('CREATE TABLE entity (handle VARCHAR(255) NOT NULL, j_card CLOB NOT NULL --(DC2Type:json) + , PRIMARY KEY(handle))'); + $this->addSql('CREATE TABLE entity_event (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, entity_id VARCHAR(255) NOT NULL, "action" VARCHAR(255) NOT NULL, date DATETIME NOT NULL --(DC2Type:datetime_immutable) + , CONSTRAINT FK_975A3F5E81257D5D FOREIGN KEY (entity_id) REFERENCES entity (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)'); $this->addSql('CREATE INDEX IDX_975A3F5E81257D5D ON entity_event (entity_id)'); $this->addSql('CREATE TABLE nameserver (ldh_name VARCHAR(255) NOT NULL, PRIMARY KEY(ldh_name))'); - $this->addSql('CREATE TABLE nameserver_entity (nameserver_id VARCHAR(255) NOT NULL, entity_id INTEGER NOT NULL, roles CLOB NOT NULL --(DC2Type:simple_array) + $this->addSql('CREATE TABLE nameserver_entity (nameserver_id VARCHAR(255) NOT NULL, entity_id VARCHAR(255) NOT NULL, roles CLOB NOT NULL --(DC2Type:simple_array) , status CLOB NOT NULL --(DC2Type:simple_array) - , PRIMARY KEY(nameserver_id, entity_id), CONSTRAINT FK_A269AFB41A555619 FOREIGN KEY (nameserver_id) REFERENCES nameserver (ldh_name) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_A269AFB481257D5D FOREIGN KEY (entity_id) REFERENCES entity (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + , PRIMARY KEY(nameserver_id, entity_id), CONSTRAINT FK_A269AFB41A555619 FOREIGN KEY (nameserver_id) REFERENCES nameserver (ldh_name) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_A269AFB481257D5D FOREIGN KEY (entity_id) REFERENCES entity (handle) NOT DEFERRABLE INITIALLY IMMEDIATE)'); $this->addSql('CREATE INDEX IDX_A269AFB41A555619 ON nameserver_entity (nameserver_id)'); $this->addSql('CREATE INDEX IDX_A269AFB481257D5D ON nameserver_entity (entity_id)'); $this->addSql('CREATE TABLE user (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, email VARCHAR(180) NOT NULL, roles CLOB NOT NULL --(DC2Type:json) diff --git a/src/Controller/TestController.php b/src/Controller/TestController.php index 276e0e8..e0c6fa7 100644 --- a/src/Controller/TestController.php +++ b/src/Controller/TestController.php @@ -49,7 +49,7 @@ class TestController extends AbstractController public function testRoute(string $fqdn): Response { $tld = $this->getTld($fqdn); - $rdapServer = $this->getRdapServer($tld); + $rdapServer = $this->getRDAPServer($tld); $res = $this->client->request( 'GET', $rdapServer . 'domain/' . $fqdn @@ -80,7 +80,7 @@ class TestController extends AbstractController foreach ($res['entities'] as $rdapEntity) { if (!array_key_exists('handle', $rdapEntity)) continue; - $entity = $this->processEntity($rdapEntity, $tld); + $entity = $this->processEntity($rdapEntity); $this->em->persist($entity); $this->em->flush(); @@ -118,8 +118,7 @@ class TestController extends AbstractController foreach ($rdapNameserver['entities'] as $rdapEntity) { if (!array_key_exists('handle', $rdapEntity)) continue; - - $entity = $this->processEntity($rdapEntity, $tld); + $entity = $this->processEntity($rdapEntity); $this->em->persist($entity); $this->em->flush(); @@ -133,8 +132,8 @@ class TestController extends AbstractController $nameserver->addNameserverEntity($nameserverEntity ->setNameserver($nameserver) - ->setStatus(array_map(fn($str): DomainStatus => DomainStatus::from($str), $rdapNameserver['status'])) ->setEntity($entity) + ->setStatus(array_map(fn($str): DomainStatus => DomainStatus::from($str), $rdapNameserver['status'])) ->setRoles(array_map(fn($str): DomainRole => DomainRole::from($str), $rdapEntity['roles']))); } @@ -157,7 +156,7 @@ class TestController extends AbstractController return strtolower(substr($domain, $lastDotPosition + 1)); } - private function getRdapServer(string $tld) + private function getRDAPServer(string $tld) { $dnsRoot = json_decode(file_get_contents($this->getParameter('kernel.project_dir') . '/src/Config/dns.json'))->services; @@ -167,16 +166,14 @@ class TestController extends AbstractController throw new Exception("This TLD ($tld) is not supported."); } - private function processEntity(array $rdapEntity, string $tld): Entity + private function processEntity(array $rdapEntity): Entity { $entity = $this->entityRepository->findOneBy([ - "handle" => $rdapEntity['handle'], - "tld" => $tld + "handle" => $rdapEntity['handle'] ]); if ($entity === null) $entity = new Entity(); $entity - ->setTld($tld) ->setHandle($rdapEntity['handle']) ->setJCard($rdapEntity['vcardArray']); diff --git a/src/Entity/DomainEntity.php b/src/Entity/DomainEntity.php index c376652..0defdd5 100644 --- a/src/Entity/DomainEntity.php +++ b/src/Entity/DomainEntity.php @@ -17,7 +17,7 @@ class DomainEntity #[ORM\Id] #[ORM\ManyToOne(targetEntity: Entity::class, cascade: ['persist'], inversedBy: 'domainEntities')] - #[ORM\JoinColumn(referencedColumnName: 'id', nullable: false)] + #[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)] private ?Entity $entity = null; #[ORM\Column(type: Types::SIMPLE_ARRAY, enumType: DomainRole::class)] diff --git a/src/Entity/Entity.php b/src/Entity/Entity.php index 7a79126..768c918 100644 --- a/src/Entity/Entity.php +++ b/src/Entity/Entity.php @@ -11,18 +11,11 @@ use Doctrine\ORM\Mapping as ORM; class Entity { + #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column] - private ?int $id = null; - - #[ORM\Column(length: 255)] private ?string $handle = null; - #[ORM\Column(length: 255)] - private ?string $tld = null; - /** * @var Collection */ @@ -51,11 +44,6 @@ class Entity $this->events = new ArrayCollection(); } - public function getId(): ?int - { - return $this->id; - } - public function getHandle(): ?string { return $this->handle; @@ -68,18 +56,6 @@ class Entity return $this; } - public function getTld(): ?string - { - return $this->tld; - } - - public function setTld(string $tld): static - { - $this->tld = $tld; - - return $this; - } - /** * @return Collection */ diff --git a/src/Entity/EntityEvent.php b/src/Entity/EntityEvent.php index 859e779..1ba127b 100644 --- a/src/Entity/EntityEvent.php +++ b/src/Entity/EntityEvent.php @@ -10,7 +10,7 @@ class EntityEvent extends Event { #[ORM\ManyToOne(targetEntity: Entity::class, inversedBy: 'events')] - #[ORM\JoinColumn(referencedColumnName: 'id', nullable: false)] + #[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)] private ?Entity $entity = null; diff --git a/src/Entity/NameserverEntity.php b/src/Entity/NameserverEntity.php index d0a4f48..b637285 100644 --- a/src/Entity/NameserverEntity.php +++ b/src/Entity/NameserverEntity.php @@ -18,7 +18,7 @@ class NameserverEntity #[ORM\Id] #[ORM\ManyToOne(targetEntity: Entity::class, cascade: ['persist'], inversedBy: 'nameserverEntities')] - #[ORM\JoinColumn(referencedColumnName: 'id', nullable: false)] + #[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)] private ?Entity $entity = null;