当前位置: 首页>>代码示例>>PHP>>正文


PHP Tools\SchemaTool类代码示例

本文整理汇总了PHP中Doctrine\ORM\Tools\SchemaTool的典型用法代码示例。如果您正苦于以下问题:PHP SchemaTool类的具体用法?PHP SchemaTool怎么用?PHP SchemaTool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SchemaTool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: adminRefreshDatabaseAction

 public function adminRefreshDatabaseAction(Request $request, Application $app)
 {
     $conn = $app['db'];
     $em = $app['doctrine.orm.entity_manager'];
     $params = $conn->getParams();
     $name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false);
     try {
         $conn->getSchemaManager()->dropDatabase($name);
         $conn->getSchemaManager()->createDatabase($name);
         $conn->close();
     } catch (\Exception $e) {
         return 1;
     }
     $classes = [];
     foreach ($app['authbucket_oauth2.model'] as $class) {
         $classes[] = $em->getClassMetadata($class);
     }
     PersistentObject::setObjectManager($em);
     $tool = new SchemaTool($em);
     $tool->dropSchema($classes);
     $tool->createSchema($classes);
     $purger = new ORMPurger();
     $executor = new ORMExecutor($em, $purger);
     $loader = new Loader();
     $loader->loadFromDirectory(__DIR__ . '/../DataFixtures/ORM');
     $executor->execute($loader->getFixtures());
     return $app->redirect($app['url_generator']->generate('index'));
 }
开发者ID:miguelbemartin,项目名称:oauth2-php,代码行数:28,代码来源:DefaultController.php

示例2: setUp

    protected function setUp()
    {
        if (!class_exists('Doctrine\\Common\\Version')) {
            $this->markTestSkipped('Doctrine is not available.');
        }

        $this->em = DoctrineOrmTestCase::createTestEntityManager();

        parent::setUp();

        $schemaTool = new SchemaTool($this->em);
        $classes = array(
            $this->em->getClassMetadata(self::SINGLE_IDENT_CLASS),
            $this->em->getClassMetadata(self::SINGLE_STRING_IDENT_CLASS),
            $this->em->getClassMetadata(self::COMPOSITE_IDENT_CLASS),
            $this->em->getClassMetadata(self::COMPOSITE_STRING_IDENT_CLASS),
        );

        try {
            $schemaTool->dropSchema($classes);
        } catch(\Exception $e) {
        }

        try {
            $schemaTool->createSchema($classes);
        } catch(\Exception $e) {
        }
    }
开发者ID:naknak,项目名称:symfony,代码行数:28,代码来源:EntityTypeTest.php

示例3: setUp

 public function setUp()
 {
     $this->_oldEntityManager = \SoliantEntityAudit\Module::getModuleOptions()->getEntityManager();
     $this->_oldAuditedClassNames = \SoliantEntityAudit\Module::getModuleOptions()->getAuditedClassNames();
     $this->_oldJoinClasses = \SoliantEntityAudit\Module::getModuleOptions()->resetJoinClasses();
     $isDevMode = false;
     $config = Setup::createConfiguration($isDevMode, null, null);
     $chain = new DriverChain();
     // Use ZFC User for authentication tests
     $chain->addDriver(new XmlDriver(__DIR__ . '/../../../vendor/zf-commons/zfc-user-doctrine-orm/config/xml/zfcuser'), 'ZfcUser\\Entity');
     $chain->addDriver(new XmlDriver(__DIR__ . '/../../../vendor/zf-commons/zfc-user-doctrine-orm/config/xml/zfcuserdoctrineorm'), 'ZfcUserDoctrineORM\\Entity');
     $chain->addDriver(new StaticPHPDriver(__DIR__ . "/../Models"), 'SoliantEntityAuditTest\\Models\\LogRevision');
     $chain->addDriver(new AuditDriver('.'), 'SoliantEntityAudit\\Entity');
     $config->setMetadataDriverImpl($chain);
     // Replace entity manager
     $moduleOptions = \SoliantEntityAudit\Module::getModuleOptions();
     $conn = array('driver' => 'pdo_sqlite', 'memory' => true);
     $moduleOptions->setAuditedClassNames(array('SoliantEntityAuditTest\\Models\\LogRevision\\Album' => array(), 'SoliantEntityAuditTest\\Models\\LogRevision\\Performer' => array(), 'SoliantEntityAuditTest\\Models\\LogRevision\\Song' => array(), 'SoliantEntityAuditTest\\Models\\LogRevision\\SingleCoverArt' => array()));
     $entityManager = EntityManager::create($conn, $config);
     $moduleOptions->setEntityManager($entityManager);
     $schemaTool = new SchemaTool($entityManager);
     // Add auditing listener
     $entityManager->getEventManager()->addEventSubscriber(new LogRevision());
     $sql = $schemaTool->getUpdateSchemaSql($entityManager->getMetadataFactory()->getAllMetadata());
     #print_r($sql);die();
     $schemaTool->createSchema($entityManager->getMetadataFactory()->getAllMetadata());
     $this->_em = $entityManager;
 }
开发者ID:VOONWerbeagentur,项目名称:SoliantEntityAudit,代码行数:28,代码来源:LogRevisionTest.php

示例4: setUp

 protected function setUp()
 {
     if (!class_exists('Symfony\\Component\\Form\\Form')) {
         $this->markTestSkipped('The "Form" component is not available');
     }
     if (!class_exists('Doctrine\\DBAL\\Platforms\\MySqlPlatform')) {
         $this->markTestSkipped('Doctrine DBAL is not available.');
     }
     if (!class_exists('Doctrine\\Common\\Version')) {
         $this->markTestSkipped('Doctrine Common is not available.');
     }
     if (!class_exists('Doctrine\\ORM\\EntityManager')) {
         $this->markTestSkipped('Doctrine ORM is not available.');
     }
     $this->em = DoctrineOrmTestCase::createTestEntityManager();
     $this->emRegistry = $this->createRegistryMock('default', $this->em);
     parent::setUp();
     $schemaTool = new SchemaTool($this->em);
     $classes = array($this->em->getClassMetadata(self::ITEM_GROUP_CLASS), $this->em->getClassMetadata(self::SINGLE_IDENT_CLASS), $this->em->getClassMetadata(self::SINGLE_STRING_IDENT_CLASS), $this->em->getClassMetadata(self::COMPOSITE_IDENT_CLASS), $this->em->getClassMetadata(self::COMPOSITE_STRING_IDENT_CLASS));
     try {
         $schemaTool->dropSchema($classes);
     } catch (\Exception $e) {
     }
     try {
         $schemaTool->createSchema($classes);
     } catch (\Exception $e) {
     }
 }
开发者ID:ronaldlunaramos,项目名称:webstore,代码行数:28,代码来源:EntityTypeTest.php

示例5: setUp

 public function setUp()
 {
     parent::setUp();
     $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
     $schemaTool = new SchemaTool($em);
     $schemaTool->createSchema($em->getMetadataFactory()->getAllMetadata());
 }
开发者ID:bitecodes,项目名称:rest-api-generator-bundle,代码行数:7,代码来源:NestedResourceSubscriberTest.php

示例6: setUp

 public function setUp()
 {
     parent::setUp();
     $schemaTool = new SchemaTool($this->entityManager);
     $schemaTool->createSchema(array($this->entityManager->getClassMetadata('Pagerfanta\\Tests\\Adapter\\DoctrineORM\\User'), $this->entityManager->getClassMetadata('Pagerfanta\\Tests\\Adapter\\DoctrineORM\\Group'), $this->entityManager->getClassMetadata('Pagerfanta\\Tests\\Adapter\\DoctrineORM\\Person')));
     $this->user1 = $user = new User();
     $this->user2 = $user2 = new User();
     $group1 = new Group();
     $group2 = new Group();
     $group3 = new Group();
     $user->groups[] = $group1;
     $user->groups[] = $group2;
     $user->groups[] = $group3;
     $user2->groups[] = $group1;
     $author1 = new Person();
     $author1->name = 'Foo';
     $author1->biography = 'Baz bar';
     $author2 = new Person();
     $author2->name = 'Bar';
     $author2->biography = 'Bar baz';
     $this->entityManager->persist($user);
     $this->entityManager->persist($user2);
     $this->entityManager->persist($group1);
     $this->entityManager->persist($group2);
     $this->entityManager->persist($group3);
     $this->entityManager->persist($author1);
     $this->entityManager->persist($author2);
     $this->entityManager->flush();
 }
开发者ID:3lolo,项目名称:lr_app,代码行数:29,代码来源:DoctrineORMAdapterTest.php

示例7: execute

 /**
  * do the thing here.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $driver = new DoctrineAdapter();
     $driver->init();
     $em = $driver->getManager();
     $schema = new SchemaTool($em);
     $models = [];
     $model_name = $input->getArgument('model_name');
     $full_name = Config::getInstance()->get('root-namespace') . '\\Models' . '\\' . $model_name . 'Model';
     $schemaManager = $em->getConnection()->getSchemaManager();
     try {
         $metadata = $em->getClassMetadata($full_name);
         $table_name = $metadata->getTableName();
         if ($schemaManager->tablesExist([$table_name]) == true) {
             $models[] = $metadata;
         }
         if (count($models) > 0) {
             $schema->dropSchema($models);
         } else {
             $output->writeln('O model ' . $full_name . ' nao esta registrado no banco de dados.');
         }
     } catch (\Doctrine\ORM\Mapping\MappingException $e) {
         $output->writeln('Erro encontrado:');
         $output->writeln($e->getMessage());
         return;
     }
     $output->writeln('Tabela ' . $table_name . ' removida com sucesso.');
 }
开发者ID:anna-framework,项目名称:anna,代码行数:31,代码来源:DbDropTableCommand.php

示例8: executeSchemaCommand

 protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
 {
     // Defining if update is complete or not (--complete not defined means $saveMode = true)
     $saveMode = $input->getOption('complete') !== true;
     if ($input->getOption('dump-sql') === true) {
         $sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode);
         $output->write(implode(';' . PHP_EOL, $sqls) . PHP_EOL);
     } else {
         if ($input->getOption('force') === true) {
             $output->write('Updating database schema...' . PHP_EOL);
             $schemaTool->updateSchema($metadatas, $saveMode);
             $output->write('Database schema updated successfully!' . PHP_EOL);
         } else {
             $output->write('ATTENTION: This operation should not be executed in a production environment.' . PHP_EOL);
             $output->write('Use the incremental update to detect changes during development and use' . PHP_EOL);
             $output->write('this SQL DDL to manually update your database in production.' . PHP_EOL . PHP_EOL);
             $sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode);
             if (count($sqls)) {
                 $output->write('Schema-Tool would execute ' . count($sqls) . ' queries to update the database.' . PHP_EOL);
                 $output->write('Please run the operation with --force to execute these queries or use --dump-sql to see them.' . PHP_EOL);
             } else {
                 $output->write('Nothing to update. The database is in sync with the current entity metadata.' . PHP_EOL);
             }
         }
     }
 }
开发者ID:halljb57,项目名称:flextrine,代码行数:26,代码来源:UpdateCommand.php

示例9: createSchemaTool

 /**
  * @param EntityManager $em
  * @return SchemaTool
  */
 private function createSchemaTool(EntityManager $em)
 {
     $schemaTool = new SchemaTool($em);
     $schemaTool->dropDatabase();
     $schemaTool->createSchema($em->getMetadataFactory()->getAllMetadata());
     return $schemaTool;
 }
开发者ID:cobase,项目名称:cobase,代码行数:11,代码来源:ServiceTestCase.php

示例10: updateDbSchema

 /**
  * Updates DB Schema. Changes from Diamante only will be applied for current schema. Other bundles updating skips
  * @throws \Exception if there are no changes in entities
  */
 protected function updateDbSchema()
 {
     /**
      * @var $em \Doctrine\ORM\EntityManager
      */
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $event = $em->getEventManager();
     $sm = $em->getConnection()->getSchemaManager();
     $allMetadata = $em->getMetadataFactory()->getAllMetadata();
     $schemaTool = new SchemaTool($em);
     $entitiesMetadata = array($em->getClassMetadata(\Diamante\DeskBundle\Entity\Branch::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Ticket::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Comment::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Attachment::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\BranchEmailConfiguration::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\MessageReference::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\TicketHistory::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\WatcherList::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\TicketTimeline::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Audit::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\AuditField::getClassName()), $em->getClassMetadata(\Diamante\DeskBundle\Entity\Article::getClassName()));
     $event->disableListeners();
     $currentSchema = $sm->createSchema();
     $schemaFromMetadata = $schemaTool->getSchemaFromMetadata($allMetadata);
     $entitiesSchema = $schemaTool->getSchemaFromMetadata($entitiesMetadata);
     $entitiesTables = $entitiesSchema->getTables();
     $entitiesTableName = array_keys($entitiesTables);
     $currentDiamanteSchema = $this->getTargetSchema($currentSchema, $entitiesTableName);
     $diamanteSchemaFromMetadata = $this->getTargetSchema($schemaFromMetadata, $entitiesTableName);
     $comparator = new Comparator();
     $diff = $comparator->compare($currentDiamanteSchema, $diamanteSchemaFromMetadata);
     $toUpdate = $diff->toSql($em->getConnection()->getDatabasePlatform());
     if (empty($toUpdate)) {
         throw new \Exception('No new updates found. DiamanteDesk is up to date!');
     }
     $conn = $em->getConnection();
     foreach ($toUpdate as $sql) {
         $conn->executeQuery($sql);
     }
 }
开发者ID:northdakota,项目名称:diamantedesk-application,代码行数:34,代码来源:AbstractCommand.php

示例11: updateDbSchema

 /**
  * Updates DB Schema.
  * @throws \Exception if there are no changes in entities
  */
 protected function updateDbSchema()
 {
     /**
      * @var $em \Doctrine\ORM\EntityManager
      */
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $event = $em->getEventManager();
     $sm = $em->getConnection()->getSchemaManager();
     $allMetadata = $em->getMetadataFactory()->getAllMetadata();
     $schemaTool = new SchemaTool($em);
     $entitiesMetadata = array($em->getClassMetadata(ApiUser::getClassName()), $em->getClassMetadata(DiamanteUser::getClassName()));
     $event->disableListeners();
     $currentSchema = $sm->createSchema();
     $schemaFromMetadata = $schemaTool->getSchemaFromMetadata($allMetadata);
     $entitiesSchema = $schemaTool->getSchemaFromMetadata($entitiesMetadata);
     $entitiesTables = $entitiesSchema->getTables();
     $entitiesTableName = array_keys($entitiesTables);
     $currentDiamanteSchema = $this->getTargetSchema($currentSchema, $entitiesTableName);
     $diamanteSchemaFromMetadata = $this->getTargetSchema($schemaFromMetadata, $entitiesTableName);
     $comparator = new Comparator();
     $diff = $comparator->compare($currentDiamanteSchema, $diamanteSchemaFromMetadata);
     $toUpdate = $diff->toSql($em->getConnection()->getDatabasePlatform());
     if (empty($toUpdate)) {
         throw new \Exception('No new updates found. Diamante Api Bundle is up to date!');
     }
     $conn = $em->getConnection();
     foreach ($toUpdate as $sql) {
         $conn->executeQuery($sql);
     }
 }
开发者ID:gitter-badger,项目名称:diamantedesk-application,代码行数:34,代码来源:SchemaCommand.php

示例12: prepareDatabase

 private function prepareDatabase()
 {
     /** @var EntityManager $em */
     $em = $this->registry->getManager();
     $tool = new SchemaTool($em);
     $tool->createSchema($em->getMetadataFactory()->getAllMetadata());
 }
开发者ID:karol-wojcik,项目名称:serializer,代码行数:7,代码来源:IntegrationTest.php

示例13: createSchema

 private function createSchema(ContainerInterface $container)
 {
     $entityManager = $container->get('doctrine.orm.entity_manager');
     /** @var EntityManager $entityManager */
     $schemaTool = new SchemaTool($entityManager);
     $schemaTool->createSchema($entityManager->getMetadataFactory()->getAllMetadata());
 }
开发者ID:TomasVotruba,项目名称:SymfonyBridge,代码行数:7,代码来源:SmokeTest.php

示例14: dropAndCreateSchema

 private function dropAndCreateSchema()
 {
     $schemaTool = new SchemaTool($this->getEntityManager());
     $metadata = $this->getEntityManager()->getMetadataFactory()->getAllMetadata();
     $schemaTool->dropSchema($metadata);
     $schemaTool->createSchema($metadata);
 }
开发者ID:lzakrzewski,项目名称:tests-with-database-examples,代码行数:7,代码来源:EmptyDatabaseTest.php

示例15: createDoctrineSchema

 /**
  * Creates schema for doctrine entities
  *
  * @throws \Doctrine\ORM\Tools\ToolsException
  */
 protected function createDoctrineSchema()
 {
     $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
     $tool = new SchemaTool($this->entityManager);
     $tool->dropSchema($metadata);
     $tool->createSchema($metadata);
 }
开发者ID:silversolutions,项目名称:content-loader-bundle,代码行数:12,代码来源:DatabaseSchemaCreator.php


注:本文中的Doctrine\ORM\Tools\SchemaTool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。