MassRefresh.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Backend\Controller\Adminhtml\Cache;
  8. use Magento\Framework\Exception\LocalizedException;
  9. use Magento\Framework\Controller\ResultFactory;
  10. class MassRefresh extends \Magento\Backend\Controller\Adminhtml\Cache
  11. {
  12. /**
  13. * Authorization level of a basic admin session
  14. *
  15. * @see _isAllowed()
  16. */
  17. const ADMIN_RESOURCE = 'Magento_Backend::refresh_cache_type';
  18. /**
  19. * Mass action for cache refresh
  20. *
  21. * @return \Magento\Backend\Model\View\Result\Redirect
  22. */
  23. public function execute()
  24. {
  25. try {
  26. $types = $this->getRequest()->getParam('types');
  27. $updatedTypes = 0;
  28. if (!is_array($types)) {
  29. $types = [];
  30. }
  31. $this->_validateTypes($types);
  32. foreach ($types as $type) {
  33. $this->_cacheTypeList->cleanType($type);
  34. $updatedTypes++;
  35. }
  36. if ($updatedTypes > 0) {
  37. $this->messageManager->addSuccessMessage(__("%1 cache type(s) refreshed.", $updatedTypes));
  38. }
  39. } catch (LocalizedException $e) {
  40. $this->messageManager->addErrorMessage($e->getMessage());
  41. } catch (\Exception $e) {
  42. $this->messageManager->addExceptionMessage($e, __('An error occurred while refreshing cache.'));
  43. }
  44. /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
  45. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  46. return $resultRedirect->setPath('adminhtml/*');
  47. }
  48. }