コード例 #1
0
 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)');
     }
 }
コード例 #2
0
 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')));
 }
コード例 #3
0
 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')));
 }
コード例 #4
0
 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.');
         }
     }
 }
コード例 #5
0
 /**
  * @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());
 }
コード例 #6
0
 public function testRunInstallCommandChooseNothing()
 {
     $application = new Application($this->getClient()->getKernel());
     $application->add(new InstallCommand());
     $application->add(new DropDatabaseDoctrineCommand());
     $application->add(new CreateDatabaseDoctrineCommand());
     // drop database first, so the install command won't ask to reset things
     $command = new DropDatabaseDoctrineCommand();
     $command->setApplication($application);
     $command->run(new ArrayInput(['command' => 'doctrine:database:drop', '--force' => true]), new NullOutput());
     $this->getClient()->getContainer()->get('doctrine')->getConnection()->close();
     $command = new CreateDatabaseDoctrineCommand();
     $command->setApplication($application);
     $command->run(new ArrayInput(['command' => 'doctrine:database:create', '--env' => 'test']), new NullOutput());
     $command = $application->find('wallabag:install');
     // We mock the QuestionHelper
     $question = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\QuestionHelper')->disableOriginalConstructor()->getMock();
     $question->expects($this->exactly(2))->method('ask')->will($this->onConsecutiveCalls(false, false));
     // We override the standard helper with our mock
     $command->getHelperSet()->set($question, 'question');
     $tester = new CommandTester($command);
     $tester->execute(['command' => $command->getName()]);
     $this->assertContains('Checking system requirements.', $tester->getDisplay());
     $this->assertContains('Setting up database.', $tester->getDisplay());
     $this->assertContains('Administration setup.', $tester->getDisplay());
     $this->assertContains('Config setup.', $tester->getDisplay());
     $this->assertContains('Creating schema', $tester->getDisplay());
 }