public static function cleanDatabase($em) { $tool = new \Doctrine\ORM\Tools\SchemaTool($em); $classes = array($em->getClassMetadata('Poc\\PocPlugins\\Tagging\\Driver\\Doctrine2\\Entities\\Cache'), $em->getClassMetadata('Poc\\PocPlugins\\Tagging\\Driver\\Doctrine2\\Entities\\CacheTag'), $em->getClassMetadata('Poc\\PocPlugins\\Tagging\\Driver\\Doctrine2\\Entities\\Tag')); $tool->dropDatabase(); $tool->createSchema($classes); }
public function resetDatabase() { $metadatas = $this->em->getMetadataFactory()->getAllMetadata(); $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $tool->dropDatabase(); $tool->createSchema($metadatas); }
public function tearDown() { $this->doctrineContainer->getConnection()->close(); $em = $this->doctrineContainer->getEntityManager(); $tool = new \Doctrine\ORM\Tools\SchemaTool($em); $tool->dropDatabase(); parent::tearDown(); }
public function processAction() { $em = $this->getComponent('entityManager'); $tool = new \Doctrine\ORM\Tools\SchemaTool($em); $classes = array($em->getClassMetadata('application\\modules\\user\\models\\User'), $em->getClassMetadata('application\\modules\\comment\\models\\Comment'), $em->getClassMetadata('application\\modules\\proposal\\models\\Proposal'), $em->getClassMetadata('application\\modules\\userrequest\\models\\UserRequest'), $em->getClassMetadata('application\\modules\\category\\models\\Category'), $em->getClassMetadata('application\\modules\\vote\\models\\ProposalVote'), $em->getClassMetadata('application\\modules\\vote\\models\\CommentVote')); $tool->dropDatabase(); $tool->createSchema($classes); $this->createRequest('database', 'fill')->execute(); }
protected final function importDatabaseSchema() { $em = self::$kernel->getContainer()->get('doctrine.orm.entity_manager'); $metadata = $em->getMetadataFactory()->getAllMetadata(); if (!empty($metadata)) { $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em); $schemaTool->dropDatabase(); $schemaTool->createSchema($metadata); } }
public function generateSchema() { $metadatas = $this->em->getMetadataFactory()->getAllMetadata(); if (!empty($metadatas)) { $tool = new \Doctrine\ORM\Tools\SchemaTool($this->om); $tool->dropDatabase(); $tool->dropSchema($metadatas); $tool->createSchema($metadatas); } }
protected final function importDatabaseSchema() { $em = $this->getEntityManager(); $metadata = $em->getMetadataFactory()->getAllMetadata(); if (!empty($metadata)) { $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em); $schemaTool->dropDatabase(); $schemaTool->createSchema($metadata); } }
public static function init() { $zf2ModulePaths = [dirname(dirname(__DIR__))]; if ($path = static::findParentPath('vendor')) { $zf2ModulePaths[] = $path; } if ($path = static::findParentPath('module')) { $zf2ModulePaths[] = $path; } if (($path = static::findParentPath('src')) !== $zf2ModulePaths[0]) { $zf2ModulePaths[] = $path; } static::initAutoloader(); $config = (include __DIR__ . '/../config/application.config.php'); $serviceManager = new ServiceManager(new ServiceManagerConfig()); $serviceManager->setService('ApplicationConfig', $config); $serviceManager->get('ModuleManager')->loadModules(); static::$serviceManager = $serviceManager; if (defined("TEST_SUITE") && constant("TEST_SUITE") == 'full') { $entityManager = $serviceManager->get('doctrine.entitymanager.orm_default'); //Validate the schema; $validator = new \Doctrine\ORM\Tools\SchemaValidator($entityManager); $errors = $validator->validateMapping(); if (count($errors) > 0) { foreach ($errors as $entity => $errors) { echo "Error in Entity: '" . $entity . "':\n"; echo implode("\n", $errors); echo "\n"; } die; } //Create the schema $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager); $mdFactory = $entityManager->getMetadataFactory(); $mdFactory->getAllMetadata(); $tool->dropDatabase(); $tool->createSchema($mdFactory->getAllMetadata()); $loader = new Loader(); $loader->addFixture(new \ProjectTest\Fixture\LoadVersionData()); $loader->addFixture(new \ContactTest\Fixture\LoadContactData()); $loader->addFixture(new \ProjectTest\Fixture\LoadProjectLogoData()); $loader->addFixture(new \ProjectTest\Fixture\LoadDocumentData()); $loader->addFixture(new \ProjectTest\Fixture\LoadFundingStatusData()); $loader->addFixture(new \ProjectTest\Fixture\LoadIdeaDocumentData()); $loader->addFixture(new \ProjectTest\Fixture\LoadIdeaImageData()); $loader->addFixture(new \ProjectTest\Fixture\LoadIdeaDescriptionData()); $loader->addFixture(new \ProjectTest\Fixture\LoadInviteData()); $loader->addFixture(new \ProjectTest\Fixture\LoadProjectRationaleData()); $loader->addFixture(new \GeneralTest\Fixture\LoadWebInfoData()); $loader->addFixture(new \OrganisationTest\Fixture\LoadOrganisationData()); $purger = new ORMPurger(); $executor = new ORMExecutor($entityManager, $purger); $executor->execute($loader->getFixtures()); } }
public static function createTables(EntityManager $entityManager) { $tables = $entityManager->getConnection()->getSchemaManager()->listTables(); if (count($tables) == 0) { $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($entityManager); $cmf = $entityManager->getMetadataFactory(); $classes = $cmf->getAllMetadata(); $schemaTool->dropDatabase(); $schemaTool->createSchema($classes); } }
public function installDatabase() { $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->entityManager); $entityClasses = $this->getEntities(); $classes = array(); foreach ($entityClasses as $entityClass) { $classes[] = $this->entityManager->getClassMetadata($entityClass); } $schemaTool->dropDatabase(); $schemaTool->createSchema($classes); $this->activateTatami(); $this->installUserRoles(); return $this; }
public static function init() { $zf2ModulePaths = [dirname(dirname(__DIR__))]; if ($path = static::findParentPath('vendor')) { $zf2ModulePaths[] = $path; } if ($path = static::findParentPath('module')) { $zf2ModulePaths[] = $path; } if (($path = static::findParentPath('src')) !== $zf2ModulePaths[0]) { $zf2ModulePaths[] = $path; } static::initAutoloader(); $config = (include __DIR__ . '/../config/application.config.php'); $serviceManager = new ServiceManager(new ServiceManagerConfig()); $serviceManager->setService('ApplicationConfig', $config); $serviceManager->get('ModuleManager')->loadModules(); static::$serviceManager = $serviceManager; $entityManager = $serviceManager->get('Doctrine\\ORM\\EntityManager'); // //Validate the schema; // $validator = new SchemaValidator($entityManager); // $errors = $validator->validateMapping(); // // if (count($errors) > 0) { // foreach ($errors AS $entity => $errors) { // echo "Error in Entity: '" . $entity . "':\n"; // echo implode("\n", $errors); // echo "\n"; // } // die(); // } //Create the schema $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager); $mdFactory = $entityManager->getMetadataFactory(); $mdFactory->getAllMetadata(); $tool->dropDatabase(); $tool->createSchema($mdFactory->getAllMetadata()); // $loader = new Loader(); // $loader->addFixture(new \ProjectTest\Fixture\LoadVersionData()); // $loader->addFixture(new \ProgramTest\Fixture\LoadDomainData()); // $loader->addFixture(new \GeneralTest\Fixture\LoadContentTypeData()); // $loader->addFixture(new \ProjectTest\Fixture\LoadProjectLogoData()); // $loader->addFixture(new \ProjectTest\Fixture\LoadDocumentTypeData()); // // $purger = new ORMPurger(); // $executor = new ORMExecutor($entityManager, $purger); // $executor->execute($loader->getFixtures()); }
public function createDatabase() { $em = $this->doctrineContainer->getEntityManager(); $tool = new \Doctrine\ORM\Tools\SchemaTool($em); $tool->dropDatabase(); $tool->createSchema($em->getMetadataFactory()->getAllMetadata()); $usuario = new \Application\Entity\Usuario(); $usuario->setNome('admin'); $usuario->setEnergia(100); $usuario->setEnergiaMaxima(100); $usuario->setEmail('*****@*****.**'); $usuario->setSenha('123'); $em->persist($usuario); $em->flush(); self::$created = true; }
public static function init() { $zf2ModulePaths = array(dirname(dirname(__DIR__))); if ($path = static::findParentPath('vendor')) { $zf2ModulePaths[] = $path; } if ($path = static::findParentPath('module')) { $zf2ModulePaths[] = $path; } if (($path = static::findParentPath('src')) !== $zf2ModulePaths[0]) { $zf2ModulePaths[] = $path; } static::initAutoloader(); $config = (include __DIR__ . '/../config/application.config.php'); $serviceManager = new ServiceManager(new ServiceManagerConfig()); $serviceManager->setService('ApplicationConfig', $config); $serviceManager->get('ModuleManager')->loadModules(); static::$serviceManager = $serviceManager; if (defined("TEST_SUITE") && constant("TEST_SUITE") == 'full') { $entityManager = $serviceManager->get('Doctrine\\ORM\\EntityManager'); //Validate the schema; $validator = new SchemaValidator($entityManager); $errors = $validator->validateMapping(); if (count($errors) > 0) { foreach ($errors as $entity => $errors) { echo "Error in Entity: '" . $entity . "':\n"; echo implode("\n", $errors); echo "\n"; } die; } //Create the schema $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager); $mdFactory = $entityManager->getMetadataFactory(); $mdFactory->getAllMetadata(); $tool->dropDatabase(); $tool->createSchema($mdFactory->getAllMetadata()); $loader = new Loader(); $loader->addFixture(new \AdminTest\Fixture\LoadAccessData()); $purger = new ORMPurger(); $executor = new ORMExecutor($entityManager, $purger); $executor->execute($loader->getFixtures()); } }
protected function setUp() { parent::setUp(); // Build an Entity Manager $pdo = new \PDO($_ENV['Doctrine_Store_SQLite_DSN'], null, null, array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION)); $dbal_driver = new \Doctrine\DBAL\Driver\PDOSqlite\Driver(); $conn = new \Doctrine\DBAL\Connection(array('pdo' => $pdo), $dbal_driver); $orm_config = new \Doctrine\ORM\Configuration(); $orm_config->setAutoGenerateProxyClasses(true); $orm_config->setMetadataDriverImpl($orm_config->newDefaultAnnotationDriver(__DIR__ . '/TestEntity/Doctrine')); $orm_config->setProxyDir($_ENV['Doctrine_Store_Proxy_Root_Directory']); $orm_config->setProxyNamespace('DerpTest\\Machinist\\Store\\TestEntity\\Doctrine\\proxy'); $this->em = \Doctrine\ORM\EntityManager::create($conn, $orm_config, null); // Build the schema for testing $schema_tool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $metadatas = $this->em->getMetadataFactory()->getAllMetadata(); $schema_tool->dropDatabase(); $schema_tool->createSchema($metadatas); $this->driver = new Doctrine($this->em, array('DerpTest\\Machinist\\Store\\TestEntity\\Doctrine')); }
/** * Initializes a bootstrapped PartKeepr environment. * * This is done within a function because we don't want to pollute the globals, which would give the following message * during unit tests: * * "PDOException: You cannot serialize or unserialize PDO instances" */ function initializeEnvironment() { PartKeepr::initialize("test"); $tool = new \Doctrine\ORM\Tools\SchemaTool(PartKeepr::getEM()); $classes = PartKeepr::getClassMetaData(); $tool->dropDatabase(); $tool->createSchema($classes); /* Some very basic installation things */ PartCategoryManager::getInstance()->ensureRootExists(); /* Create a blank admin user */ $user = new User(); $user->setUsername("admin"); $user->setPassword("admin"); $user->setAdmin(true); PartKeepr::getEM()->persist($user); /* Create a blank regular user */ $user2 = new User(); $user2->setUsername("regular"); $user2->setPassword("regular"); $user2->setAdmin(false); PartKeepr::getEM()->persist($user2); PartKeepr::getEM()->flush(); }
/** * Setup the temporary database with data from the real one * @param \Doctrine\ORM\EntityManager $em */ protected function buildTemporaryDatabase(\Doctrine\ORM\EntityManager $em) { $classes = $this->_em->getMetadataFactory()->getAllMetadata(); $tool = new \Doctrine\ORM\Tools\SchemaTool($em); $tool->dropDatabase(); $tool->createSchema($classes); foreach ($this->_em->getRepository('\\Jazzee\\Entity\\PageType')->findAll() as $type) { $newType = new \Jazzee\Entity\PageType(); $newType->setClass($type->getClass()); $newType->setName($type->getName()); $em->persist($newType); } foreach ($this->_em->getRepository('\\Jazzee\\Entity\\ElementType')->findAll() as $type) { $newType = new \Jazzee\Entity\ElementType(); $newType->setClass($type->getClass()); $newType->setName($type->getName()); $em->persist($newType); } foreach ($this->_em->getRepository('\\Jazzee\\Entity\\PaymentType')->findAll() as $type) { $newType = new \Jazzee\Entity\PaymentType(); $newType->setClass($type->getClass()); $newType->setName($type->getName()); if ($type->isExpired()) { $newType->expire(); } foreach ($type->getVariables() as $var) { $newVar = new Jazzee\Entity\PaymentTypeVariable(); $newVar->setName($var->getName()); $newVar->setValue($var->getValue()); $newVar->setType($newType); $em->persist($newVar); } $em->persist($newType); } $em->flush(); $em->clear(); $count = 0; foreach ($this->_em->getRepository('\\Jazzee\\Entity\\School')->findAllArray() as $arr) { $newSchool = new \Jazzee\Entity\School(); $newSchool->setCity($arr['city']); $newSchool->setCode($arr['code']); $newSchool->setCountry($arr['country']); $newSchool->setName($arr['name']); $newSchool->setPostalCode($arr['postalCode']); $newSchool->setSearchTerms($arr['searchTerms']); $newSchool->setState($arr['state']); $em->persist($newSchool); $count++; if ($count > 1000) { $count = 0; $em->flush(); $em->clear(); } } $em->flush(); }
protected function setup() { $client = static::createClient(); $container = $client->getContainer(); $em = $container->get('doctrine')->getEntityManager(); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em); $schemaTool->dropDatabase(); $metadata = $em->getMetadataFactory()->getAllMetadata(); if (!empty($metadata)) { $schemaTool->createSchema($metadata); } }
/** * Called after a functional test in Flow, dumps everything in the database. * * @return void */ public function tearDown() { // "driver" is used only for Doctrine, thus we (mis-)use it here // additionally, when no path is set, skip this step, assuming no DB is needed if ($this->settings['backendOptions']['driver'] !== null && $this->settings['backendOptions']['path'] !== null) { $this->entityManager->clear(); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->entityManager); $schemaTool->dropDatabase(); $this->systemLogger->log('Doctrine 2 schema destroyed.', LOG_NOTICE); } else { $this->systemLogger->log('Doctrine 2 destroy skipped, driver and path backend options not set!', LOG_NOTICE); } }
} echo "Performing actions...\n"; @mkdir("../src/Proxies"); @mkdir("../data"); @mkdir("../data/images"); chmod("../data/images", 0777); chmod("../data/files", 0777); $tool = new \Doctrine\ORM\Tools\SchemaTool(PartKeepr::getEM()); $classes = PartKeepr::getClassMetaData(); $tool->dropDatabase($classes); $tool->createSchema($classes); /* Create initial test user */ $user = new User(); $user->setUsername("test"); $user->setPassword("test"); $user->setAdmin(true); PartKeepr::getEM()->persist($user); /* Create footprints */ $newFootprints = array(); $newCategories = array(); mysql_connect("localhost", "partdb", "partdb");
/** * @AfterScenario * @param AfterScenarioScope $scope */ public function dropSchema(AfterScenarioScope $scope) { $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->entityManager); $schemaTool->dropDatabase(); }
<?php /** * Created by PhpStorm. * User: turin * Date: 24.01.16 * Time: 01:20 */ require __DIR__ . '/autoload.php'; $kernel = new AppKernel('test', true); // create a "test" kernel $kernel->boot(); $container = $kernel->getContainer(); $em = $container->get('doctrine')->getManager(); $metadata = $em->getMetadataFactory()->getAllMetadata(); if (!empty($metadata)) { // Create SchemaTool $tool = new \Doctrine\ORM\Tools\SchemaTool($em); $tool->dropDatabase(); $tool->createSchema($metadata); } else { throw new \Doctrine\DBAL\Schema\SchemaException('No Metadata Classes to process.'); }
/** * Drop the current database and start again. */ public function rebuild() { $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->entityManager); $metadatas = $this->entityManager->getMetadataFactory()->getAllMetadata(); $schemaTool->dropDatabase(); $this->log('Creating database schema...'); $schemaTool->createSchema($metadatas); $this->log('Database schema created successfully!'); }
public static function testTearDown() { $entityManager = SurveyEntityManager::getEntityManager(true, true); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($entityManager); $schemaTool->dropDatabase(); //Ensure we do not leak across tests. SurveyEntityManager::$entityManager = null; }
* This source file is subject to the MIT license that is bundled with this package in the file LICENCE.md. */ if (cli\choose("Are you sure", 'yn', 'n') == 'n') { exit; } require_once $cmds['cache-clear']->name(); $schema = new \Doctrine\ORM\Tools\SchemaTool($app->em->value()); cli\line('Deleting existing files..'); if ($app->config->dataDir->exists()) { $app->config->dataDir->remove(true); } if ($app->config->publicDataDir->exists()) { $app->config->publicDataDir->remove(true); } cli\line('Dropping existing database..'); $schema->dropDatabase(); $app->em->beginTransaction(); try { cli\line('Creating schema..'); $schema->createSchema($app->em->getMetadataFactory()->getAllMetadata()); cli\line('Creating default user..'); $user = new \Chalk\Core\User(); $user->fromArray(['name' => 'Root', 'emailAddress' => '*****@*****.**', 'passwordPlain' => 'password', 'role' => \Chalk\Core\User::ROLE_DEVELOPER]); $app->em->persist($user); $app->em->flush(); cli\line('Creating default page..'); $page = new \Chalk\Core\Page(); $page->fromArray(['name' => 'Site']); $app->em->persist($page); $app->em->flush(); cli\line('Creating default structures..');