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


PHP SchemaTool::getUpdateSchemaSql方法代码示例

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


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

示例1: 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

示例2: execute

 public function execute()
 {
     $d = $this->factory()->appDoctrine();
     $this->app->dataStorage->clearStorage('CyantreeDoctrineModule/Proxies');
     $this->app->cacheStorage->clearStorage('CyantreeDoctrineModule');
     $tool = new SchemaTool($d);
     $queries = $tool->getUpdateSchemaSql($d->getMetadataFactory()->getAllMetadata());
     if ($queries) {
         $hash = '';
         foreach ($queries as $query) {
             $hash = md5($hash . $query);
         }
         $code = substr($hash, 0, 8);
         if ($transferredCode = $this->request->args->get('code')) {
             if ($transferredCode == $code) {
                 $tool->updateSchema($d->getMetadataFactory()->getAllMetadata());
                 $this->result->showSuccess('Schema has been updated.');
                 return;
             } else {
                 $this->result->showError('Passed invalid code.');
             }
         }
         $this->result->showWarning('Schema is not up to date. The following queries would be executed:');
         foreach ($queries as $query) {
             $this->result->showInfo($query);
         }
         $this->result->showWarning("Execute with -code={$code} to update the database schema.");
     } else {
         $this->result->showSuccess('Schema is up to date.');
     }
 }
开发者ID:cyantree,项目名称:grout-project,代码行数:31,代码来源:UpdateDatabaseSchemaCommand.php

示例3: 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;
     $sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode);
     if (0 == count($sqls)) {
         $output->writeln('Nothing to update - your database is already in sync with the current entity metadata.');
         return;
     }
     $dumpSql = true === $input->getOption('dump-sql');
     $force = true === $input->getOption('force');
     if ($dumpSql && $force) {
         throw new \InvalidArgumentException('You can pass either the --dump-sql or the --force option (but not both simultaneously).');
     }
     if ($dumpSql) {
         $output->writeln(implode(';' . PHP_EOL, $sqls));
     } else {
         if ($force) {
             $output->writeln('Updating database schema...');
             $schemaTool->updateSchema($metadatas, $saveMode);
             $output->writeln(sprintf('Database schema updated successfully! "<info>%s</info>" queries were executed', count($sqls)));
         } else {
             $output->writeln('<comment>ATTENTION</comment>: This operation should not be executed in a production environment.');
             $output->writeln('           Use the incremental update to detect changes during development and use');
             $output->writeln('           the SQL DDL provided to manually update your database in production.');
             $output->writeln('');
             $output->writeln(sprintf('The Schema-Tool would execute <info>"%s"</info> queries to update the database.', count($sqls)));
             $output->writeln('Please run the operation by passing one of the following options:');
             $output->writeln(sprintf('    <info>%s --force</info> to execute the command', $this->getName()));
             $output->writeln(sprintf('    <info>%s --dump-sql</info> to dump the SQL statements to the screen', $this->getName()));
         }
     }
 }
开发者ID:laiello,项目名称:masfletes,代码行数:33,代码来源:UpdateCommand.php

示例4: updateAction

 public function updateAction()
 {
     $console = $this->getServiceLocator()->get('console');
     // Make sure that we are running in a console and the user has not tricked our
     // application into running this action from a public web server.
     $request = $this->getRequest();
     if (!$request instanceof ConsoleRequest) {
         throw new RuntimeException('You can only use this action from a console.');
     }
     $classes = array();
     $metas = $this->getAuditObjectManager()->getMetadataFactory()->getAllMetadata();
     foreach ($metas as $meta) {
         $classes[] = $meta;
     }
     $schemaTool = new SchemaTool($this->getAuditObjectManager());
     try {
         $result = $schemaTool->getUpdateSchemaSql($classes, false);
     } catch (\Exception $e) {
         $console->write($e->getCode() . ": " . $e->getMessage());
         $console->write("\nExiting now");
         return;
     }
     foreach ($result as $sql) {
         $console->write($sql . ";\n");
     }
 }
开发者ID:api-skeletons,项目名称:zf-doctrine-audit,代码行数:26,代码来源:SchemaToolController.php

示例5: execute

 /**
  * Runs command
  *
  * @param  InputInterface  $input
  * @param  OutputInterface $output
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln($this->getDescription());
     /** @var EntityManager $em */
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     /** @var ConfigManager $configManager */
     $configManager = $this->getContainer()->get('oro_entity_config.config_manager');
     $metadata = array_filter($em->getMetadataFactory()->getAllMetadata(), function ($doctrineMetadata) use($configManager) {
         /** @var ClassMetadataInfo $doctrineMetadata */
         return $this->isExtendEntity($doctrineMetadata->getReflectionClass()->getName(), $configManager);
     });
     $schemaTool = new SchemaTool($em);
     $sqls = $schemaTool->getUpdateSchemaSql($metadata, true);
     if (0 === count($sqls)) {
         $output->writeln('Nothing to update - a database is already in sync with the current entity metadata.');
     } else {
         if ($input->getOption('dry-run')) {
             $output->writeln(implode(';' . PHP_EOL, $sqls) . ';');
         } else {
             $output->writeln('Updating database schema...');
             $schemaTool->updateSchema($metadata, true);
             $output->writeln(sprintf('Database schema updated successfully! "<info>%s</info>" queries were executed', count($sqls)));
         }
     }
     if (!$input->getOption('dry-run')) {
         /** @var EnumSynchronizer $enumSynchronizer */
         $enumSynchronizer = $this->getContainer()->get('oro_entity_extend.enum_synchronizer');
         $enumSynchronizer->sync();
     }
 }
开发者ID:xamin123,项目名称:platform,代码行数:37,代码来源:UpdateSchemaCommand.php

示例6: main

 /**
  * main method
  *
  * @return void
  */
 public function main()
 {
     static $em;
     if ($em === null) {
         $wd = getcwd();
         $zf = $this->project->getProperty('zf');
         $application = (require $zf);
         if (!$application instanceof Application) {
             throw new BuildException(sprintf('zf bootstrap file "%s" should return an instance of Zend\\Mvc\\Application', $zf));
         }
         chdir($wd);
         $em = $application->getServiceManager()->get($this->em);
     }
     $metadatas = $em->getMetadataFactory()->getAllMetadata();
     if (!empty($metadatas)) {
         $tool = new SchemaTool($em);
         $sqls = $tool->getUpdateSchemaSql($metadatas, false);
         if (0 === count($sqls)) {
             $this->log('Nothing to update - your database is already in sync with the current entity metadata.');
         } else {
             $this->log('Updating database schema...');
             $tool->updateSchema($metadatas, false);
             $this->log(sprintf('Database schema updated successfully! %s queries were executed', count($sqls)));
         }
     } else {
         $this->log('No metadata classes to process');
     }
 }
开发者ID:heartsentwined,项目名称:zf2-phing-task,代码行数:33,代码来源:DoctrineUpdateTask.php

示例7: 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

示例8: getUpdateBundleSqlSchema

 private function getUpdateBundleSqlSchema()
 {
     $sql = array();
     foreach ($this->_application->getBundles() as $bundle) {
         $classes = $this->_getBundleSchema($bundle);
         $sql = array_merge($sql, $this->_schemaTool->getUpdateSchemaSql($classes, true));
     }
     return $sql;
 }
开发者ID:nietzcheson,项目名称:BackBee,代码行数:9,代码来源:Database.php

示例9: fire

 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->info('Checking if database needs updating....');
     $clean = $this->option('clean');
     $sql = $this->tool->getUpdateSchemaSql($this->metadata->getAllMetadata(), !$clean);
     if (empty($sql)) {
         $this->info('No updates found.');
         return;
     }
     if ($this->option('sql')) {
         $this->info('Outputting update query:');
         $this->info(implode(';' . PHP_EOL, $sql));
     } else {
         $this->info('Updating database schema....');
         $this->tool->updateSchema($this->metadata->getAllMetadata(), !$clean);
         $this->info('Schema has been updated!');
     }
 }
开发者ID:rsamborski,项目名称:laravel-doctrine,代码行数:23,代码来源:SchemaUpdateCommand.php

示例10: getUpdateQueries

 /**
  * @return string[]
  */
 protected function getUpdateQueries()
 {
     $cache = $this->entityManager->getConfiguration()->getMetadataCacheImpl();
     if ($cache instanceof ClearableCache) {
         $cache->deleteAll();
     }
     $schemaTool = new SchemaTool($this->entityManager);
     $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
     $queries = $schemaTool->getUpdateSchemaSql($metadata, TRUE);
     return $queries;
 }
开发者ID:nextras,项目名称:migrations,代码行数:14,代码来源:StructureDiffGenerator.php

示例11: testUpdateSchemaWithPostgreSQLSchema

 /**
  * @group DDC-1657
  */
 public function testUpdateSchemaWithPostgreSQLSchema()
 {
     $classes = array($this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1657Screen'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1657Avatar'));
     $tool = new SchemaTool($this->_em);
     $tool->createSchema($classes);
     $sql = $tool->getUpdateSchemaSql($classes);
     $sql = array_filter($sql, function ($sql) {
         return strpos($sql, "DROP SEQUENCE stonewood.") === 0;
     });
     $this->assertCount(0, $sql, implode("\n", $sql));
 }
开发者ID:selimcr,项目名称:servigases,代码行数:14,代码来源:PostgreSqlSchemaToolTest.php

示例12: fire

 public function fire()
 {
     $this->info('Checking if database needs updating....');
     $sql = $this->tool->getUpdateSchemaSql($this->metadata->getAllMetadata(), $this->option('clean'));
     if (empty($sql)) {
         $this->info('No updates found.');
         return;
     }
     if ($this->option('sql')) {
         $this->info('Outputting update query:');
         $this->info(implode(';' . PHP_EOL, $sql) . ';');
     } else {
         if ($this->option('commit')) {
             $this->info('Updating database schema....');
             $this->tool->updateSchema($this->metadata->getAllMetadata());
             $this->info('Schema has been updated!');
         } else {
             $this->comment("Warning: this command can cause data loss. Run with --sql or --commit.");
         }
     }
 }
开发者ID:opensolutions,项目名称:doctrine2bridge-l5,代码行数:21,代码来源:Update.php

示例13: 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 {
         $output->write('Updating database schema...' . PHP_EOL);
         $schemaTool->updateSchema($metadatas, $saveMode);
         $output->write('Database schema updated successfully!' . PHP_EOL);
     }
 }
开发者ID:jacques-sounvi,项目名称:addressbook,代码行数:13,代码来源:UpdateCommand.php

示例14: 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 {
             $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:skoop,项目名称:symfony-sandbox,代码行数:23,代码来源:UpdateCommand.php

示例15: checkThatNewConstraintsCanBeApplied

 private function checkThatNewConstraintsCanBeApplied(EntityManager $em)
 {
     $tool = new SchemaTool($em);
     $metas = $em->getMetadataFactory()->getAllMetadata();
     // Bad ordering of Indexes changes in Doctrine DBAL-2.5
     $sqls = $tool->getUpdateSchemaSql($metas, true);
     foreach ($sqls as $sql) {
         if ('DROP INDEX usr_id ON Sessions' === $sql) {
             $em->getConnection()->executeQuery($sql);
         }
     }
     // End patching DBAL-2.5
     $tool->updateSchema($metas, true);
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:14,代码来源:Upgrade39UsersTest.php


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