diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassDisable.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassDisable.php index 98703f0bfa139..867d1a22ef384 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassDisable.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassDisable.php @@ -26,11 +26,11 @@ public function execute() } $this->_validateTypes($types); foreach ($types as $code) { + $this->_cacheTypeList->cleanType($code); if ($this->_cacheState->isEnabled($code)) { $this->_cacheState->setEnabled($code, false); $updatedTypes++; } - $this->_cacheTypeList->cleanType($code); } if ($updatedTypes > 0) { $this->_cacheState->persist(); diff --git a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassRefresh.php b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassRefresh.php index 420d8757e5bb2..85adf2c382578 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassRefresh.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/Cache/MassRefresh.php @@ -27,7 +27,6 @@ public function execute() $this->_validateTypes($types); foreach ($types as $type) { $this->_cacheTypeList->cleanType($type); - $this->_eventManager->dispatch('adminhtml_cache_refresh_type', ['type' => $type]); $updatedTypes++; } if ($updatedTypes > 0) { diff --git a/app/code/Magento/PageCache/Model/Cache/Type.php b/app/code/Magento/PageCache/Model/Cache/Type.php index d1e6df21888d5..8366e17ad8501 100644 --- a/app/code/Magento/PageCache/Model/Cache/Type.php +++ b/app/code/Magento/PageCache/Model/Cache/Type.php @@ -19,11 +19,33 @@ class Type extends \Magento\Framework\Cache\Frontend\Decorator\TagScope */ const CACHE_TAG = 'FPC'; + /** + * @var \Magento\Framework\Event\ManagerInterface + */ + private $eventManager; + /** * @param \Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool + * @param \Magento\Framework\Event\ManagerInterface $eventManager */ - public function __construct(\Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool) - { + public function __construct( + \Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool, + \Magento\Framework\Event\ManagerInterface $eventManager + ) { parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG); + $this->eventManager = $eventManager; + } + + /** + * {@inheritdoc} + * + * @param string $mode + * @param array $tags + * @return bool + */ + public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, array $tags = []) + { + $this->eventManager->dispatch('adminhtml_cache_refresh_type'); + return parent::clean($mode, $tags); } } diff --git a/app/code/Magento/PageCache/Test/Unit/Model/Cache/TypeTest.php b/app/code/Magento/PageCache/Test/Unit/Model/Cache/TypeTest.php new file mode 100644 index 0000000000000..1b1dcdfb41140 --- /dev/null +++ b/app/code/Magento/PageCache/Test/Unit/Model/Cache/TypeTest.php @@ -0,0 +1,51 @@ +eventManagerMock = $this->getMockBuilder('Magento\Framework\Event\ManagerInterface') + ->disableOriginalConstructor() + ->getMock(); + $this->cacheFrontendPoolMock = $this->getMockBuilder('Magento\Framework\App\Cache\Type\FrontendPool') + ->disableOriginalConstructor() + ->getMock(); + $cacheFrontend = $this->getMockBuilder('Magento\Framework\Cache\FrontendInterface') + ->disableOriginalConstructor() + ->getMock(); + $this->cacheFrontendPoolMock->expects($this->once()) + ->method('get') + ->willReturn($cacheFrontend); + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->model = $objectManager->getObject( + 'Magento\PageCache\Model\Cache\Type', + [ + 'eventManager' => $this->eventManagerMock, + 'cacheFrontendPool' => $this->cacheFrontendPoolMock, + ] + ); + } + + public function testClean() + { + $this->eventManagerMock->expects($this->once()) + ->method('dispatch') + ->with('adminhtml_cache_refresh_type'); + + $this->model->clean(); + } +} diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index c3b0b306b14be..a84de426be517 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -956,8 +956,8 @@ public function uninstall() { $this->log->log('Starting Magento uninstallation:'); - $this->cleanupDb(); $this->cleanCaches(); + $this->cleanupDb(); $this->log->log('File system cleanup:'); $messages = $this->cleanupFiles->clearAllFiles(); diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 0364f22e3b400..c8741286da0eb 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -390,7 +390,7 @@ public function testUninstall() ])); $this->logger->expects($this->at(0))->method('log')->with('Starting Magento uninstallation:'); $this->logger - ->expects($this->at(1)) + ->expects($this->at(2)) ->method('log') ->with('No database connection defined - skipping database cleanup'); $cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); @@ -400,7 +400,7 @@ public function testUninstall() ->method('get') ->with('Magento\Framework\App\Cache\Manager') ->willReturn($cacheManager); - $this->logger->expects($this->at(2))->method('log')->with('Cache cleared successfully'); + $this->logger->expects($this->at(1))->method('log')->with('Cache cleared successfully'); $this->logger->expects($this->at(3))->method('log')->with('File system cleanup:'); $this->logger ->expects($this->at(4)) @@ -494,7 +494,7 @@ private function prepareForUpdateModulesTests() /** * Mocking autoload function - * + * * @returns array */ function spl_autoload_functions()