mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-17 09:45:29 +00:00
feat: use timestamp instead of bool on deletedAt
This commit is contained in:
parent
c4f79bece8
commit
d8cfef2bce
35
migrations/Version20250915213341.php
Normal file
35
migrations/Version20250915213341.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?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 Version20250915213341 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'deleted_at on domain_entity';
|
||||
}
|
||||
|
||||
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_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
|
||||
$this->addSql('UPDATE domain_entity SET deleted_at = NOW() WHERE deleted IS TRUE');
|
||||
$this->addSql('ALTER TABLE domain_entity DROP deleted');
|
||||
$this->addSql('COMMENT ON COLUMN domain_entity.deleted_at IS \'(DC2Type:datetime_immutable)\'');
|
||||
}
|
||||
|
||||
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 deleted BOOLEAN NOT NULL DEFAULT FALSE');
|
||||
$this->addSql('ALTER TABLE domain_entity DROP deleted_at');
|
||||
}
|
||||
}
|
||||
@ -660,7 +660,7 @@ class Domain
|
||||
$attendees = [];
|
||||
|
||||
/* @var DomainEntity $entity */
|
||||
foreach ($this->getDomainEntities()->filter(fn (DomainEntity $domainEntity) => !$domainEntity->getDeleted())->getIterator() as $domainEntity) {
|
||||
foreach ($this->getDomainEntities()->filter(fn (DomainEntity $domainEntity) => !$domainEntity->getDeletedAt())->getIterator() as $domainEntity) {
|
||||
$jCard = $domainEntity->getEntity()->getJCard();
|
||||
|
||||
if (empty($jCard)) {
|
||||
|
||||
@ -27,14 +27,9 @@ class DomainEntity
|
||||
#[Groups(['domain-entity:entity', 'domain-entity:domain'])]
|
||||
private array $roles = [];
|
||||
|
||||
#[ORM\Column]
|
||||
#[ORM\Column(nullable: true)]
|
||||
#[Groups(['domain-entity:entity', 'domain-entity:domain'])]
|
||||
private ?bool $deleted;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->deleted = false;
|
||||
}
|
||||
private ?\DateTimeImmutable $deletedAt = null;
|
||||
|
||||
public function getDomain(): ?Domain
|
||||
{
|
||||
@ -75,14 +70,14 @@ class DomainEntity
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDeleted(): ?bool
|
||||
public function getDeletedAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->deleted;
|
||||
return $this->deletedAt;
|
||||
}
|
||||
|
||||
public function setDeleted(?bool $deleted): static
|
||||
public function setDeletedAt(?\DateTimeImmutable $deletedAt): static
|
||||
{
|
||||
$this->deleted = $deleted;
|
||||
$this->deletedAt = $deletedAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -36,6 +36,7 @@ use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\HttpClient\Exception\ClientException;
|
||||
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
@ -267,7 +268,7 @@ class RDAPService
|
||||
private function handleRdapException(\Exception $e, string $idnDomain, ?Domain $domain, ?ResponseInterface $response): \Exception
|
||||
{
|
||||
if (
|
||||
($e instanceof ClientException && 404 === $e->getResponse()->getStatusCode())
|
||||
($e instanceof ClientException && Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode())
|
||||
|| ($e instanceof TransportExceptionInterface && null !== $response && !in_array('content-length', $response->getHeaders(false)) && 404 === $response->getStatusCode())
|
||||
) {
|
||||
if (null !== $domain) {
|
||||
@ -386,8 +387,9 @@ class RDAPService
|
||||
*/
|
||||
private function updateDomainEntities(Domain $domain, array $rdapData): void
|
||||
{
|
||||
$now = new \DateTimeImmutable();
|
||||
foreach ($domain->getDomainEntities()->getIterator() as $domainEntity) {
|
||||
$domainEntity->setDeleted(true);
|
||||
$domainEntity->setDeletedAt($now);
|
||||
}
|
||||
|
||||
if (!isset($rdapData['entities']) || !is_array($rdapData['entities'])) {
|
||||
@ -411,7 +413,7 @@ class RDAPService
|
||||
->setDomain($domain)
|
||||
->setEntity($entity)
|
||||
->setRoles($roles)
|
||||
->setDeleted(false));
|
||||
->setDeletedAt(null));
|
||||
|
||||
$this->em->persist($domainEntity);
|
||||
$this->em->flush();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user