From 0c650b4b93ad69a5f54e247ef176c0e4a23560f9 Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Thu, 12 Mar 2020 18:31:10 +0100 Subject: [PATCH 1/2] Fix purging HTTP cache for unreadable relations --- .../EventListener/PurgeHttpCacheListener.php | 4 +++- .../EventListener/PurgeHttpCacheListenerTest.php | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Bridge/Doctrine/EventListener/PurgeHttpCacheListener.php b/src/Bridge/Doctrine/EventListener/PurgeHttpCacheListener.php index 7fb2125179f..1cbcad3d397 100644 --- a/src/Bridge/Doctrine/EventListener/PurgeHttpCacheListener.php +++ b/src/Bridge/Doctrine/EventListener/PurgeHttpCacheListener.php @@ -125,7 +125,9 @@ private function gatherRelationTags(EntityManagerInterface $em, $entity): void { $associationMappings = $em->getClassMetadata(ClassUtils::getClass($entity))->getAssociationMappings(); foreach (array_keys($associationMappings) as $property) { - $this->addTagsFor($this->propertyAccessor->getValue($entity, $property)); + if ($this->propertyAccessor->isReadable($entity, $property)) { + $this->addTagsFor($this->propertyAccessor->getValue($entity, $property)); + } } } diff --git a/tests/Bridge/Doctrine/EventListener/PurgeHttpCacheListenerTest.php b/tests/Bridge/Doctrine/EventListener/PurgeHttpCacheListenerTest.php index 1ac39ad5bd0..6ed5b8501ba 100644 --- a/tests/Bridge/Doctrine/EventListener/PurgeHttpCacheListenerTest.php +++ b/tests/Bridge/Doctrine/EventListener/PurgeHttpCacheListenerTest.php @@ -29,6 +29,7 @@ use Doctrine\ORM\UnitOfWork; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Symfony\Component\PropertyAccess\PropertyAccessorInterface; /** * @author Kévin Dunglas @@ -78,11 +79,22 @@ public function testOnFlush() $emProphecy = $this->prophesize(EntityManagerInterface::class); $emProphecy->getUnitOfWork()->willReturn($uowProphecy->reveal())->shouldBeCalled(); - $emProphecy->getClassMetadata(Dummy::class)->willReturn(new ClassMetadata(Dummy::class))->shouldBeCalled(); + $dummyClassMetadata = new ClassMetadata(Dummy::class); + $dummyClassMetadata->associationMappings = [ + 'relatedDummy' => [], + 'relatedOwningDummy' => [], + ]; + $emProphecy->getClassMetadata(Dummy::class)->willReturn($dummyClassMetadata)->shouldBeCalled(); $emProphecy->getClassMetadata(DummyNoGetOperation::class)->willReturn(new ClassMetadata(DummyNoGetOperation::class))->shouldBeCalled(); $eventArgs = new OnFlushEventArgs($emProphecy->reveal()); - $listener = new PurgeHttpCacheListener($purgerProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal()); + $propertyAccessorProphecy = $this->prophesize(PropertyAccessorInterface::class); + $propertyAccessorProphecy->isReadable(Argument::type(Dummy::class), 'relatedDummy')->willReturn(true); + $propertyAccessorProphecy->isReadable(Argument::type(Dummy::class), 'relatedOwningDummy')->willReturn(false); + $propertyAccessorProphecy->getValue(Argument::type(Dummy::class), 'relatedDummy')->shouldBeCalled(); + $propertyAccessorProphecy->getValue(Argument::type(Dummy::class), 'relatedOwningDummy')->shouldNotBeCalled(); + + $listener = new PurgeHttpCacheListener($purgerProphecy->reveal(), $iriConverterProphecy->reveal(), $resourceClassResolverProphecy->reveal(), $propertyAccessorProphecy->reveal()); $listener->onFlush($eventArgs); $listener->postFlush(); } From 307f0a153f69497ec95318d4187831eb6302db24 Mon Sep 17 00:00:00 2001 From: Alan Poulain Date: Tue, 9 Mar 2021 11:27:05 +0100 Subject: [PATCH 2/2] chore: add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fc4a330b47..73db78de70a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 2.6.4 +* Doctrine: Fix purging HTTP cache for unreadable relations (#3441) * Swagger UI: Remove Google fonts (#4112) ## 2.6.3