MassChangelog.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Indexer\Controller\Adminhtml\Indexer;
  8. use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
  9. class MassChangelog extends \Magento\Indexer\Controller\Adminhtml\Indexer implements HttpPostActionInterface
  10. {
  11. /**
  12. * Turn mview on for the given indexers
  13. *
  14. * @return void
  15. */
  16. public function execute()
  17. {
  18. $indexerIds = $this->getRequest()->getParam('indexer_ids');
  19. if (!is_array($indexerIds)) {
  20. $this->messageManager->addError(__('Please select indexers.'));
  21. } else {
  22. try {
  23. foreach ($indexerIds as $indexerId) {
  24. /** @var \Magento\Framework\Indexer\IndexerInterface $model */
  25. $model = $this->_objectManager->get(
  26. \Magento\Framework\Indexer\IndexerRegistry::class
  27. )->get($indexerId);
  28. $model->setScheduled(true);
  29. }
  30. $this->messageManager->addSuccess(
  31. __('%1 indexer(s) are in "Update by Schedule" mode.', count($indexerIds))
  32. );
  33. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  34. $this->messageManager->addError($e->getMessage());
  35. } catch (\Exception $e) {
  36. $this->messageManager->addException(
  37. $e,
  38. __("We couldn't change indexer(s)' mode because of an error.")
  39. );
  40. }
  41. }
  42. $this->_redirect('*/*/list');
  43. }
  44. }