protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dmName = $input->getOption('dm');
     $dmName = $dmName ? $dmName : 'default';
     $dmServiceName = sprintf('doctrine.odm.mongodb.%s_document_manager', $dmName);
     $dm = $this->container->get($dmServiceName);
     $dirOrFile = $input->getOption('fixtures');
     if ($dirOrFile) {
         $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
     } else {
         $paths = array();
         $bundleDirs = $this->container->getKernelService()->getBundleDirs();
         foreach ($this->container->getKernelService()->getBundles() as $bundle) {
             $tmp = dirname(str_replace('\\', '/', get_class($bundle)));
             $namespace = str_replace('/', '\\', dirname($tmp));
             $class = basename($tmp);
             if (isset($bundleDirs[$namespace]) && is_dir($dir = $bundleDirs[$namespace] . '/' . $class . '/DataFixtures/MongoDB')) {
                 $paths[] = $dir;
             }
         }
     }
     $loader = new \Doctrine\Common\DataFixtures\Loader();
     foreach ($paths as $path) {
         $loader->loadFromDirectory($path);
     }
     $fixtures = $loader->getFixtures();
     $purger = new \Doctrine\Common\DataFixtures\Purger\MongoDBPurger($dm);
     $executor = new \Doctrine\Common\DataFixtures\Executor\MongoDBExecutor($dm, $purger);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     $executor->execute($fixtures, $input->getOption('append'));
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dmName = $input->getOption('dm');
     $dmName = $dmName ? $dmName : 'default';
     $dmServiceName = sprintf('doctrine.odm.mongodb.%s_document_manager', $dmName);
     $dm = $this->container->get($dmServiceName);
     $dirOrFile = $input->getOption('fixtures');
     if ($dirOrFile) {
         $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
     } else {
         $paths = array();
         foreach ($this->container->get('kernel')->getBundles() as $bundle) {
             $paths[] = $bundle->getPath() . '/DataFixtures/MongoDB';
         }
     }
     $paths = array_filter($paths, 'is_dir');
     $loader = new \Doctrine\Common\DataFixtures\Loader();
     foreach ($paths as $path) {
         $loader->loadFromDirectory($path);
     }
     $fixtures = $loader->getFixtures();
     $purger = new \Doctrine\Common\DataFixtures\Purger\MongoDBPurger($dm);
     $executor = new \Doctrine\Common\DataFixtures\Executor\MongoDBExecutor($dm, $purger);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     $executor->execute($fixtures, $input->getOption('append'));
 }
Exemple #3
0
 /**
  * Autoloads the fixtures passed in the static array $fixtures
  *
  * @param boolean $append        Does it append fixtures
  * @param array   $options       The options
  * @param array   $kernelOptions The options to pass to `WebTestCase::createKernel()`
  *
  * TODO: Add support for other Entity/Document managers
  *
  * @return void
  */
 public function loadFixtures($append = false, array $options = array(), array $kernelOptions = array())
 {
     if (null !== static::$kernel) {
         static::$kernel->shutdown();
     }
     static::$kernel = static::createKernel($kernelOptions);
     static::$kernel->boot();
     static::$dm = static::$kernel->getContainer()->get('doctrine.odm.mongodb.document_manager');
     $loader = new Loader();
     foreach ($this->getDataFixturesPaths() as $path) {
         $loader->loadFromDirectory($path);
     }
     $fixtures = $loader->getFixtures();
     $purger = new \Doctrine\Common\DataFixtures\Purger\MongoDBPurger(static::$dm);
     $executor = new \Doctrine\Common\DataFixtures\Executor\MongoDBExecutor(static::$dm, $purger);
     $executor->execute($fixtures, $append);
 }