ソースを参照

[tree][closure] fixed a bug with mem cache like apc, did not saved mapping info, closes #58

gediminasm 14 年 前
コミット
56e4f69f5a

+ 4 - 0
lib/Gedmo/Tree/Strategy/ORM/Closure.php

@@ -61,6 +61,7 @@ class Closure implements Strategy
     {
         $config = $this->listener->getConfiguration($em, $meta->name);
         $closureMetadata = $em->getClassMetadata($config['closure']);
+
         if (!$closureMetadata->hasAssociation('ancestor')) {
             // create ancestor mapping
             $ancestorMapping = array(
@@ -118,6 +119,9 @@ class Closure implements Strategy
         $closureMetadata->table['indexes'][$indexName] = array(
             'columns' => array('depth')
         );
+        if ($cacheDriver = $em->getMetadataFactory()->getCacheDriver()) {
+            $cacheDriver->save($closureMetadata->name."\$CLASSMETADATA", $closureMetadata, null);
+        }
     }
 
     /**

+ 16 - 1
tests/Gedmo/Mapping/TreeMappingTest.php

@@ -25,7 +25,7 @@ class TreeMappingTest extends \PHPUnit_Framework_TestCase
     public function setUp()
     {
         $config = new \Doctrine\ORM\Configuration();
-        $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
+        $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ApcCache);
         $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
         $config->setProxyDir(TESTS_TEMP_DIR);
         $config->setProxyNamespace('Gedmo\Mapping\Proxy');
@@ -54,6 +54,21 @@ class TreeMappingTest extends \PHPUnit_Framework_TestCase
         $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
     }
 
+    public function testApcCached()
+    {
+        if (!extension_loaded('apc') || !ini_get('apc.enable_cli')) {
+            $this->markTestSkipped('APC extension is not loaded.');
+        }
+        $meta = $this->em->getClassMetadata(self::YAML_CLOSURE_CATEGORY);
+        $this->em->getClassMetadata('Tree\Fixture\Closure\CategoryClosure');
+
+        $meta = $this->em->getMetadataFactory()->getCacheDriver()->fetch(
+            "Tree\\Fixture\\Closure\\CategoryClosure\$CLASSMETADATA"
+        );
+        $this->assertTrue($meta->hasAssociation('ancestor'));
+        $this->assertTrue($meta->hasAssociation('descendant'));
+    }
+
     public function testYamlNestedMapping()
     {
         $meta = $this->em->getClassMetadata(self::TEST_YAML_ENTITY_CLASS);