protected function execute(InputInterface $input, OutputInterface $output) { /** @var $doctrine \Doctrine\Common\Persistence\ManagerRegistry */ $doctrine = $this->getContainer()->get('doctrine'); $em = $doctrine->getManager($input->getOption('em')); if ($input->isInteractive() && !$input->getOption('append')) { if (!$this->askConfirmation($input, $output, '<question>Careful, database will be purged. Do you want to continue y/N ?</question>', false)) { return; } } if ($input->getOption('shard')) { if (!$em->getConnection() instanceof PoolingShardConnection) { throw new \LogicException(sprintf("Connection of EntityManager '%s' must implement shards configuration.", $input->getOption('em'))); } $em->getConnection()->connect($input->getOption('shard')); } $dirOrFile = $input->getOption('fixtures'); if ($dirOrFile) { $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile); } else { $paths = array(); foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) { $paths[] = $bundle->getPath() . '/DataFixtures/ORM'; } } $loader = new DataFixturesLoader($this->getContainer()); foreach ($paths as $path) { if (is_dir($path)) { $loader->loadFromDirectory($path); } elseif (is_file($path)) { $loader->loadFromFile($path); } } $fixtures = $loader->getFixtures(); if (!$fixtures) { throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths))); } $purger = new ORMPurger($em); $purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE); $executor = new ORMExecutor($em, $purger); $executor->setLogger(function ($message) use($output) { $output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message)); }); $executor->execute($fixtures, $input->getOption('append'), $input->getOption('multiple-transactions')); }
protected function execute(InputInterface $input, OutputInterface $output) { $dm = $this->getContainer()->get('doctrine_mongodb')->getManager($input->getOption('dm')); $dirOrFile = $input->getOption('fixtures'); $bundles = $input->getOption('bundles'); if ($bundles && $dirOrFile) { throw new \InvalidArgumentException('Use only one option: --bundles or --fixtures.'); } if ($input->isInteractive() && !$input->getOption('append')) { $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('Careful, database will be purged. Do you want to continue (y/N) ?', false); if (!$helper->ask($input, $output, $question)) { return; } } if ($dirOrFile) { $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile); } elseif ($bundles) { $kernel = $this->getContainer()->get('kernel'); foreach ($bundles as $bundle) { $paths[] = $kernel->getBundle($bundle)->getPath(); } } else { $paths = $this->getContainer()->getParameter('doctrine_mongodb.odm.fixtures_dirs'); $paths = is_array($paths) ? $paths : array($paths); foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) { $paths[] = $bundle->getPath() . '/DataFixtures/MongoDB'; } } $loader = new ContainerAwareLoader($this->getContainer()); foreach ($paths as $path) { if (is_dir($path)) { $loader->loadFromDirectory($path); } else { if (is_file($path)) { $loader->loadFromFile($path); } } } $fixtures = $loader->getFixtures(); if (!$fixtures) { throw new \InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths))); } $purger = new MongoDBPurger($dm); $executor = new MongoDBExecutor($dm, $purger); $executor->setLogger(function ($message) use($output) { $output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message)); }); $executor->execute($fixtures, $input->getOption('append')); }