Skip to content

Commit

Permalink
Merge pull request #50 from guillaume-sainthillier/app-update
Browse files Browse the repository at this point in the history
App update
  • Loading branch information
guillaume-sainthillier authored Nov 22, 2024
2 parents 8eabd91 + 4a3189f commit fbdbfa1
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 66 deletions.
6 changes: 6 additions & 0 deletions docker/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
# Disable Topics tracking if not enabled explicitly: https://github.com/jkarlin/topics
header ?Permissions-Policy "browsing-topics=()"
header /build/* Cache-Control "public, max-age=31536000, immutable"
header /bundles/easyadmin/* Cache-Control "public, max-age=31536000, immutable"
# Cache favicons, images and SVGs for a year
header /images/* Cache-Control "public, max-age=31536000, immutable"
header /*.ico Cache-Control "public, max-age=31536000, immutable"
header /*.png Cache-Control "public, max-age=31536000, immutable"
header /*.svg Cache-Control "public, max-age=31536000, immutable"

php_server
}
7 changes: 4 additions & 3 deletions src/Entity/EntityTimestampableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace App\Entity;

use App\Utils\UnitOfWorkOptimizer;
use DateTimeImmutable;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
Expand All @@ -30,9 +31,9 @@ public function getCreatedAt(): ?DateTimeImmutable
return $this->createdAt;
}

public function setCreatedAt(DateTimeImmutable $updatedAt): void
public function setCreatedAt(DateTimeImmutable $createdAt): void
{
$this->createdAt = $updatedAt;
$this->createdAt = UnitOfWorkOptimizer::getDateTimeValue($this->createdAt, $createdAt);
}

public function getUpdatedAt(): ?DateTimeImmutable
Expand All @@ -42,6 +43,6 @@ public function getUpdatedAt(): ?DateTimeImmutable

public function setUpdatedAt(DateTimeImmutable $updatedAt): void
{
$this->updatedAt = $updatedAt;
$this->updatedAt = UnitOfWorkOptimizer::getDateTimeValue($this->updatedAt, $updatedAt);
}
}
26 changes: 13 additions & 13 deletions src/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
use App\Reject\Reject;
use App\Repository\EventRepository;
use App\Utils\TagUtils;
use App\Utils\UnitOfWorkOptimizer;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
Expand Down Expand Up @@ -78,18 +78,18 @@ class Event implements Stringable, ExternalIdentifiableInterface, InternalIdenti
private ?string $description = null;

#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?DateTimeInterface $externalUpdatedAt = null;
private ?DateTime $externalUpdatedAt = null;

#[Assert\NotBlank(message: 'Vous devez donner une date à votre événement')]
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
#[Groups(['elasticsearch:event:details'])]
#[Type("DateTimeInterface<'Y-m-d'>")]
private ?DateTimeInterface $startDate;
private ?DateTime $startDate;

#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
#[Groups(['elasticsearch:event:details'])]
#[Type("DateTimeInterface<'Y-m-d'>")]
private ?DateTimeInterface $endDate = null;
private ?DateTime $endDate = null;

#[ORM\Column(type: Types::STRING, length: 256, nullable: true)]
private ?string $hours = null;
Expand Down Expand Up @@ -541,38 +541,38 @@ public function setDescription(?string $description): self
return $this;
}

public function getExternalUpdatedAt(): ?DateTimeInterface
public function getExternalUpdatedAt(): ?DateTime
{
return $this->externalUpdatedAt;
}

public function setExternalUpdatedAt(?DateTimeInterface $externalUpdatedAt): self
public function setExternalUpdatedAt(?DateTime $externalUpdatedAt): self
{
$this->externalUpdatedAt = $externalUpdatedAt;
$this->externalUpdatedAt = UnitOfWorkOptimizer::getDateTimeValue($this->externalUpdatedAt, $externalUpdatedAt);

return $this;
}

public function getStartDate(): ?DateTimeInterface
public function getStartDate(): ?DateTime
{
return $this->startDate;
}

public function setStartDate(?DateTimeInterface $startDate): self
public function setStartDate(?DateTime $startDate): self
{
$this->startDate = $startDate;
$this->startDate = UnitOfWorkOptimizer::getDateValue($this->startDate, $startDate);

return $this;
}

public function getEndDate(): ?DateTimeInterface
public function getEndDate(): ?DateTime
{
return $this->endDate;
}

public function setEndDate(?DateTimeInterface $endDate): self
public function setEndDate(?DateTime $endDate): self
{
$this->endDate = $endDate;
$this->endDate = UnitOfWorkOptimizer::getDateValue($this->endDate, $endDate);

return $this;
}
Expand Down
11 changes: 6 additions & 5 deletions src/Entity/ParserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

use App\Reject\Reject;
use App\Repository\ParserDataRepository;
use DateTimeInterface;
use App\Utils\UnitOfWorkOptimizer;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

Expand All @@ -28,7 +29,7 @@ class ParserData
private ?string $externalOrigin = null;

#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?DateTimeInterface $lastUpdated = null;
private ?DateTime $lastUpdated = null;

#[ORM\Column(type: Types::INTEGER)]
private int $reason = Reject::VALID;
Expand Down Expand Up @@ -65,14 +66,14 @@ public function setExternalId(string $externalId): self
return $this;
}

public function getLastUpdated(): ?DateTimeInterface
public function getLastUpdated(): ?DateTime
{
return $this->lastUpdated;
}

public function setLastUpdated(?DateTimeInterface $lastUpdated): self
public function setLastUpdated(?DateTime $lastUpdated): self
{
$this->lastUpdated = $lastUpdated;
$this->lastUpdated = UnitOfWorkOptimizer::getDateTimeValue($this->lastUpdated, $lastUpdated);

return $this;
}
Expand Down
20 changes: 10 additions & 10 deletions src/Entity/ParserHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
namespace App\Entity;

use App\Repository\ParserHistoryRepository;
use App\Utils\UnitOfWorkOptimizer;
use DateTime;
use DateTimeInterface;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

Expand All @@ -22,10 +22,10 @@ class ParserHistory
{
use EntityIdentityTrait;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private DateTimeInterface $startDate;
private DateTime $startDate;

#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private DateTimeInterface $endDate;
private DateTime $endDate;

#[ORM\Column(type: Types::STRING, length: 127)]
private ?string $fromData = null;
Expand All @@ -48,7 +48,7 @@ public function __construct()
#[ORM\PrePersist]
public function majEndDate(): void
{
$this->endDate = new DateTime();
$this->setEndDate(new DateTime());
}

/**
Expand All @@ -59,14 +59,14 @@ public function getDuree(): int
return $this->endDate->getTimestamp() - $this->startDate->getTimestamp();
}

public function getStartDate(): ?DateTimeInterface
public function getStartDate(): ?DateTime
{
return $this->startDate;
}

public function setStartDate(DateTimeInterface $startDate): self
public function setStartDate(DateTime $startDate): self
{
$this->startDate = $startDate;
$this->startDate = UnitOfWorkOptimizer::getDateTimeValue($this->startDate, $startDate);

return $this;
}
Expand All @@ -83,14 +83,14 @@ public function setFromData(string $fromData): self
return $this;
}

public function getEndDate(): ?DateTimeInterface
public function getEndDate(): ?DateTime
{
return $this->endDate;
}

public function setEndDate(DateTimeInterface $endDate): self
public function setEndDate(DateTime $endDate): self
{
$this->endDate = $endDate;
$this->endDate = UnitOfWorkOptimizer::getDateTimeValue($this->endDate, $endDate);

return $this;
}
Expand Down
11 changes: 6 additions & 5 deletions src/Entity/PlaceMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

use App\Contracts\ExternalIdentifiableInterface;
use App\Repository\PlaceMetadataRepository;
use DateTimeInterface;
use App\Utils\UnitOfWorkOptimizer;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
Expand All @@ -33,7 +34,7 @@ class PlaceMetadata implements ExternalIdentifiableInterface, Stringable
private ?string $externalOrigin = null;

#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?DateTimeInterface $externalUpdatedAt = null;
private ?DateTime $externalUpdatedAt = null;

public function __toString(): string
{
Expand Down Expand Up @@ -67,14 +68,14 @@ public function setExternalOrigin(string $externalOrigin): self
return $this;
}

public function getExternalUpdatedAt(): ?DateTimeInterface
public function getExternalUpdatedAt(): ?DateTime
{
return $this->externalUpdatedAt;
}

public function setExternalUpdatedAt(?DateTimeInterface $externalUpdatedAt): self
public function setExternalUpdatedAt(?DateTime $externalUpdatedAt): self
{
$this->externalUpdatedAt = $externalUpdatedAt;
$this->externalUpdatedAt = UnitOfWorkOptimizer::getDateTimeValue($this->externalUpdatedAt, $externalUpdatedAt);

return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/ResetPasswordRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace App\Entity;

use App\Repository\ResetPasswordRequestRepository;
use DateTimeInterface;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestTrait;
Expand All @@ -25,7 +25,7 @@ class ResetPasswordRequest implements ResetPasswordRequestInterface
#[ORM\JoinColumn(nullable: false)]
private User $user;

public function __construct(User $user, DateTimeInterface $expiresAt, string $selector, string $hashedToken)
public function __construct(User $user, DateTimeImmutable $expiresAt, string $selector, string $hashedToken)
{
$this->user = $user;
$this->initialize($expiresAt, $selector, $hashedToken);
Expand Down
18 changes: 9 additions & 9 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use App\Contracts\PrefixableObjectKeyInterface;
use App\Doctrine\EntityListener\UserEmailEntityListener;
use App\Repository\UserRepository;
use App\Utils\UnitOfWorkOptimizer;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
Expand Down Expand Up @@ -66,10 +66,10 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Seriali
private bool $enabled = true;

#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?DateTimeInterface $lastLogin;
private ?DateTime $lastLogin;

#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?DateTimeInterface $passwordRequestedAt = null;
private ?DateTime $passwordRequestedAt = null;

#[ORM\Column(type: Types::JSON)]
private array $roles = [];
Expand Down Expand Up @@ -575,26 +575,26 @@ public function setEnabled(bool $enabled): self
return $this;
}

public function getLastLogin(): ?DateTimeInterface
public function getLastLogin(): ?DateTime
{
return $this->lastLogin;
}

public function setLastLogin(?DateTimeInterface $lastLogin): self
public function setLastLogin(?DateTime $lastLogin): self
{
$this->lastLogin = $lastLogin;
$this->lastLogin = UnitOfWorkOptimizer::getDateTimeValue($this->lastLogin, $lastLogin);

return $this;
}

public function getPasswordRequestedAt(): ?DateTimeInterface
public function getPasswordRequestedAt(): ?DateTime
{
return $this->passwordRequestedAt;
}

public function setPasswordRequestedAt(?DateTimeInterface $passwordRequestedAt): self
public function setPasswordRequestedAt(?DateTime $passwordRequestedAt): self
{
$this->passwordRequestedAt = $passwordRequestedAt;
$this->passwordRequestedAt = UnitOfWorkOptimizer::getDateTimeValue($this->passwordRequestedAt, $passwordRequestedAt);

return $this;
}
Expand Down
19 changes: 6 additions & 13 deletions src/EntityFactory/EventEntityFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use App\Entity\Place;
use App\Entity\User;
use App\Handler\EntityProviderHandler;
use DateTime;

final readonly class EventEntityFactory implements EntityFactoryInterface
{
Expand Down Expand Up @@ -46,24 +47,16 @@ public function create(?object $entity, object $dto): object
$entity->setExternalId($dto->externalId);
$entity->setExternalOrigin($dto->externalOrigin);

if ($entity->getExternalUpdatedAt()?->format('Y-m-d H:i:s') !== $dto->externalUpdatedAt?->format('Y-m-d H:i:s')) {
$entity->setExternalUpdatedAt($dto->externalUpdatedAt);
}

if ($entity->getStartDate()?->format('Y-m-d H:i:s') !== $dto->startDate?->format('Y-m-d H:i:s')) {
$entity->setStartDate($dto->startDate);
}

if ($entity->getEndDate()?->format('Y-m-d H:i:s') !== $dto->endDate?->format('Y-m-d H:i:s')) {
$entity->setEndDate($dto->endDate);
}
$entity->setExternalUpdatedAt(null === $dto->externalUpdatedAt ? null : DateTime::createFromInterface($dto->externalUpdatedAt));
$entity->setStartDate(null === $dto->startDate ? null : DateTime::createFromInterface($dto->startDate));
$entity->setEndDate(null === $dto->endDate ? null : DateTime::createFromInterface($dto->endDate));

$entity->setAddress($dto->address);
if ($dto->createdAt && $entity->getCreatedAt()?->format('Y-m-d H:i:s') !== $dto->createdAt->format('Y-m-d H:i:s')) {
if ($dto->createdAt) {
$entity->setCreatedAt($dto->createdAt);
}

if ($dto->updatedAt && $entity->getUpdatedAt()?->format('Y-m-d H:i:s') !== $dto->updatedAt->format('Y-m-d H:i:s')) {
if ($dto->updatedAt) {
$entity->setUpdatedAt($dto->updatedAt);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Repository/ResetPasswordRequestRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use App\Entity\ResetPasswordRequest;
use App\Entity\User;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
Expand Down Expand Up @@ -43,6 +44,6 @@ public function createResetPasswordRequest(object $user, DateTimeInterface $expi
throw new RuntimeException('Unable to pass an user instance');
}

return new ResetPasswordRequest($user, $expiresAt, $selector, $hashedToken);
return new ResetPasswordRequest($user, DateTimeImmutable::createFromInterface($expiresAt), $selector, $hashedToken);
}
}
Loading

0 comments on commit fbdbfa1

Please sign in to comment.