feat: add updatedAt on DomainEntity

This commit is contained in:
Maël Gangloff
2024-08-06 19:05:02 +02:00
parent 1fd5dd90db
commit e46851ca54
4 changed files with 64 additions and 2 deletions

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 Version20240806170123 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 updated_at DATE DEFAULT CURRENT_TIMESTAMP NOT NULL');
$this->addSql('COMMENT ON COLUMN domain_entity.updated_at IS \'(DC2Type:date_immutable)\'');
$this->addSql('ALTER TABLE domain_entity ALTER updated_at DROP DEFAULT');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE domain_entity DROP updated_at');
}
}

View File

@@ -32,7 +32,6 @@ class DomainRefreshController extends AbstractController
/**
* @throws TransportExceptionInterface
* @throws HttpExceptionInterface
* @throws DecodingExceptionInterface
* @throws ExceptionInterface
* @throws \Exception

View File

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

View File

@@ -258,7 +258,8 @@ readonly class RDAPService
$domain->addDomainEntity($domainEntity
->setDomain($domain)
->setEntity($entity)
->setRoles($roles));
->setRoles($roles))
->updateTimestamps();
$this->em->persist($domainEntity);
$this->em->flush();