Fixed CS
This commit is contained in:
parent
0347aaccb8
commit
e463a8bcd8
|
@ -43,8 +43,9 @@ class DatabaseCreateCommand extends PhingCommand
|
|||
\Propel::setConfiguration($this->getTemporaryConfiguration($name, $config));
|
||||
$connection = \Propel::getConnection();
|
||||
|
||||
$statement = $connection->prepare($query);
|
||||
$statement = $connection->prepare($query);
|
||||
$statement->execute();
|
||||
|
||||
$output->writeln(sprintf('<info><comment>%s</comment> has been created.</info>', $dbName));
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln(sprintf('<error>An error has occured: %s</error>', $e->getMessage()));
|
||||
|
|
|
@ -47,6 +47,7 @@ EOT
|
|||
if ($input->getOption('force')) {
|
||||
if ('prod' === $this->getApplication()->getKernel()->getEnvironment()) {
|
||||
$this->writeSection($output, 'WARNING: you are about to drop a database in production !', 'bg=red;fg=white');
|
||||
|
||||
if (false === $this->askConfirmation($output, 'Are you sure ? (y/n) ', false)) {
|
||||
$output->writeln('Aborted, nice decision !');
|
||||
return -2;
|
||||
|
@ -63,6 +64,7 @@ EOT
|
|||
$connection = \Propel::getConnection($name);
|
||||
$statement = $connection->prepare($query);
|
||||
$statement->execute();
|
||||
|
||||
$output->writeln(sprintf('<info><comment>%s</comment> has been dropped.</info>', $dbName));
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln(sprintf('<error>An error has occured: %s</error>', $e->getMessage()));
|
||||
|
|
|
@ -111,6 +111,7 @@ EOT
|
|||
// Create a "datadb.map" file
|
||||
$datadbContent = '';
|
||||
$datas = $finder->name('*.xml')->in($this->absoluteFixturesPath);
|
||||
|
||||
foreach($datas as $data) {
|
||||
$output->writeln(sprintf('Loaded fixtures from <comment>%s</comment>.', $data));
|
||||
|
||||
|
@ -137,7 +138,6 @@ EOT
|
|||
$insertCommand->execute($input, $output);
|
||||
|
||||
$this->removeTemporaryFiles();
|
||||
|
||||
$this->filesystem->remove($datadbFile);
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,6 @@ EOT
|
|||
$datas = $finder->name('*.sql')->in($this->absoluteFixturesPath);
|
||||
foreach($datas as $data) {
|
||||
$output->writeln(sprintf('Loaded fixtures from <comment>%s</comment>.', $data));
|
||||
|
||||
$sqldbContent .= $data->getFilename() . '=default' . PHP_EOL;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,86 +36,75 @@ The <info>--force</info> parameter has to be used to actually drop the table.
|
|||
The <info>--connection</info> parameter allows you to change the connection to use.
|
||||
The default connection is the active connection (propel.dbal.default_connection).
|
||||
EOT
|
||||
)
|
||||
)
|
||||
->setName('propel:table:drop');
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Command
|
||||
*
|
||||
* @throws \InvalidArgumentException When the target directory does not exist
|
||||
*/
|
||||
/**
|
||||
* @see Command
|
||||
*
|
||||
* @throws \InvalidArgumentException When the target directory does not exist
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$tablesToDelete = $input->getArgument('table');
|
||||
$tablesToDelete = $input->getArgument('table');
|
||||
|
||||
if ($input->getOption('force'))
|
||||
{
|
||||
$nbTable = count($tablesToDelete);
|
||||
$tablePlural = (($nbTable > 1 || $nbTable == 0) ? 's' : '' );
|
||||
if ($input->getOption('force')) {
|
||||
$nbTable = count($tablesToDelete);
|
||||
$tablePlural = (($nbTable > 1 || $nbTable == 0) ? 's' : '' );
|
||||
|
||||
if ('prod' === $this->getApplication()->getKernel()->getEnvironment())
|
||||
{
|
||||
$this->writeSection($output, 'WARNING: you are about to drop ' . (count($input->getArgument('table')) ?: 'all') . ' table' . $tablePlural . ' in production !', 'bg=red;fg=white');
|
||||
if ('prod' === $this->getApplication()->getKernel()->getEnvironment()) {
|
||||
$this->writeSection($output, 'WARNING: you are about to drop ' . (count($input->getArgument('table')) ?: 'all') . ' table' . $tablePlural . ' in production !', 'bg=red;fg=white');
|
||||
|
||||
if (false === $this->askConfirmation($output, 'Are you sure ? (y/n) ', false))
|
||||
{
|
||||
$output->writeln('Aborted, nice decision !');
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeSection($output, '[Propel] You are running the command: propel:table:drop');
|
||||
|
||||
try
|
||||
{
|
||||
list($name, $config) = $this->getConnection($input, $output);
|
||||
$connection = \Propel::getConnection($name);
|
||||
|
||||
$showStatement = $connection->prepare('SHOW TABLES;');
|
||||
$showStatement->execute();
|
||||
$allTables = $showStatement->fetchAll(\PDO::FETCH_COLUMN);
|
||||
|
||||
if ($nbTable)
|
||||
{
|
||||
foreach ($tablesToDelete as $tableToDelete)
|
||||
{
|
||||
if(!array_search($tableToDelete, $allTables))
|
||||
{
|
||||
throw new \InvalidArgumentException(sprintf('Table %s doesn\'t exist in the database.', $tableToDelete));
|
||||
}
|
||||
if (false === $this->askConfirmation($output, 'Are you sure ? (y/n) ', false)) {
|
||||
$output->writeln('Aborted, nice decision !');
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$tablesToDelete = $allTables;
|
||||
}
|
||||
|
||||
$connection->exec('SET FOREIGN_KEY_CHECKS = 0;');
|
||||
$this->writeSection($output, '[Propel] You are running the command: propel:table:drop');
|
||||
|
||||
$tablesToDelete = join(', ', $tablesToDelete);
|
||||
try {
|
||||
list($name, $config) = $this->getConnection($input, $output);
|
||||
$connection = \Propel::getConnection($name);
|
||||
|
||||
if ($tablesToDelete != '')
|
||||
{
|
||||
$connection->exec('DROP TABLE ' . $tablesToDelete . ' ;');
|
||||
$showStatement = $connection->prepare('SHOW TABLES;');
|
||||
$showStatement->execute();
|
||||
|
||||
$output->writeln(sprintf('Table' . $tablePlural . ' <info><comment>%s</comment> has been dropped.</info>', $tablesToDelete));
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln('No table <info>has been dropped</info>');
|
||||
}
|
||||
$allTables = $showStatement->fetchAll(\PDO::FETCH_COLUMN);
|
||||
|
||||
$connection->exec('SET FOREIGN_KEY_CHECKS = 1;');
|
||||
if ($nbTable) {
|
||||
foreach ($tablesToDelete as $tableToDelete) {
|
||||
if(!array_search($tableToDelete, $allTables)) {
|
||||
throw new \InvalidArgumentException(sprintf('Table %s doesn\'t exist in the database.', $tableToDelete));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$tablesToDelete = $allTables;
|
||||
}
|
||||
|
||||
$connection->exec('SET FOREIGN_KEY_CHECKS = 0;');
|
||||
|
||||
$tablesToDelete = join(', ', $tablesToDelete);
|
||||
|
||||
if ('' !== $tablesToDelete) {
|
||||
$connection->exec('DROP TABLE ' . $tablesToDelete . ' ;');
|
||||
|
||||
$output->writeln(sprintf('Table' . $tablePlural . ' <info><comment>%s</comment> has been dropped.</info>', $tablesToDelete));
|
||||
}
|
||||
else {
|
||||
$output->writeln('No table <info>has been dropped</info>');
|
||||
}
|
||||
|
||||
$connection->exec('SET FOREIGN_KEY_CHECKS = 1;');
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$output->writeln(sprintf('<error>An error has occured: %s</error>', $e->getMessage()));
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$output->writeln(sprintf('<error>An error has occured: %s</error>', $e->getMessage()));
|
||||
else {
|
||||
$output->writeln('<error>You have to use --force to drop some table.</error>');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln('<error>You have to use --force to drop some table.</error>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue