Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add effectiveOn with current DateTime in case none was set during cre… #57

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/EventListener/TransactionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -41,7 +46,7 @@ public function preUpdate(PreUpdateEventArgs $args): void

/** @var Transaction $transaction */
$transaction = $args->getObject();

if ($args->hasChangedField('applied')) {
$this->updatedTransactions[] = $transaction;
}
Expand Down