Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CleanImages.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
12 
13 class CleanImages extends \Magento\Backend\Controller\Adminhtml\Cache implements HttpGetActionInterface
14 {
20  const ADMIN_RESOURCE = 'Magento_Backend::flush_catalog_images';
21 
27  public function execute()
28  {
29  try {
30  $this->_objectManager->create(\Magento\Catalog\Model\Product\Image::class)->clearCache();
31  $this->_eventManager->dispatch('clean_catalog_images_cache_after');
32  $this->messageManager->addSuccessMessage(__('The image cache was cleaned.'));
33  } catch (LocalizedException $e) {
34  $this->messageManager->addErrorMessage($e->getMessage());
35  } catch (\Exception $e) {
36  $this->messageManager->addExceptionMessage($e, __('An error occurred while clearing the image cache.'));
37  }
38 
40  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
41  return $resultRedirect->setPath('adminhtml/*');
42  }
43 }
__()
Definition: __.php:13