Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function generate(LoaderInterface $loader, FixturesLoaderInterface $fixturesLoader, array $bundles, $environment)
 {
     $doctrineDataLoaders = $this->fixturesFinder->getDataLoaders($bundles, $environment);
     $_fixturesLoader = clone $fixturesLoader;
     $_fixturesLoader->addProvider($doctrineDataLoaders);
     return new Loader($_fixturesLoader, $loader->getProcessors(), $loader->getPersistOnce());
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function generate(LoaderInterface $loader, FixturesLoaderInterface $fixturesLoader, array $bundles, $environment)
 {
     if (!$loader instanceof Loader) {
         throw new \UnexpectedValueException('Unsupported loader for this generator. Must be an instance of Hautelook\\AliceBundle\\Alice\\DataFixtures\\Loader.');
     }
     $doctrineDataLoaders = $this->fixturesFinder->getDataLoaders($bundles, $environment);
     $_fixturesLoader = clone $fixturesLoader;
     $_fixturesLoader->addProvider($doctrineDataLoaders);
     return new Loader($_fixturesLoader, $loader->getProcessorChain(), $loader->getPersistOnce(), $loader->getLoadingLimit());
 }
Ejemplo n.º 3
0
 /**
  * @param ExecutorInterface $executor
  * @param ObjectManager     $manager
  * @param LoaderInterface   $loader
  * @param string[]          $fixtures Real path to fixtures files
  * @param bool              $append
  */
 private function executeExecutor(ExecutorInterface $executor, ObjectManager $manager, LoaderInterface $loader, array $fixtures, $append = false)
 {
     $function = function (ObjectManager $manager) use($executor, $loader, $fixtures, $append) {
         if (false === $append) {
             $executor->purge();
         }
         $loader->load(new Doctrine($manager), $fixtures);
     };
     if (method_exists($manager, 'transactional')) {
         $manager->transactional($function);
     } else {
         $function($manager);
     }
 }
 /**
  * {@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));
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  *
  * \RuntimeException Unsupported Application type
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var Application $application */
     $application = $this->getApplication();
     if (false === $application instanceof Application) {
         throw new \RuntimeException('Expected Symfony\\Bundle\\FrameworkBundle\\Console\\Application application.');
     }
     $environment = $input->getOption('env');
     $manager = $this->doctrine->getManager($input->getOption('manager'));
     // 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;
         }
     }
     // Get bundles
     $bundles = $input->getOption('bundle');
     if (true === empty($bundles)) {
         $bundles = $application->getKernel()->getBundles();
     } else {
         $bundles = $this->finder->resolveBundles($application, $bundles);
     }
     // Get fixtures
     $fixtures = $this->finder->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));
     }
     // Get data loaders to generate the new loader
     // Have to create a new one to add each data loader as a provider
     $loaders = $this->finder->getDataLoaders($bundles, $environment);
     $newLoader = new Loader(new ProcessorChain($this->loader->getProcessors()), new ProviderChain(array_merge($this->loader->getOptions()['providers'], $loaders)), $this->loader->getOptions()['locale'], $this->loader->getOptions()['seed'], $this->loader->getOptions()['persist_once'], true === isset($this->loader->getOptions()['logger']) ? $this->loader->getOptions()['logger'] : null);
     // Get executor
     $purger = new ORMPurger($manager);
     $purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
     $executor = new ORMExecutor($manager, $newLoader, $purger);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     // Purge database and load fixtures
     $executor->execute($fixtures, $input->getOption('append'));
     $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', 'fixtures loaded'));
 }