Skip to content

Commit 24620be

Browse files
authored
Merge pull request #430 from alcaeus/fix-embedded-document-proxy-generation
Exclude embedded documents from proxy generation
2 parents cc85b5b + 7fdf0b0 commit 24620be

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

CacheWarmer/ProxyCacheWarmer.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
namespace Doctrine\Bundle\MongoDBBundle\CacheWarmer;
1616

1717
use Doctrine\Common\Proxy\AbstractProxyFactory;
18+
use Doctrine\ODM\MongoDB\DocumentManager;
19+
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
1820
use Symfony\Component\DependencyInjection\ContainerInterface;
1921
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
2022

@@ -72,8 +74,20 @@ public function warmUp($cacheDir)
7274
$registry = $this->container->get('doctrine_mongodb');
7375
foreach ($registry->getManagers() as $dm) {
7476
/* @var $dm \Doctrine\ODM\MongoDB\DocumentManager */
75-
$classes = $dm->getMetadataFactory()->getAllMetadata();
77+
$classes = $this->getClassesForProxyGeneration($dm);
7678
$dm->getProxyFactory()->generateProxyClasses($classes);
7779
}
7880
}
81+
82+
/**
83+
* @param DocumentManager $dm
84+
*
85+
* @return ClassMetadata[]
86+
*/
87+
private function getClassesForProxyGeneration(DocumentManager $dm)
88+
{
89+
return array_filter($dm->getMetadataFactory()->getAllMetadata(), function (ClassMetadata $metadata) {
90+
return !$metadata->isEmbeddedDocument && !$metadata->isMappedSuperclass;
91+
});
92+
}
7993
}

Tests/CacheWarmer/ProxyCacheWarmerTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ public function testWarmerNotOptional()
6060

6161
public function testWarmerExecuted()
6262
{
63-
$this->proxyMock->expects($this->once())->method('generateProxyClasses');
63+
$this->proxyMock
64+
->expects($this->once())
65+
->method('generateProxyClasses')
66+
->with($this->countOf(1))
67+
;
6468
$this->warmer->warmUp('meh');
6569
}
6670

@@ -82,4 +86,4 @@ public function provideWarmerNotExecuted()
8286
[ Configuration::AUTOGENERATE_FILE_NOT_EXISTS ],
8387
];
8488
}
85-
}
89+
}

0 commit comments

Comments
 (0)