/** * Toggle cache * */ public function execute() { $allTypes = array_keys($this->_cacheTypeList->getTypes()); $updatedTypes = 0; $disable = true; $enable = true; foreach ($allTypes as $code) { if ($this->_cacheState->isEnabled($code) && $disable) { $this->_cacheState->setEnabled($code, false); $updatedTypes++; $enable = false; } if (!$this->_cacheState->isEnabled($code) && $enable) { $this->_cacheState->setEnabled($code, true); $updatedTypes++; $disable = false; } if ($disable) { $this->_cacheTypeList->cleanType($code); } } if ($updatedTypes > 0) { $this->_cacheState->persist(); $this->messageManager->addSuccess(__("%1 cache type(s) disabled.", $updatedTypes)); } }
/** * Load data * * @param bool $printQuery * @param bool $logQuery * @return $this * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function loadData($printQuery = false, $logQuery = false) { if (!$this->isLoaded()) { foreach ($this->_cacheTypeList->getTypes() as $type) { $this->addItem($type); } $this->_setIsLoaded(true); } return $this; }
/** * Check whether specified cache types exist * * @param array $types * @return void * @throws \Magento\Framework\Exception\LocalizedException */ protected function _validateTypes(array $types) { if (empty($types)) { return; } $allTypes = array_keys($this->_cacheTypeList->getTypes()); $invalidTypes = array_diff($types, $allTypes); if (count($invalidTypes) > 0) { throw new LocalizedException(__('Specified cache type(s) don\'t exist: %1', join(', ', $invalidTypes))); } }
/** * @return array */ public function getAvailableTypes() { $result = []; foreach ($this->cacheTypeList->getTypes() as $type) { $result[] = $type['id']; } return $result; }
/** * @return $this */ public function finish() { $this->_setAppInstalled(); $this->_refreshConfig(); /* Enable all cache types */ foreach (array_keys($this->_cacheTypeList->getTypes()) as $cacheTypeCode) { $this->_cacheState->setEnabled($cacheTypeCode, true); } $this->_cacheState->persist(); return $this; }