Knp\Bundle\KnpBundlesBundle\Command\KbSolrIndexCommand::execute PHP Method

execute() protected method

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (!$input->getOption('skip-server-check') && !$this->getContainer()->get('knp_bundles.utils.solr')->isSolrRunning()) {
            $output->writeln('<error>Solr is NOT running. Please start server first!</error>');
            return 1;
        }
        $verbose = $input->getOption('verbose');
        $force = $input->getOption('force');
        $bundleName = $input->getArgument('bundleName');
        $doctrine = $this->getContainer()->get('doctrine');
        /** @var $indexer \Knp\Bundle\KnpBundlesBundle\Indexer\SolrIndexer */
        $indexer = $this->getContainer()->get('knp_bundles.indexer.solr');
        if ($verbose) {
            $output->writeln($bundleName ? 'Getting bundle (' . $bundleName . ') data to re-index.' : 'Getting bundles data to re-index.');
        }
        if ($bundleName) {
            list($ownerName, $name) = explode('/', $bundleName);
            $bundles = array($doctrine->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\Bundle')->findOneByOwnerNameAndName($ownerName, $name));
        } elseif ($force) {
            $bundles = $doctrine->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\Bundle')->findAll();
        } else {
            $bundles = $doctrine->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\Bundle')->getStaleBundlesForIndexing();
        }
        if ($force) {
            if ($verbose) {
                $output->writeln('Deleting existing index.');
            }
            $indexer->deleteBundlesIndexes($bundleName ? current($bundles) : null);
        }
        /* @var $bundle Bundle */
        foreach ($bundles as $key => $bundle) {
            $this->reindex($bundle, $indexer, $output, $verbose);
            unset($bundles[$key]);
        }
        $doctrine->getManager()->flush();
        return 0;
    }