Sulu\Bundle\RouteBundle\Command\UpdateRouteCommand::execute PHP Метод

execute() защищенный Метод

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)
    {
        $batchSize = $input->getOption('batch-size');
        /** @var EntityManagerInterface $entityManager */
        $entityManager = $this->getContainer()->get('doctrine.orm.entity_manager');
        $routeManager = $this->getContainer()->get('sulu_route.manager.route_manager');
        /** @var EntityRepository $repository */
        $repository = $entityManager->getRepository($input->getArgument('entity'));
        $query = $repository->createQueryBuilder('entity')->select('count(entity.id)')->getQuery();
        $result = $query->getResult();
        $count = (int) $result[0][1];
        $query = $repository->createQueryBuilder('entity')->getQuery();
        $output->writeln(sprintf('<comment>updating route for "%s" instances of "%s"</comment>', $count, $input->getArgument('entity')));
        $progressBar = new ProgressBar($output, $count);
        $progressBar->setFormat('debug');
        $progressBar->display();
        $index = 0;
        foreach ($query->iterate() as $item) {
            $entity = $item[0];
            if (null !== $entity->getRoute()) {
                $routeManager->update($entity);
            } else {
                $entityManager->persist($routeManager->create($entity));
            }
            $progressBar->advance();
            $entity = null;
            if (0 === $index++ % $batchSize) {
                $entityManager->flush();
                // trigger garbage collect
                $entityManager->clear();
            }
        }
        // flush the rest of the entities
        $entityManager->flush();
        //$progressBar->finish();
        $output->writeln('');
    }
UpdateRouteCommand