private function createDatabase() { $command = new CreateDatabaseDoctrineCommand(); $command->setContainer($this->getContainer()); $code = $command->run(new ArrayInput(array()), new NullOutput()); if ($code !== 0) { throw new \Exception('Database cannot be created (existing database must be dropped first)'); } }
protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln(sprintf('<comment>%s - Installing the platform...</comment>', date('H:i:s'))); $databaseCreator = new CreateDatabaseDoctrineCommand(); $databaseCreator->setContainer($this->getContainer()); $databaseCreator->run(new ArrayInput(array()), $output); $verbosityLevelMap = array(LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL, LogLevel::INFO => OutputInterface::VERBOSITY_NORMAL, LogLevel::DEBUG => OutputInterface::VERBOSITY_NORMAL); $consoleLogger = new ConsoleLogger($output, $verbosityLevelMap); /** @var \Claroline\CoreBundle\Library\Installation\PlatformInstaller $installer */ $installer = $this->getContainer()->get('claroline.installation.platform_installer'); $installer->setOutput($output); $installer->setLogger($consoleLogger); $installer->installFromKernel($input->getOption('with-optional-fixtures')); $output->writeln(sprintf('<comment>%s - Platform installed.</comment>', date('H:i:s'))); }
protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln(sprintf('<comment>%s - Updating the platform...</comment>', date('H:i:s'))); $databaseCreator = new CreateDatabaseDoctrineCommand(); $databaseCreator->setContainer($this->getContainer()); $databaseCreator->run(new ArrayInput(array()), $output); $verbosityLevelMap = array(LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL, LogLevel::INFO => OutputInterface::VERBOSITY_NORMAL, LogLevel::DEBUG => OutputInterface::VERBOSITY_NORMAL); $consoleLogger = new ConsoleLogger($output, $verbosityLevelMap); /** @var \Claroline\CoreBundle\Library\Installation\PlatformInstaller $installer */ $installer = $this->getContainer()->get('claroline.installation.platform_installer'); $installer->setOutput($output); $installer->setLogger($consoleLogger); $installer->updateFromComposerInfo(); /** @var \Claroline\CoreBundle\Library\Installation\Refresher $refresher */ $refresher = $this->getContainer()->get('claroline.installation.refresher'); $refresher->dumpAssets($this->getContainer()->getParameter('kernel.environment')); MaintenanceHandler::disableMaintenance(); $output->writeln(sprintf('<comment>%s - Platform updated.</comment>', date('H:i:s'))); }
private function createDatabaseIfNotExists() { try { $this->log('Checking database connection...'); $cn = $this->container->get('doctrine.dbal.default_connection'); // todo: implement a more sophisticated way to test connection, as the // following query works mainly in MySQL, PostgreSQL and MS-Server // see http://stackoverflow.com/questions/3668506/efficient-sql-test-query-or-validation-query-that-will-work-across-all-or-most $cn->query('SELECT 1'); } catch (\Exception $ex) { $this->log('Unable to connect to database: trying to create database...'); $command = new CreateDatabaseDoctrineCommand(); $command->setContainer($this->container); $code = $command->run(new ArrayInput(array()), $this->output ?: new NullOutput()); if ($code !== 0) { throw new \Exception('Database cannot be created : check that the parameters you provided ' . 'are correct and/or that you have sufficient permissions.'); } } }
/** * @param PHPUnit_Framework_TestSuite $suite * * @throws \Doctrine\ORM\Tools\ToolsException */ public function startTestSuite(PHPUnit_Framework_TestSuite $suite) { $kernel = new AppKernel('test', true); // create a "test" kernel $kernel->boot(); $application = new Application($kernel); // add the database:drop command to the application and run it $command = new DropDatabaseDoctrineCommand(); $command->setContainer($kernel->getContainer()); $application->add($command); $input = new ArrayInput(['command' => 'doctrine:database:drop', '--force' => true]); $command->run($input, new ConsoleOutput()); // This stops a bug where Drop Database does not close the handle properly & causes subsequent // "database not found" errors. $connection = $kernel->getContainer()->get('doctrine')->getConnection(); if ($connection->isConnected()) { $connection->close(); } // add the database:create command to the application and run it $command = new CreateDatabaseDoctrineCommand(); $command->setContainer($kernel->getContainer()); $application->add($command); $input = new ArrayInput(['command' => 'doctrine:database:create']); $command->run($input, new ConsoleOutput()); // Run the database migrations, with --quiet because they are quite // chatty on the console. $command = new MigrationsMigrateDoctrineCommand(); $application->add($command); $input = new ArrayInput(['command' => 'doctrine:migrations:migrate', '--quiet' => false, '--no-interaction' => true]); $input->setInteractive(false); $command->run($input, new ConsoleOutput(ConsoleOutput::VERBOSITY_QUIET)); // and load the fixtures $command = new LoadDataFixturesDoctrineCommand(); $command->setContainer($kernel->getContainer()); $application->add($command); $input = new ArrayInput(['command' => 'doctrine:fixtures:load', '--quiet']); $input->setInteractive(false); $command->run($input, new ConsoleOutput()); }