Ejemplo n.º 1
0
 /**
  * Reset partially or completely the database.
  *
  * @param  array|null $entityMetadata The array that contains only metadata of entities we want to create
  * @param  boolean    $hardReset      This option force hard reset of the entire database
  * @return self
  */
 public function resetDatabase(array $entityMetadata = null, $hardReset = false)
 {
     $schemaTool = new SchemaTool($this->getEntityManager());
     if (null === $entityMetadata || true === $hardReset) {
         $schemaTool->dropDatabase();
     } else {
         $schemaTool->dropSchema($entityMetadata);
     }
     if (null === $entityMetadata) {
         $entityFinder = new EntityFinder($this->getApplication()->getBBDir());
         $metadataDriver = $this->getEntityManager()->getConfiguration()->getMetadataDriverImpl();
         foreach ($this->getEntityPaths() as $path) {
             $metadataDriver->addPaths([$path]);
             $metadataDriver->addExcludePaths($entityFinder->getExcludePaths($path));
         }
         $entityMetadata = $metadata = $this->getEntityManager()->getMetadataFactory()->getAllMetadata();
         $this->getEntityManager()->getClassMetadata('BackBee\\ClassContent\\AbstractClassContent')->addDiscriminatorMapClass('BackBee\\ClassContent\\Tests\\Mock\\MockContent', 'BackBee\\ClassContent\\Tests\\Mock\\MockContent');
     }
     $schemaTool->createSchema($entityMetadata);
     return $this;
 }
Ejemplo n.º 2
0
 public function initDb($bbapp)
 {
     $em = $bbapp->getContainer()->get('em');
     $em->getConnection()->getConfiguration()->setSQLLogger(null);
     $entityFinder = new EntityFinder($bbapp->getBBDir());
     $paths = [$bbapp->getBBDir() . '/Bundle', $bbapp->getBBDir() . '/Cache/DAO', $bbapp->getBBDir() . '/ClassContent', $bbapp->getBBDir() . '/ClassContent/Indexes', $bbapp->getBBDir() . '/Logging', $bbapp->getBBDir() . '/NestedNode', $bbapp->getBBDir() . '/Security', $bbapp->getBBDir() . '/Site', $bbapp->getBBDir() . '/Stream/ClassWrapper', $bbapp->getBBDir() . '/Util/Sequence/Entity', $bbapp->getBBDir() . '/Workflow'];
     foreach ($paths as $path) {
         $em->getConfiguration()->getMetadataDriverImpl()->addPaths([$path]);
         $em->getConfiguration()->getMetadataDriverImpl()->addExcludePaths($entityFinder->getExcludePaths($path));
     }
     $metadata = $em->getMetadataFactory()->getAllMetadata();
     $schema = new SchemaTool($em);
     $schema->dropDatabase();
     $schema->createSchema($metadata);
 }