protected function loadFixtures(array $fixtures)
 {
     /** @var PHPCR $dbManager */
     $dbManager = $this->getDbManager('PHPCR');
     $loader = new ContainerAwareLoader($this->getContainer());
     foreach ($fixtures as $className) {
         $dbManager->loadFixtureClass($loader, $className);
     }
     $purger = new PHPCRPurger();
     $executor = new PHPCRExecutor($dbManager->getOm(), $purger);
     $referenceRepository = new ProxyReferenceRepository($dbManager->getOm());
     $executor->setReferenceRepository($referenceRepository);
     $executor->execute($loader->getFixtures(), true);
     $dbManager->getOm()->clear();
 }
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('name')) {
         trigger_error('The name attribute for command doctrine:phpcr:fixtures:load is deprecated. It was never used.', E_USER_DEPRECATED);
     }
     if ($input->getOption('dm')) {
         $dmName = $input->getOption('dm');
     } else {
         if ($input->getOption('session')) {
             $dmName = $input->getOption('session');
             trigger_error('The session attribute for command doctrine:phpcr:fixtures:load is deprecated. Use --dm instead.', E_USER_DEPRECATED);
         } else {
             $dmName = null;
         }
     }
     DoctrineCommandHelper::setApplicationDocumentManager($this->getApplication(), $dmName);
     $dm = $this->getHelperSet()->get('phpcr')->getDocumentManager();
     $noInitialize = $input->getOption('no-initialize');
     if ($input->isInteractive() && !$input->getOption('append')) {
         /** @var $dialog DialogHelper */
         $dialog = $this->getHelperSet()->get('dialog');
         if (!$dialog->askConfirmation($output, '<question>Careful, database will be purged. Do you want to continue Y/N ?</question>', false)) {
             return 0;
         }
     }
     $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/PHPCR';
         }
     }
     $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 PHPCRPurger($dm);
     if ($noInitialize) {
         $initializerManager = null;
     } else {
         $initializerManager = $this->getContainer()->get('doctrine_phpcr.initializer_manager');
     }
     $executor = new PHPCRExecutor($dm, $purger, $initializerManager);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     $executor->execute($fixtures, $input->getOption('append'));
     return 0;
 }
Exemple #3
0
 /**
  * Return the PHPCR Executor class.
  *
  * @return PHPCRExecutor
  */
 private function getExecutor($initialize = false)
 {
     static $lastInitialize = null;
     if ($this->executor && $initialize === $lastInitialize) {
         return $this->executor;
     }
     $initializerManager = $initialize ? $this->container->get('doctrine_phpcr.initializer_manager') : null;
     $purger = new PHPCRPurger();
     $executor = new PHPCRExecutor($this->getOm(), $purger, $initializerManager);
     $referenceRepository = new ProxyReferenceRepository($this->getOm());
     $executor->setReferenceRepository($referenceRepository);
     $this->executor = $executor;
     $lastInitialize = $initialize;
     return $executor;
 }