Release 2.23.0 (#5075)
This commit is contained in:
20
src/Doctrine/Behavior/CreatedAt.php
Normal file
20
src/Doctrine/Behavior/CreatedAt.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Doctrine\Behavior;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface CreatedAt
|
||||
{
|
||||
public function getCreatedAt(): ?\DateTimeImmutable;
|
||||
|
||||
public function setCreatedAt(\DateTimeImmutable $dateTime): void;
|
||||
}
|
||||
28
src/Doctrine/Behavior/CreatedTrait.php
Normal file
28
src/Doctrine/Behavior/CreatedTrait.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Doctrine\Behavior;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
trait CreatedTrait
|
||||
{
|
||||
#[ORM\Column(name: 'created_at', type: 'datetime_immutable', nullable: true)]
|
||||
private ?\DateTimeImmutable $createdAt = null;
|
||||
|
||||
public function getCreatedAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function setCreatedAt(\DateTimeImmutable $dateTime): void
|
||||
{
|
||||
$this->createdAt = $dateTime;
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,11 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Doctrine;
|
||||
namespace App\Doctrine\Behavior;
|
||||
|
||||
interface ModifiedAt
|
||||
{
|
||||
public function getModifiedAt(): ?\DateTimeImmutable;
|
||||
|
||||
public function setModifiedAt(\DateTimeImmutable $dateTime): void;
|
||||
}
|
||||
28
src/Doctrine/Behavior/ModifiedTrait.php
Normal file
28
src/Doctrine/Behavior/ModifiedTrait.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Doctrine\Behavior;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
trait ModifiedTrait
|
||||
{
|
||||
#[ORM\Column(name: 'modified_at', type: 'datetime_immutable', nullable: true)]
|
||||
private ?\DateTimeImmutable $modifiedAt = null;
|
||||
|
||||
public function getModifiedAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->modifiedAt;
|
||||
}
|
||||
|
||||
public function setModifiedAt(\DateTimeImmutable $dateTime): void
|
||||
{
|
||||
$this->modifiedAt = $dateTime;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
namespace App\Doctrine;
|
||||
|
||||
use App\Doctrine\Behavior\CreatedAt;
|
||||
use App\Doctrine\Behavior\ModifiedAt;
|
||||
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
|
||||
use Doctrine\Common\EventSubscriber;
|
||||
use Doctrine\ORM\Event\OnFlushEventArgs;
|
||||
@@ -36,12 +38,18 @@ final class ModifiedSubscriber implements EventSubscriber, DataSubscriberInterfa
|
||||
if ($entity instanceof ModifiedAt) {
|
||||
$entity->setModifiedAt($now);
|
||||
}
|
||||
if ($entity instanceof CreatedAt && $entity->getCreatedAt() === null) {
|
||||
$entity->setCreatedAt($now);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($uow->getScheduledEntityInsertions() as $entity) {
|
||||
if ($entity instanceof ModifiedAt) {
|
||||
$entity->setModifiedAt($now);
|
||||
}
|
||||
if ($entity instanceof CreatedAt && $entity->getCreatedAt() === null) {
|
||||
$entity->setCreatedAt($now);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user