Skip to content

Instantly share code, notes, and snippets.

@angelo510
Created January 19, 2017 17:18
Show Gist options
  • Save angelo510/3c88b87da0655ebd156e4cff8595d062 to your computer and use it in GitHub Desktop.
Save angelo510/3c88b87da0655ebd156e4cff8595d062 to your computer and use it in GitHub Desktop.
Magento Resize Image
<?php
namespace EShop\ImageResizer\Controller\Adminhtml\Cache;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Controller\Adminhtml\Cache as MagentoAdminCache;
use Magento\Framework\App\Cache\Frontend\Pool;
use Magento\Framework\App\Cache\StateInterface;
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\View\Result\PageFactory;
use Staempfli\ImageResizer\Helper\Cache as ResizerCacheHelper;
class CleanResizedImages extends MagentoAdminCache
{
public function __construct(
ResizerCacheHelper $resizerCacheHelper,
Context $context,
TypeListInterface $cacheTypeList,
StateInterface $cacheState,
Pool $cacheFrontendPool,
PageFactory $resultPageFactory
) {
parent::__construct($context, $cacheTypeList, $cacheState, $cacheFrontendPool, $resultPageFactory);
$this->resizerCacheHelper = $resizerCacheHelper;
}
public function execute()
{
try {
$this->resizerCacheHelper->clearResizedImagesCache();
$this->_eventManager->dispatch('staempfli_imageresizer_clean_images_cache_after');
$this->messageManager->addSuccessMessage(__('The resized images cache was cleaned.'));
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addExceptionMessage($e, __('An error occurred while clearing the resized images cache.'));
}
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('adminhtml/cache');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment