Exemplo n.º 1
0
    /**
     * {@inheritdoc}
     *
     * \RuntimeException Unsupported Application type
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (false !== strpos($input->getFirstArgument(), 'hautelook_alice:fixtures:load') || false !== strpos($input->getFirstArgument(), 'h:f:l')) {
            $output->writeln('<comment>The use of "hautelook_alice:fixtures:load" command is deprecated since 1.0 and will be removed in 2.0. Use the
"hautelook_alice:doctrine:fixtures:load" instead.</comment>');
        }
        // Warn the user that the database will be purged
        // Ask him to confirm his choice
        if ($input->isInteractive() && !$input->getOption('append')) {
            if (false === $this->askConfirmation($input, $output, '<question>Careful, database will be purged. Do you want to continue y/N ?</question>', false)) {
                return;
            }
        }
        $manager = $this->doctrine->getManager($input->getOption('manager'));
        $environment = $input->getOption('env');
        $bundles = $input->getOption('bundle');
        /** @var Application $application */
        $application = $this->getApplication();
        if (false === $application instanceof Application) {
            throw new \RuntimeException('Expected Symfony\\Bundle\\FrameworkBundle\\Console\\Application application.');
        }
        // Get bundles
        if (true === empty($bundles)) {
            $bundles = $application->getKernel()->getBundles();
        } else {
            $bundles = $this->bundlesResolver->resolveBundles($application, $bundles);
        }
        $fixtures = $this->fixturesFinder->getFixtures($application->getKernel(), $bundles, $environment);
        $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', 'fixtures found:'));
        foreach ($fixtures as $fixture) {
            $output->writeln(sprintf('      <comment>-</comment> <info>%s</info>', $fixture));
        }
        $truncate = $input->hasOption('purge-with-truncate') ? $input->getOption('purge-with-truncate') : false;
        // Shard database
        $shard = $input->getOption('shard');
        if (!empty($shard)) {
            $connection = $manager->getConnection();
            if (!$connection instanceof PoolingShardConnection) {
                throw new \RuntimeException('Expected Doctrine\\DBAL\\Sharding\\PoolingShardConnection connection when using shard option.');
            }
            // Switch to shard database
            $connection->connect($shard);
        }
        $this->fixturesExecutor->execute($manager, $this->loaderGenerator->generate($this->loader, $this->fixturesLoader, $bundles, $environment), $fixtures, $input->getOption('append'), function ($message) use($output) {
            $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
        }, $truncate);
        $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', 'fixtures loaded'));
    }
Exemplo n.º 2
0
 /**
  * @param array $bundles
  * @return array
  */
 private function resolveBundles($bundles)
 {
     return $this->fixturesFinder->getFixtures($this->kernel, $this->bundlesResolver->resolveBundles(new Application($this->kernel), $bundles), 'test');
 }