Skip to content

Commit

Permalink
feat: add updatedAt on DomainEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
maelgangloff committed Aug 6, 2024
1 parent 1fd5dd9 commit e46851c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
34 changes: 34 additions & 0 deletions migrations/Version20240806170123.php
Original file line number Diff line number Diff line change
@@ -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');
}
}
1 change: 0 additions & 1 deletion src/Controller/DomainRefreshController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function __construct(private readonly DomainRepository $domainRepository,

/**
* @throws TransportExceptionInterface
* @throws HttpExceptionInterface
* @throws DecodingExceptionInterface
* @throws ExceptionInterface
* @throws \Exception
Expand Down
28 changes: 28 additions & 0 deletions src/Entity/DomainEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,4 +74,23 @@ public function setRoles(array $roles): static

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'));
}
}
3 changes: 2 additions & 1 deletion src/Service/RDAPService.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ public function registerDomain(string $fqdn): Domain
$domain->addDomainEntity($domainEntity
->setDomain($domain)
->setEntity($entity)
->setRoles($roles));
->setRoles($roles))
->updateTimestamps();

$this->em->persist($domainEntity);
$this->em->flush();
Expand Down

0 comments on commit e46851c

Please sign in to comment.