Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Nomerogram\Console\Command\Base;
- use Propel\Runtime\Exception\PropelException;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- use Symfony\Component\Console\Question\ConfirmationQuestion;
- /**
- * Для команд, в которых
- * выборка из бд не по промежутку а по limit'у
- * Class AbstractPhotoRunnerCommandModified
- *
- * @package Nomerogram\Console\Command\Base
- */
- abstract class AbstractPhotoRunnerCommandModified extends AbstractRunnerCommand
- {
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- *
- * @throws PropelException
- */
- private function reindexAll(InputInterface $input, OutputInterface $output)
- {
- $config = $this->getConfig($input);
- if (!$this->askConfirmation($config, $input, $output)) {
- return;
- }
- $left = $config['from'];
- $right = min($left + $config['batch'] - 1, $config['to']);
- while ($left <= $config['to']) {
- $ids = $this->getBatchIds($left, $right, $config)->toArray();
- $count = count($ids);
- $right = end($ids);
- $output->writeln("Found {$count} at [$left, $right]");
- if ($count > 0) {
- try {
- $this->processBatch($ids, $config, $output);
- } catch (\Exception $exception) {
- $output->writeln('<fg=red>' . $exception->getMessage() . '</>');
- }
- }
- $left = $right;
- }
- }
- /**
- * @param array $config
- * @param InputInterface $input
- * @param OutputInterface $output
- *
- * @return bool
- */
- private function askConfirmation(array $config, InputInterface $input, OutputInterface $output)
- {
- $this->writeConfigInfo($config, $output);
- $helper = $this->getHelper('question');
- $question = new ConfirmationQuestion('Continue with this action? [y/N] ', false);
- if (!$helper->ask($input, $output, $question)) {
- return false;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement