From ec9f131ba0582c6afc9f0dc61bfafbcff80b97c1 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Thu, 5 Jan 2023 15:40:07 +0100 Subject: [PATCH] Store PersistentCollection changes in entity change set as array The property $entityChangeSets of UnitOfWork stores entity changes as an array of two items for each property changed. Before this change, when an entity with a property holding a Collection was changed, $entityChangeSets stored only the old Collection. --- UPGRADE.md | 6 ++++++ lib/Doctrine/ORM/Event/PreUpdateEventArgs.php | 7 +++---- lib/Doctrine/ORM/UnitOfWork.php | 4 ++-- psalm-baseline.xml | 6 +----- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 8dcf4108a4a..452afb74f46 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -141,6 +141,12 @@ Use one of the dedicated event classes instead: * `Doctrine\ORM\Event\PostRemoveEventArgs` * `Doctrine\ORM\Event\PostLoadEventArgs` +## BC BREAK: Changed entity changeset when a `Collection` is modified + +When working with an entity with a `Collection` property, when that property +is changed, the changeset stored in `UnitOfWork` includes the old and the new +value of this property as an array of two items. + ## BC BREAK: Removed `AttributeDriver::$entityAnnotationClasses` and `AttributeDriver::getReader()` * If you need to change the behavior of `AttributeDriver::isTransient()`, diff --git a/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php b/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php index 090487b8605..235cca9f548 100644 --- a/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php +++ b/lib/Doctrine/ORM/Event/PreUpdateEventArgs.php @@ -5,7 +5,6 @@ namespace Doctrine\ORM\Event; use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\PersistentCollection; use Doctrine\Persistence\Event\LifecycleEventArgs; use InvalidArgumentException; @@ -19,12 +18,12 @@ */ class PreUpdateEventArgs extends LifecycleEventArgs { - /** @var array */ + /** @var array */ private array $entityChangeSet; /** * @param mixed[][] $changeSet - * @psalm-param array $changeSet + * @psalm-param array $changeSet */ public function __construct(object $entity, EntityManagerInterface $em, array &$changeSet) { @@ -37,7 +36,7 @@ public function __construct(object $entity, EntityManagerInterface $em, array &$ * Retrieves entity changeset. * * @return mixed[][] - * @psalm-return array + * @psalm-return array */ public function getEntityChangeSet(): array { diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 4cfcb346224..0b70ec68379 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -514,7 +514,7 @@ private function executeExtraUpdates(): void * Gets the changeset for an entity. * * @return mixed[][] - * @psalm-return array + * @psalm-return array */ public function & getEntityChangeSet(object $entity): array { @@ -715,7 +715,7 @@ public function computeChangeSet(ClassMetadata $class, object $entity): void } $this->collectionDeletions[$coid] = $orgValue; - $changeSet[$propName] = $orgValue; // Signal changeset, to-many assocs will be ignored. + $changeSet[$propName] = [$orgValue, $actualValue]; continue; } diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 488480808f7..589b3d62afb 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1214,11 +1214,7 @@ $collectionToDelete $collectionToUpdate - - entityChangeSets]]> - entityChangeSets]]> - - + $entityState $entityState