diff -r 000000000000 -r 7f95f8617b0b vendor/symfony/src/Symfony/Bundle/DoctrineBundle/Command/CreateDatabaseDoctrineCommand.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/symfony/src/Symfony/Bundle/DoctrineBundle/Command/CreateDatabaseDoctrineCommand.php Sat Sep 24 15:40:41 2011 +0200 @@ -0,0 +1,68 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\DoctrineBundle\Command; + +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Doctrine\DBAL\DriverManager; + +/** + * Database tool allows you to easily drop and create your configured databases. + * + * @author Fabien Potencier + * @author Jonathan H. Wage + */ +class CreateDatabaseDoctrineCommand extends DoctrineCommand +{ + protected function configure() + { + $this + ->setName('doctrine:database:create') + ->setDescription('Create the configured databases') + ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command') + ->setHelp(<<doctrine:database:create command creates the default +connections database: + +php app/console doctrine:database:create + +You can also optionally specify the name of a connection to create the +database for: + +php app/console doctrine:database:create --connection=default +EOT + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $connection = $this->getDoctrineConnection($input->getOption('connection')); + + $params = $connection->getParams(); + $name = isset($params['path']) ? $params['path'] : $params['dbname']; + + unset($params['dbname']); + + $tmpConnection = DriverManager::getConnection($params); + + try { + $tmpConnection->getSchemaManager()->createDatabase($name); + $output->writeln(sprintf('Created database for connection named %s', $name)); + } catch (\Exception $e) { + $output->writeln(sprintf('Could not create database for connection named %s', $name)); + $output->writeln(sprintf('%s', $e->getMessage())); + } + + $tmpConnection->close(); + } +}