Sulu\Bundle\ContactBundle\Command\AccountRecoverCommand::execute PHP Метод

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

Execute command.
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)
    {
        $em = $this->getEntityManager();
        $force = $input->getOption('force');
        $fixDepth = $input->getOption('fix-depth');
        $repo = $this->getEntityRepository();
        $verify = $repo->verify();
        $success = false;
        // fix nested tree
        if ($verify !== true) {
            $output->writeln(sprintf('<comment>%s errors were found.</comment>', count($verify)));
            if ($force) {
                $repo->recover();
                $em->flush();
                $success = true;
            }
        } else {
            $output->writeln('<info>Your tree is fine. No errors found.<info>');
        }
        // fix depths if -depth is defined
        if ($fixDepth) {
            // fix nodes without parents
            $numberParentLess = $this->findNodesWithoutParents();
            if ($numberParentLess > 0) {
                $output->writeln(sprintf('<comment>%s nodes without parent were found.</comment>', $numberParentLess));
                if ($force) {
                    $this->fixNodesWithoutParents();
                    $success = true;
                    $em->flush();
                }
            } else {
                $output->writeln('<info>No wrong depth gaps detected<info>');
            }
            // fix depth gaps
            $numberWrongDepth = $this->findInitialWrongDepthGap();
            if ($numberWrongDepth > 0) {
                $output->writeln(sprintf('<comment>%s wrong depths were found.</comment>', $numberWrongDepth));
                if ($force) {
                    // update depths
                    $affected = 1;
                    while ($affected > 0) {
                        $affected = $this->fixWrongDepthGap();
                    }
                    $success = true;
                    $em->flush();
                }
            } else {
                $output->writeln('<info>No nodes without parents detected<info>');
            }
        }
        if (!$force) {
            $output->writeln(sprintf('Call this command with <info>--force</info> option to perform recovery.'));
        }
        if ($success === true) {
            $output->writeln('<info>Recovery complete<info>');
        }
    }