I am trying to create an installation Bundle for my Symfony 2.2.3 application. Therefore I want to drop/create a database (mysql) and then create the schema via Controller Actions.
My Code:
$kernel = $this->get('kernel');
$application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
$application->setAutoExit(false);
// drop old database
$options = array('command' => 'doctrine:database:drop', '--force' => true);
$application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
// create new database
$options = array('command' => 'doctrine:database:create');
$result = $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
// check if database:create was successful, then create schema
if($result == 0) {
$options = array('command' => 'doctrine:schema:create');
$result = $application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
}
database:drop and database:create work fine (both commands return 0), but creating the schema then fails.
However, when I comment the first 2 commands out so that only doctrine:schema:create will be executed (if clause removed, of course) and reload the page without changing anything else the database schema will be created properly.
Can anyone tell me what the problem is?
newand\Symfony\Component\Console\Input\ArrayInput($options)line 16