Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. <?php
  2. namespace Nomerogram\Console\Command\Base;
  3.  
  4. use Propel\Runtime\Exception\PropelException;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. use Symfony\Component\Console\Question\ConfirmationQuestion;
  8.  
  9. /**
  10. * Для команд, в которых
  11. * выборка из бд не по промежутку а по limit'у
  12. * Class AbstractPhotoRunnerCommandModified
  13. *
  14. * @package Nomerogram\Console\Command\Base
  15. */
  16. abstract class AbstractPhotoRunnerCommandModified extends AbstractRunnerCommand
  17. {
  18. /**
  19. * @param InputInterface $input
  20. * @param OutputInterface $output
  21. *
  22. * @throws PropelException
  23. */
  24. private function reindexAll(InputInterface $input, OutputInterface $output)
  25. {
  26. $config = $this->getConfig($input);
  27.  
  28. if (!$this->askConfirmation($config, $input, $output)) {
  29. return;
  30. }
  31.  
  32. $left = $config['from'];
  33. $right = min($left + $config['batch'] - 1, $config['to']);
  34.  
  35. while ($left <= $config['to']) {
  36. $ids = $this->getBatchIds($left, $right, $config)->toArray();
  37.  
  38. $count = count($ids);
  39. $right = end($ids);
  40.  
  41. $output->writeln("Found {$count} at [$left, $right]");
  42.  
  43. if ($count > 0) {
  44. try {
  45. $this->processBatch($ids, $config, $output);
  46. } catch (\Exception $exception) {
  47. $output->writeln('<fg=red>' . $exception->getMessage() . '</>');
  48. }
  49. }
  50. $left = $right;
  51. }
  52. }
  53.  
  54. /**
  55. * @param array $config
  56. * @param InputInterface $input
  57. * @param OutputInterface $output
  58. *
  59. * @return bool
  60. */
  61. private function askConfirmation(array $config, InputInterface $input, OutputInterface $output)
  62. {
  63. $this->writeConfigInfo($config, $output);
  64.  
  65. $helper = $this->getHelper('question');
  66. $question = new ConfirmationQuestion('Continue with this action? [y/N] ', false);
  67.  
  68. if (!$helper->ask($input, $output, $question)) {
  69. return false;
  70. }
  71. return true;
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement