protected function execute(InputInterface $input, OutputInterface $output) { $dm = $this->getContainer()->get('doctrine_mongodb')->getManager($input->getOption('dm')); $dirOrFile = $input->getOption('fixtures'); if ($dirOrFile) { $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile); } 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); } } $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')); }
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'; } } $loader = new DataFixturesLoader($this->container); foreach ($paths as $path) { if (is_dir($path)) { $loader->loadFromDirectory($path); } } $fixtures = $loader->getFixtures(); $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')); }
protected function execute(InputInterface $input, OutputInterface $output) { $dmName = $input->getOption('dm'); $dmName = $dmName ? $dmName : 'default'; $dmServiceName = sprintf('doctrine.odm.mongodb.%s_document_manager', $dmName); if (!$this->container->has($dmServiceName)) { throw new InvalidArgumentException(sprintf('Could not find a document manager configured with the name "%s". Check your ' . 'application configuration to configure your Doctrine document managers.', $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'; } } $loader = new DataFixturesLoader($this->container); foreach ($paths as $path) { if (is_dir($path)) { $loader->loadFromDirectory($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')); }
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'; } } $loaderClass = $this->getContainer()->getParameter('doctrine_mongodb.odm.fixture_loader'); $loader = new $loaderClass($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')); }