fix: identify tld type

This commit is contained in:
Maël Gangloff
2024-07-24 22:17:54 +02:00
parent 3d4f905eab
commit 416ffd4a7f
3 changed files with 53 additions and 10 deletions

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240724201612 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TEMPORARY TABLE __temp__tld AS SELECT tld, contract_terminated, date_of_contract_signature, delegation_date, registry_operator, removal_date, specification13, type FROM tld');
$this->addSql('DROP TABLE tld');
$this->addSql('CREATE TABLE tld (tld VARCHAR(63) NOT NULL, contract_terminated BOOLEAN DEFAULT NULL, date_of_contract_signature DATE DEFAULT NULL --(DC2Type:date_immutable)
, delegation_date DATE DEFAULT NULL --(DC2Type:date_immutable)
, registry_operator VARCHAR(255) DEFAULT NULL, removal_date DATE DEFAULT NULL --(DC2Type:date_immutable)
, specification13 BOOLEAN DEFAULT NULL, type VARCHAR(10) NOT NULL, PRIMARY KEY(tld))');
$this->addSql('INSERT INTO tld (tld, contract_terminated, date_of_contract_signature, delegation_date, registry_operator, removal_date, specification13, type) SELECT tld, contract_terminated, date_of_contract_signature, delegation_date, registry_operator, removal_date, specification13, type FROM __temp__tld');
$this->addSql('DROP TABLE __temp__tld');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TEMPORARY TABLE __temp__tld AS SELECT tld, contract_terminated, date_of_contract_signature, delegation_date, registry_operator, removal_date, specification13, type FROM tld');
$this->addSql('DROP TABLE tld');
$this->addSql('CREATE TABLE tld (tld VARCHAR(63) NOT NULL, contract_terminated BOOLEAN DEFAULT NULL, date_of_contract_signature DATE DEFAULT NULL --(DC2Type:date_immutable)
, delegation_date DATE DEFAULT NULL --(DC2Type:date_immutable)
, registry_operator VARCHAR(255) DEFAULT NULL, removal_date DATE DEFAULT NULL --(DC2Type:date_immutable)
, specification13 BOOLEAN DEFAULT NULL, type VARCHAR(10) DEFAULT NULL, PRIMARY KEY(tld))');
$this->addSql('INSERT INTO tld (tld, contract_terminated, date_of_contract_signature, delegation_date, registry_operator, removal_date, specification13, type) SELECT tld, contract_terminated, date_of_contract_signature, delegation_date, registry_operator, removal_date, specification13, type FROM __temp__tld');
$this->addSql('DROP TABLE __temp__tld');
}
}

View File

@@ -68,7 +68,7 @@ class Tld
#[Groups(["tld:list", "tld:item"])]
private ?bool $specification13 = null;
#[ORM\Column(length: 10, nullable: true, enumType: TldType::class)]
#[ORM\Column(length: 10, enumType: TldType::class)]
#[Groups(["tld:item"])]
private ?TldType $type = null;

View File

@@ -339,15 +339,13 @@ readonly class RDAPService
$tldEntity = $this->tldRepository->findOneBy(['tld' => $tld]);
if ($tldEntity === null) $tldEntity = new Tld();
if ($tldEntity->getType() === null) {
$type = $this->getTldType($tld);
if ($type !== null) {
$tldEntity->setType($type);
} elseif ($tldEntity->isContractTerminated() === null) {
$tldEntity->setType(TldType::ccTLD);
} else {
$tldEntity->setType(TldType::gTLD);
}
$type = $this->getTldType($tld);
if ($type !== null) {
$tldEntity->setType($type);
} elseif ($tldEntity->isContractTerminated() === null) {
$tldEntity->setType(TldType::ccTLD);
} else {
$tldEntity->setType(TldType::gTLD);
}
$this->em->persist($tldEntity);