diff --git a/Command/DatabaseDropCommand.php b/Command/DatabaseDropCommand.php new file mode 100644 index 0000000..9110400 --- /dev/null +++ b/Command/DatabaseDropCommand.php @@ -0,0 +1,64 @@ +setDescription('Drop a given database or the default one.') + ->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action.') + ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use') + ->setHelp(<<propel:database:drop command will drop your database.. + + php app/console propel:insert-sql + +The --force parameter has to be used to actually drop the database. +The --connection parameter allows you to change the connection to use. +The default connection is the active connection (propel.dbal.default_connection). +EOT + ) + ->setName('propel:database:drop'); + } + + /** + * @see Command + * + * @throws \InvalidArgumentException When the target directory does not exist + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + if ($input->getOption('force')) { + list($name, $config) = $this->getConnection($input, $output); + $dbName = $this->parseDbName($config['connection']['dsn']); + $query = 'DROP DATABASE '. $dbName .';'; + + try { + $connection = \Propel::getConnection($name); + $statement = $connection->prepare($query); + //$statement->execute(); + $output->writeln(sprintf('%s has been dropped.', $dbName)); + } catch (Exception $e) { + $output->writeln(sprintf('An error has occured: %s', $e->getMessage())); + } + } else { + $output->writeln('You have to use --force to drop the database.'); + } + } +}