Example #1
0
 /**
  * Load entity configs from annotations to a database
  *
  * @param bool                 $force  Force overwrite config's option values
  * @param callable|null        $filter function (ClassMetadata[] $doctrineAllMetadata)
  * @param LoggerInterface|null $logger
  * @param bool                 $dryRun Log modifications without apply them
  *
  * @throws \Exception
  */
 public function load($force = false, \Closure $filter = null, LoggerInterface $logger = null, $dryRun = false)
 {
     $this->logger = $logger ?: new NullLogger();
     try {
         $entityManagers = $this->entityManagerBag->getEntityManagers();
         foreach ($entityManagers as $em) {
             /** @var ClassMetadata[] $doctrineAllMetadata */
             $doctrineAllMetadata = $em->getMetadataFactory()->getAllMetadata();
             if (null !== $filter) {
                 $doctrineAllMetadata = $filter($doctrineAllMetadata);
             }
             foreach ($doctrineAllMetadata as $metadata) {
                 $this->loadEntityConfigs($metadata, $force);
             }
         }
         if ($dryRun) {
             $this->configManager->clear();
         } else {
             $this->configManager->flush();
             $this->configManager->flushAllCaches();
         }
     } catch (\Exception $ex) {
         $this->logger = null;
         throw $ex;
     }
 }
 public function testGetEntityManagers()
 {
     $defaultEm = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $anotherEm = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->doctrine->expects($this->at(0))->method('getManager')->with(null)->willReturn($defaultEm);
     $this->doctrine->expects($this->at(1))->method('getManager')->with('another')->willReturn($anotherEm);
     $this->entityManagerBag->addEntityManager('another');
     $result = $this->entityManagerBag->getEntityManagers();
     $this->assertCount(2, $result);
     $this->assertSame($defaultEm, $result[0]);
     $this->assertSame($anotherEm, $result[1]);
 }
Example #3
0
 protected function loadNonConfigurable()
 {
     $cached = $this->cache->getEntities();
     $entityManagers = $this->entityManagerBag->getEntityManagers();
     foreach ($entityManagers as $em) {
         /** @var ClassMetadata[] $allMetadata */
         $allMetadata = $em->getMetadataFactory()->getAllMetadata();
         foreach ($allMetadata as $metadata) {
             if ($metadata->isMappedSuperclass) {
                 continue;
             }
             $className = $metadata->getName();
             if (!isset($cached[$className])) {
                 $fieldFlags = [];
                 $fieldNames = $metadata->getFieldNames();
                 foreach ($fieldNames as $fieldName) {
                     $fieldFlags[$fieldName] = false;
                 }
                 $fieldNames = $metadata->getAssociationNames();
                 foreach ($fieldNames as $fieldName) {
                     $fieldFlags[$fieldName] = false;
                 }
                 $this->cache->saveConfigurableValues($className, false, $fieldFlags);
             }
         }
     }
 }
 /**
  * @return string[]
  */
 protected function getSupportedEntityClasses()
 {
     $entities = [];
     $entityManagers = $this->entityManagerBag->getEntityManagers();
     foreach ($entityManagers as $em) {
         $allMetadata = SafeDatabaseChecker::getAllMetadata($em);
         foreach ($allMetadata as $metadata) {
             if ($metadata->isMappedSuperclass) {
                 continue;
             }
             if ($this->entityExclusionProvider->isIgnoredEntity($metadata->name)) {
                 continue;
             }
             $entities[] = $metadata->name;
         }
     }
     return $entities;
 }
 /**
  * @return string[]
  */
 protected function getSupportedEntityClasses()
 {
     $entities = [];
     $entityManagers = $this->entityManagerBag->getEntityManagers();
     foreach ($entityManagers as $em) {
         /** @var ClassMetadata[] $allMetadata */
         $allMetadata = $em->getMetadataFactory()->getAllMetadata();
         foreach ($allMetadata as $metadata) {
             if ($metadata->isMappedSuperclass) {
                 continue;
             }
             if ($this->entityExclusionProvider->isIgnoredEntity($metadata->name)) {
                 continue;
             }
             $entities[] = $metadata->name;
         }
     }
     return $entities;
 }
 /**
  * {@inheritdoc}
  */
 protected function initializeHierarchy()
 {
     $entityManagers = $this->entityManagerBag->getEntityManagers();
     foreach ($entityManagers as $em) {
         /** @var ClassMetadata[] $allMetadata */
         $allMetadata = $em->getMetadataFactory()->getAllMetadata();
         foreach ($allMetadata as $metadata) {
             if ($metadata->isMappedSuperclass) {
                 continue;
             }
             if ($this->extendConfigProvider->hasConfig($metadata->name) && !ExtendHelper::isEntityAccessible($this->extendConfigProvider->getConfig($metadata->name))) {
                 continue;
             }
             $parents = $this->loadParents($metadata->name);
             if (!empty($parents)) {
                 $this->hierarchy[$metadata->name] = $parents;
             }
         }
     }
 }
Example #7
0
 /**
  * Removes the entity proxies and metadata from the cache
  *
  * @param bool $keepEntityProxies Set TRUE if proxies for custom and extend entities should not be deleted
  */
 public function clear($keepEntityProxies = false)
 {
     $filesystem = new Filesystem();
     if ($keepEntityProxies) {
         $aliasesPath = ExtendClassLoadingUtils::getAliasesPath($this->cacheDir);
         if ($filesystem->exists($aliasesPath)) {
             $filesystem->remove($aliasesPath);
         }
     } else {
         $baseCacheDir = ExtendClassLoadingUtils::getEntityBaseCacheDir($this->cacheDir);
         if ($filesystem->exists($baseCacheDir)) {
             $filesystem->remove([$baseCacheDir]);
         }
         $filesystem->mkdir(ExtendClassLoadingUtils::getEntityCacheDir($this->cacheDir));
     }
     foreach ($this->entityManagerBag->getEntityManagers() as $em) {
         /** @var ClassMetadataFactory $metadataFactory */
         $metadataFactory = $em->getMetadataFactory();
         $metadataCache = $metadataFactory->getCacheDriver();
         if ($metadataCache instanceof ClearableCache) {
             $metadataCache->deleteAll();
         }
     }
 }
 /**
  * Generate doctrine proxy classes for extended entities
  */
 public function generateProxies()
 {
     foreach ($this->entityManagerBag->getEntityManagers() as $em) {
         $this->generateEntityManagerProxies($em);
     }
 }