From 6785589a0ccfe6ef31c709de7ade89cc7c96ae06 Mon Sep 17 00:00:00 2001 From: Maxime AILLOUD Date: Wed, 13 Jul 2011 16:31:49 +0200 Subject: [PATCH] Using the propel connection through the dependency injector, and dealing with foreign key when dropping table --- Command/TableDropCommand.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Command/TableDropCommand.php b/Command/TableDropCommand.php index def6159..6df3abf 100644 --- a/Command/TableDropCommand.php +++ b/Command/TableDropCommand.php @@ -69,8 +69,7 @@ EOT try { - list($name, $config) = $this->getConnection($input, $output); - $connection = \Propel::getConnection($name); + $connection = $this->getContainer()->get('propel.connection'); $showStatement = $connection->prepare('SHOW TABLES;'); $showStatement->execute(); @@ -91,12 +90,13 @@ EOT $tablesToDelete = $allTables; } + $connection->exec('SET FOREIGN_KEY_CHECKS = 0;'); + $tablesToDelete = join(', ', $tablesToDelete); if ($tablesToDelete != '') { - $dropStatement = $connection->prepare('DROP TABLE ' . $tablesToDelete . ' ;'); - $dropStatement->execute(); + $connection->exec('DROP TABLE ' . $tablesToDelete . ' ;'); $output->writeln(sprintf('Table' . $tablePlural . ' %s has been dropped.', $tablesToDelete)); } @@ -104,6 +104,8 @@ EOT { $output->writeln('No table has been dropped'); } + + $connection->exec('SET FOREIGN_KEY_CHECKS = 1;'); } catch (\Exception $e) {