IndexerResetStateCommand.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Indexer\Console\Command;
  7. use Magento\Framework\Exception\LocalizedException;
  8. use Magento\Framework\Indexer\StateInterface;
  9. use Symfony\Component\Console\Input\InputInterface;
  10. use Symfony\Component\Console\Output\OutputInterface;
  11. use Magento\Framework\Indexer\ConfigInterface;
  12. /**
  13. * Command for invalidating indexers.
  14. */
  15. class IndexerResetStateCommand extends AbstractIndexerManageCommand
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. protected function configure()
  21. {
  22. $this->setName('indexer:reset')
  23. ->setDescription('Resets indexer status to invalid')
  24. ->setDefinition($this->getInputList());
  25. parent::configure();
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. protected function execute(InputInterface $input, OutputInterface $output)
  31. {
  32. $indexers = $this->getIndexers($input);
  33. foreach ($indexers as $indexer) {
  34. try {
  35. $indexer->getState()
  36. ->setStatus(\Magento\Framework\Indexer\StateInterface::STATUS_INVALID)
  37. ->save();
  38. $output->writeln($indexer->getTitle() . ' indexer has been invalidated.');
  39. } catch (LocalizedException $e) {
  40. $output->writeln($e->getMessage());
  41. } catch (\Exception $e) {
  42. $output->writeln($indexer->getTitle() . ' indexer process unknown error:');
  43. $output->writeln($e->getMessage());
  44. }
  45. }
  46. }
  47. }