本文整理汇总了PHP中Doctrine\ORM\Tools\SchemaTool::getDropSchemaSQL方法的典型用法代码示例。如果您正苦于以下问题:PHP SchemaTool::getDropSchemaSQL方法的具体用法?PHP SchemaTool::getDropSchemaSQL怎么用?PHP SchemaTool::getDropSchemaSQL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\SchemaTool
的用法示例。
在下文中一共展示了SchemaTool::getDropSchemaSQL方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeSchemaCommand
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
{
$isFullDatabaseDrop = $input->getOption('full-database');
if ($input->getOption('dump-sql') === true) {
if ($isFullDatabaseDrop) {
$sqls = $schemaTool->getDropDatabaseSQL();
} else {
$sqls = $schemaTool->getDropSchemaSQL($metadatas);
}
$output->write(implode(';' . PHP_EOL, $sqls) . PHP_EOL);
} else {
if ($input->getOption('force') === true) {
$output->write('Dropping database schema...' . PHP_EOL);
if ($isFullDatabaseDrop) {
$schemaTool->dropDatabase();
} else {
$schemaTool->dropSchema($metadatas);
}
$output->write('Database schema dropped successfully!' . PHP_EOL);
} else {
$output->write('ATTENTION: This operation should not be executed in a production environment.' . PHP_EOL . PHP_EOL);
if ($isFullDatabaseDrop) {
$sqls = $schemaTool->getDropDatabaseSQL();
} else {
$sqls = $schemaTool->getDropSchemaSQL($metadatas);
}
if (count($sqls)) {
$output->write('Schema-Tool would execute ' . count($sqls) . ' queries to drop 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 drop. The database is empty!' . PHP_EOL);
}
}
}
}
示例2: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$sql = $this->tool->getDropSchemaSQL($this->metadata->getAllMetadata());
if (empty($sql)) {
$this->info('Current models do not exist in schema.');
return;
}
if ($this->option('sql')) {
$this->info('Outputting drop query:');
$this->info(implode(';' . PHP_EOL, $sql));
} else {
$this->info('Dropping database schema....');
$this->tool->dropSchema($this->metadata->getAllMetadata());
$this->info('Schema has been dropped!');
}
}
示例3: testDropTable
/**
* There seems to be a bug when I try to drop a table.
*/
public function testDropTable()
{
$statements = $this->tool->getDropSchemaSQL($this->classes);
$this->assertInternalType('array', $statements);
$this->assertSame('DROP SEQUENCE test_id_seq CASCADE', $statements[0]);
$this->assertSame('DROP TABLE test', $statements[1]);
}
示例4: uninstallEntity
public function uninstallEntity(array $entity)
{
$metadata = $this->getMetadata($entity);
$tool = new SchemaTool($this->_em);
$queries = $tool->getDropSchemaSQL($metadata);
return $this->persist($queries ?: array());
}
示例5: fire
/**
* Execute the console command.
*
* @param ManagerRegistry $registry
*/
public function fire(ManagerRegistry $registry)
{
$this->error('ATTENTION: This operation should not be executed in a production environment.');
$names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames();
foreach ($names as $name) {
$em = $registry->getManager($name);
$tool = new SchemaTool($em);
$this->info('');
$this->message('Checking scheme for <info>' . $name . '</info> entity manager...');
if ($this->option('sql')) {
if ($this->option('full')) {
$sql = $tool->getDropDatabaseSQL();
} else {
$sql = $tool->getDropSchemaSQL($em->getMetadataFactory()->getAllMetadata());
}
$this->comment(' ' . implode('; ' . PHP_EOL, $sql));
} else {
if ($this->option('force')) {
$this->message('Dropping database schema...');
if ($this->option('full')) {
$tool->dropDatabase();
} else {
$tool->dropSchema($em->getMetadataFactory()->getAllMetadata());
}
$this->info('Database schema dropped successfully!');
}
if ($this->option('full')) {
$sql = $tool->getDropDatabaseSQL();
} else {
$sql = $tool->getDropSchemaSQL($em->getMetadataFactory()->getAllMetadata());
}
if (count($sql)) {
$pluralization = 1 === count($sql) ? 'query was' : 'queries were';
$this->message(sprintf('The Schema-Tool would execute <info>"%s"</info> %s to update the database.', count($sql), $pluralization));
$this->message('Please run the operation by passing one - or both - of the following options:');
$this->comment(sprintf(' <info>php artisan %s --force</info> to execute the command', $this->getName()));
$this->comment(sprintf(' <info>php artisan %s --sql</info> to dump the SQL statements to the screen', $this->getName()));
} else {
$this->error('Nothing to drop. The database is empty!');
}
}
}
}
示例6: fire
public function fire()
{
$sql = $this->tool->getDropSchemaSQL($this->metadata->getAllMetadata());
if (empty($sql)) {
$this->error('Current models do not exist in schema.');
return;
}
if ($this->option('sql')) {
$this->info('Outputting drop query:' . PHP_EOL);
$this->line(implode(';' . PHP_EOL, $sql) . ';');
} else {
if ($this->option('commit')) {
$this->info('Dropping database schema....');
$this->tool->dropSchema($this->metadata->getAllMetadata());
$this->info('Schema has been dropped!');
} else {
$this->comment("Warning: this command can cause data loss. Run with --sql or --commit.");
}
}
}
示例7: executeSchemaCommand
/**
* {@inheritdoc}
*/
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
{
$isFullDatabaseDrop = $input->getOption('full-database');
if ($input->getOption('dump-sql')) {
if ($isFullDatabaseDrop) {
$sqls = $schemaTool->getDropDatabaseSQL();
} else {
$sqls = $schemaTool->getDropSchemaSQL($metadatas);
}
$output->writeln(implode(';' . PHP_EOL, $sqls));
return 0;
}
if ($input->getOption('force')) {
$output->writeln('Dropping database schema...');
if ($isFullDatabaseDrop) {
$schemaTool->dropDatabase();
} else {
$schemaTool->dropSchema($metadatas);
}
$output->writeln('Database schema dropped successfully!');
return 0;
}
$output->writeln('<comment>ATTENTION</comment>: This operation should not be executed in a production environment.' . PHP_EOL);
if ($isFullDatabaseDrop) {
$sqls = $schemaTool->getDropDatabaseSQL();
} else {
$sqls = $schemaTool->getDropSchemaSQL($metadatas);
}
if (count($sqls)) {
$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 - or both - 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()));
return 1;
}
$output->writeln('Nothing to drop. The database is empty!');
return 0;
}
示例8: testGetDropSchemaSql
public function testGetDropSchemaSql()
{
$classes = array($this->_em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsAddress'), $this->_em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser'), $this->_em->getClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsPhonenumber'));
$tool = new SchemaTool($this->_em);
$sql = $tool->getDropSchemaSQL($classes);
$this->assertEquals(13, count($sql));
$dropSequenceSQLs = 0;
foreach ($sql as $stmt) {
if (strpos($stmt, "DROP SEQUENCE") === 0) {
$dropSequenceSQLs++;
}
}
$this->assertEquals(4, $dropSequenceSQLs, "Expect 4 sequences to be dropped.");
}
示例9: dropPluginSchema
/**
* Drops plugin's tables based on Doctrine metadata.
*
* @param array $metadata
* @param MauticFactory $factory
*
* @throws \Doctrine\DBAL\ConnectionException
* @throws \Exception
*/
public static function dropPluginSchema(array $metadata, MauticFactory $factory)
{
$db = $factory->getDatabase();
$schemaTool = new SchemaTool($factory->getEntityManager());
$dropQueries = $schemaTool->getDropSchemaSQL($metadata);
$db->beginTransaction();
try {
foreach ($dropQueries as $q) {
$db->query($q);
}
$db->commit();
} catch (\Exception $e) {
$db->rollback();
throw $e;
}
}