feat: add delete property on DomainEntity

This commit is contained in:
Maël Gangloff 2024-09-04 18:06:02 +02:00
parent 7bdb289461
commit 689ad51e3a
No known key found for this signature in database
GPG Key ID: 11FDC81C24A7F629
5 changed files with 59 additions and 23 deletions

View File

@ -27,6 +27,7 @@ export interface Event {
export interface Entity {
handle: string
jCard: any
deleted: boolean
}
export interface Nameserver {

View File

@ -1,9 +1,11 @@
import {Domain} from "../api";
export const sortDomainEntities = (domain: Domain) => domain.entities.sort((e1, e2) => {
const p = (r: string[]) => r.includes('registrant') ? 5 :
r.includes('administrative') ? 4 :
r.includes('billing') ? 3 :
r.includes('registrar') ? 2 : 1
return p(e2.roles) - p(e1.roles)
})
export const sortDomainEntities = (domain: Domain) => domain.entities
.filter(e => !e.entity.deleted)
.sort((e1, e2) => {
const p = (r: string[]) => r.includes('registrant') ? 5 :
r.includes('administrative') ? 4 :
r.includes('billing') ? 3 :
r.includes('registrar') ? 2 : 1
return p(e2.roles) - p(e1.roles)
})

View File

@ -0,0 +1,34 @@
<?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 Version20240904155605 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('ALTER TABLE domain_entity ADD deleted BOOLEAN NOT NULL DEFAULT FALSE');
$this->addSql('ALTER TABLE domain_entity DROP updated_at');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE domain_entity ADD updated_at DATE NOT NULL');
$this->addSql('ALTER TABLE domain_entity DROP deleted');
$this->addSql('COMMENT ON COLUMN domain_entity.updated_at IS \'(DC2Type:date_immutable)\'');
}
}

View File

@ -27,13 +27,13 @@ class DomainEntity
#[Groups(['domain-entity:entity', 'domain-entity:domain'])]
private array $roles = [];
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
#[ORM\Column]
#[Groups(['domain-entity:entity', 'domain-entity:domain'])]
private ?\DateTimeImmutable $updatedAt = null;
private ?bool $deleted;
public function __construct()
{
$this->updatedAt = new \DateTimeImmutable('now');
$this->deleted = false;
}
public function getDomain(): ?Domain
@ -75,22 +75,15 @@ class DomainEntity
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
public function getDeleted(): ?bool
{
return $this->updatedAt;
return $this->deleted;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): static
public function setDeleted(?bool $deleted): static
{
$this->updatedAt = $updatedAt;
$this->deleted = $deleted;
return $this;
}
#[ORM\PrePersist]
#[ORM\PreUpdate]
public function updateTimestamps(): void
{
$this->setUpdatedAt(new \DateTimeImmutable('now'));
}
}

View File

@ -244,6 +244,11 @@ readonly class RDAPService
);
}
/** @var DomainEntity $domainEntity */
foreach ($domain->getDomainEntities()->getIterator() as $domainEntity) {
$domainEntity->setDeleted(true);
}
if (array_key_exists('entities', $res) && is_array($res['entities'])) {
foreach ($res['entities'] as $rdapEntity) {
if (!array_key_exists('handle', $rdapEntity) || '' === $rdapEntity['handle']) {
@ -282,8 +287,9 @@ readonly class RDAPService
$domain->addDomainEntity($domainEntity
->setDomain($domain)
->setEntity($entity)
->setRoles($roles))
->updateTimestamps();
->setRoles($roles)
->setDeleted(false)
);
$this->em->persist($domainEntity);
$this->em->flush();