From 7ca37f40fca8f14797a8cc9772f70486788405f6 Mon Sep 17 00:00:00 2001 From: Macavity <300609+Macavity@users.noreply.github.com> Date: Thu, 7 Sep 2023 01:13:04 +0200 Subject: [PATCH] Add effectiveOn with current DateTime in case none was set during creation of a Transaction --- src/EventListener/TransactionListener.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/EventListener/TransactionListener.php b/src/EventListener/TransactionListener.php index 0b176fd..f42922a 100644 --- a/src/EventListener/TransactionListener.php +++ b/src/EventListener/TransactionListener.php @@ -5,6 +5,7 @@ namespace App\EventListener; use App\Entity\Transaction; +use DateTime; use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; use Doctrine\ORM\Event\PrePersistEventArgs; use Doctrine\ORM\Event\PreUpdateEventArgs; @@ -28,6 +29,10 @@ public function prePersist(PrePersistEventArgs $args): void /** @var Transaction $transaction */ $transaction = $args->getObject(); + if (!$transaction->getEffectiveOn()) { + $transaction->setEffectiveOn(new DateTime()); + } + if ($transaction->isApplied()) { $this->updatedTransactions[] = $transaction; } @@ -41,7 +46,7 @@ public function preUpdate(PreUpdateEventArgs $args): void /** @var Transaction $transaction */ $transaction = $args->getObject(); - + if ($args->hasChangedField('applied')) { $this->updatedTransactions[] = $transaction; }