Made using schema-tool:drop and schema-tool:update more secure by requiring the user to confirm the operation with another flag --force.
This commit is contained in:
parent
803e338365
commit
7ff9976b3c
@ -49,13 +49,17 @@ class DropCommand extends AbstractCommand
|
||||
$this
|
||||
->setName('orm:schema-tool:drop')
|
||||
->setDescription(
|
||||
'Processes the schema and either drop the database schema of EntityManager Storage Connection or generate the SQL output.'
|
||||
'Drop the complete database schema of EntityManager Storage Connection or generate the corresponding SQL output.'
|
||||
)
|
||||
->setDefinition(array(
|
||||
new InputOption(
|
||||
'dump-sql', null, InputOption::PARAMETER_NONE,
|
||||
'Instead of try to apply generated SQLs into EntityManager Storage Connection, output them.'
|
||||
)
|
||||
),
|
||||
new InputOption(
|
||||
'force', null, InputOption::PARAMETER_NONE,
|
||||
"Don't ask for the deletion of the database, but force the operation to run."
|
||||
),
|
||||
))
|
||||
->setHelp(<<<EOT
|
||||
Processes the schema and either drop the database schema of EntityManager Storage Connection or generate the SQL output.
|
||||
@ -69,10 +73,19 @@ EOT
|
||||
if ($input->getOption('dump-sql') === true) {
|
||||
$sqls = $schemaTool->getDropSchemaSql($metadatas);
|
||||
$output->write(implode(';' . PHP_EOL, $sqls) . PHP_EOL);
|
||||
} else {
|
||||
} else if ($input->getOption('force') === true) {
|
||||
$output->write('Dropping database schema...' . PHP_EOL);
|
||||
$schemaTool->dropSchema($metadatas);
|
||||
$output->write('Database schema dropped successfully!' . PHP_EOL);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,11 @@ class UpdateCommand extends AbstractCommand
|
||||
new InputOption(
|
||||
'dump-sql', null, InputOption::PARAMETER_NONE,
|
||||
'Instead of try to apply generated SQLs into EntityManager Storage Connection, output them.'
|
||||
)
|
||||
),
|
||||
new InputOption(
|
||||
'force', null, InputOption::PARAMETER_NONE,
|
||||
"Don't ask for the deletion of the database, but force the operation to run."
|
||||
),
|
||||
))
|
||||
->setHelp(<<<EOT
|
||||
Processes the schema and either update the database schema of EntityManager Storage Connection or generate the SQL output.
|
||||
@ -72,15 +76,24 @@ EOT
|
||||
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);
|
||||
$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 {
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user