From e46851ca54b98958a88c528259c51fa544162579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Tue, 6 Aug 2024 19:05:02 +0200 Subject: [PATCH] feat: add updatedAt on DomainEntity --- migrations/Version20240806170123.php | 34 ++++++++++++++++++++++ src/Controller/DomainRefreshController.php | 1 - src/Entity/DomainEntity.php | 28 ++++++++++++++++++ src/Service/RDAPService.php | 3 +- 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 migrations/Version20240806170123.php diff --git a/migrations/Version20240806170123.php b/migrations/Version20240806170123.php new file mode 100644 index 0000000..1b56581 --- /dev/null +++ b/migrations/Version20240806170123.php @@ -0,0 +1,34 @@ +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'); + } +} diff --git a/src/Controller/DomainRefreshController.php b/src/Controller/DomainRefreshController.php index 2e11957..f4d81df 100644 --- a/src/Controller/DomainRefreshController.php +++ b/src/Controller/DomainRefreshController.php @@ -32,7 +32,6 @@ class DomainRefreshController extends AbstractController /** * @throws TransportExceptionInterface - * @throws HttpExceptionInterface * @throws DecodingExceptionInterface * @throws ExceptionInterface * @throws \Exception diff --git a/src/Entity/DomainEntity.php b/src/Entity/DomainEntity.php index 50ad16d..54a8f00 100644 --- a/src/Entity/DomainEntity.php +++ b/src/Entity/DomainEntity.php @@ -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')); + } } diff --git a/src/Service/RDAPService.php b/src/Service/RDAPService.php index 92e7d5e..8f4bc9b 100644 --- a/src/Service/RDAPService.php +++ b/src/Service/RDAPService.php @@ -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();