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