本文整理汇总了PHP中Doctrine\ORM\Tools\SchemaTool::updateSchema方法的典型用法代码示例。如果您正苦于以下问题:PHP SchemaTool::updateSchema方法的具体用法?PHP SchemaTool::updateSchema怎么用?PHP SchemaTool::updateSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\SchemaTool
的用法示例。
在下文中一共展示了SchemaTool::updateSchema方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
if (!GeometryEngineRegistry::has()) {
$this->markTestSkipped('This test requires a connection to a database.');
}
$engine = GeometryEngineRegistry::get();
if (!$engine instanceof PDOEngine) {
$this->markTestSkipped('This test currently only works with a PDO connection.');
}
$this->platform = $this->_conn->getDatabasePlatform();
$this->platform->registerDoctrineTypeMapping('geometry', 'binary');
$this->platform->registerDoctrineTypeMapping('linestring', 'binary');
$this->platform->registerDoctrineTypeMapping('multilinestring', 'binary');
$this->platform->registerDoctrineTypeMapping('multipoint', 'binary');
$this->platform->registerDoctrineTypeMapping('multipolygon', 'binary');
$this->platform->registerDoctrineTypeMapping('point', 'binary');
$this->platform->registerDoctrineTypeMapping('polygon', 'binary');
switch ($this->platform->getName()) {
case 'postgresql':
$this->_conn->executeQuery('CREATE EXTENSION IF NOT EXISTS postgis;');
break;
}
$this->fixtureLoader = new Loader();
$config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/Fixtures'], false);
$config->addCustomNumericFunction('EarthDistance', EarthDistanceFunction::class);
$this->em = EntityManager::create($this->_conn, $config, $this->platform->getEventManager());
$this->schemaTool = new SchemaTool($this->em);
$this->schemaTool->updateSchema([$this->em->getClassMetadata(Fixtures\GeometryEntity::class), $this->em->getClassMetadata(Fixtures\LineStringEntity::class), $this->em->getClassMetadata(Fixtures\MultiLineStringEntity::class), $this->em->getClassMetadata(Fixtures\MultiPointEntity::class), $this->em->getClassMetadata(Fixtures\MultiPolygonEntity::class), $this->em->getClassMetadata(Fixtures\PointEntity::class), $this->em->getClassMetadata(Fixtures\PolygonEntity::class)]);
$purger = new ORMPurger();
$this->ormExecutor = new ORMExecutor($this->em, $purger);
}
示例2: rebuildDatabase
/**
* Builds the DB Schema
*
* @return void
*/
protected function rebuildDatabase()
{
# 2. Drop the existing database schema
$this->schemaTool->dropDatabase();
# 3. Create the new database schema based on (1)
$entityMeta = $this->em->getMetadataFactory()->getAllMetadata();
$this->schemaTool->updateSchema($entityMeta);
}
示例3: setUp
/**
* Set up test env
*
* @return void
*/
public function setUp()
{
$this->eventDispatcher = new EventDispatcher();
$this->params = new CollectorParamBag();
$setup = Setup::createAnnotationMetadataConfiguration([ENTITIES], true);
$this->em = EntityManager::create(['driver' => 'pdo_mysql', 'user' => 'user', 'password' => '', 'dbname' => 'warden'], $setup);
// Setup Param Bag
$this->params->add('query_limit', ['type' => 'integer', 'default' => 5, 'limit' => 5, 'value' => null, 'expression' => 'value >= limit']);
// Sync the schema
$this->schema = new SchemaTool($this->em);
$this->schema->updateSchema($this->em->getMetadataFactory()->getAllMetadata(), true);
// Events
$this->start = new StartEvent();
$this->stop = new StopEvent($this->params);
}
示例4: update_entity_settings
public function update_entity_settings()
{
if (!$this->token->validate("update_entity_settings")) {
$this->error->add($this->token->getErrorMessage());
}
if (!$this->error->has()) {
if ($this->isPost()) {
$ddm = $this->post('DOCTRINE_DEV_MODE') == 1 ? 1 : 0;
if ($this->request->request->get('refresh')) {
$em = ORM::entityManager();
$config = $em->getConfiguration();
// First, we flush the metadata cache.
if (is_object($cache = $config->getMetadataCacheImpl())) {
$cache->flushAll();
}
// Next, we regnerate proxies
$metadatas = $em->getMetadataFactory()->getAllMetadata();
$em->getProxyFactory()->generateProxyClasses($metadatas, $this->app->make('config')->get('database.proxy_classes'));
// Finally, we update the schema
$tool = new SchemaTool($em);
$tool->updateSchema($metadatas, true);
$this->flash('success', t('Doctrine cache cleared, proxy classes regenerated, entity database table schema updated.'));
$this->redirect('/dashboard/system/environment/entities', 'view');
} else {
Config::save('concrete.cache.doctrine_dev_mode', (bool) $ddm);
$this->flash('success', t('Doctrine development settings updated.'));
}
$this->redirect('/dashboard/system/environment/entities', 'view');
}
} else {
$this->set('error', array($this->token->getErrorMessage()));
}
}
示例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();
}
}
示例6: 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()));
}
}
}
示例7: 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');
}
}
示例8: handleDatabaseUpdate
public function handleDatabaseUpdate(Args $args, IO $io, Command $command)
{
$tool = new SchemaTool($this->app['entyMgr']);
$tool->updateSchema($this->app['entyMgr']->getMetadataFactory()->getAllMetadata());
$io->writeLine("<info>Database schema updated.</info>");
return 0;
}
示例9: rebuildSchema
public function rebuildSchema()
{
$metadatas = $this->em->getMetadataFactory()->getAllMetadata();
$tool = new SchemaTool($this->em);
$tool->dropSchema($metadatas);
$tool->updateSchema($metadatas, false);
}
示例10: 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.');
}
}
示例11: 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);
}
}
}
}
示例12: updateSchema
public static function updateSchema($appName, $modelNames = null)
{
$em = self::getEntityManager($appName, $modelNames);
$tool = new SchemaTool($em);
$classes = self::getMetadata($appName, $modelNames);
$tool->updateSchema($classes, true);
}
示例13: schemaUpdateAction
public function schemaUpdateAction()
{
/* @var $em EntityManager */
$em = $this->serviceLocator->get("doctrine.entitymanager.orm_dest");
$metadata = $em->getMetadataFactory()->getAllMetadata();
$shemaTool = new SchemaTool($em);
$shemaTool->updateSchema($metadata, true);
}
示例14: 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!');
}
}
示例15: performDatabaseUpgrade
protected function performDatabaseUpgrade()
{
/**
* @var EntityManager
*/
$entityManager = $this->container->get('doctrine')->getManager();
$tool = new SchemaTool($entityManager);
$meta = $this->container->get('doctrine')->getManager()->getMetadataFactory()->getAllMetadata();
$tool->updateSchema($meta, true);
}