Release 2.23.0 (#5075)

This commit is contained in:
Kevin Papst
2024-10-03 10:34:20 +02:00
committed by GitHub
parent 40154be8f9
commit fb9a0dc499
142 changed files with 855 additions and 910 deletions

View 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;
}

View 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;
}
}

View File

@@ -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;
}

View 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;
}
}

View File

@@ -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);
}
}
}
}