/**
  * {@inheritdoc}
  */
 public function thereAreFixtures($fixturesFile, $persister = null)
 {
     if (null === $persister) {
         $persister = $this->persister;
     }
     if (true === is_string($persister)) {
         $persister = $this->castServiceIdToPersister($persister);
     }
     if (0 !== strpos($fixturesFile, '/') && 0 !== strpos($fixturesFile, '@')) {
         $fixturesFile = sprintf('%s/%s', $this->basePath, $fixturesFile);
     }
     $this->loader->load($persister, $this->fixturesFinder->resolveFixtures($this->kernel, [$fixturesFile]));
 }
 /**
  * @param array              $fixturesFiles
  * @param PersisterInterface $persister
  */
 private function loadFixtures($fixturesFiles, $persister = null)
 {
     if (null === $persister) {
         $persister = $this->persister;
     }
     if (true === is_string($persister)) {
         $persister = $this->castServiceIdToPersister($persister);
     }
     foreach ($fixturesFiles as $key => $fixturesFile) {
         if (0 !== strpos($fixturesFile, '/') && 0 !== strpos($fixturesFile, '@')) {
             $fixturesFiles[$key] = sprintf('%s/%s', $this->basePath, $fixturesFile);
         }
     }
     $this->loader->load($persister, $this->fixturesFinder->resolveFixtures($this->kernel, $fixturesFiles));
 }
Exemplo n.º 3
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'));
    }