-
-
Save ryaan-anthony/501565598bcba7e50223 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Clear cache cli style | |
* | |
* | |
* @category Mage | |
* @package Mage_Shell | |
* @copyright Copyright (c) 2015 Bjarne Oeverli (http://bjarneo.codes) | |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | |
*/ | |
require_once 'abstract.php'; | |
/** | |
* Magento Cache Shell Script | |
* | |
* @category Mage | |
* @package Mage_Shell | |
* @author Bjarne Oeverli <bjarne.oeverli@gmail.com> | |
*/ | |
class Mage_Shell_Cache extends Mage_Shell_Abstract | |
{ | |
/** | |
* Get Mage app | |
* | |
*/ | |
private function _getApp() | |
{ | |
return Mage::app(); | |
} | |
/** | |
* Run script | |
* | |
*/ | |
public function run() | |
{ | |
if ($this->getArg('clear')) { | |
if ($cache = $this->_getApp()->getCache()) { | |
$cache->clean(); | |
echo 'Cache cleared'.PHP_EOL; | |
} | |
} elseif ($this->getArg('enable')) { | |
$this->toggleCache(true); | |
echo 'Cache enabled'.PHP_EOL; | |
} elseif ($this->getArg('disable')) { | |
$this->toggleCache(false); | |
echo 'Cache disabled'.PHP_EOL; | |
} else { | |
echo $this->usageHelp(); | |
} | |
} | |
/** | |
* Enable/disable caches | |
* | |
* @param boolean $enable | |
*/ | |
protected function toggleCache($enable) | |
{ | |
$caches = $this->_getApp()->useCache(); | |
foreach($caches as $cache => $status){ | |
if($status != $enable) $caches[$cache] = $enable; | |
} | |
$this->_getApp()->saveUseCache($caches); | |
} | |
/** | |
* Retrieve Usage Help Message | |
* | |
*/ | |
public function usageHelp() | |
{ | |
return <<<USAGE | |
Usage: php cache.php -- [options] | |
clear Clear cache | |
enable Enable cache | |
disable Disable cache | |
help This help | |
USAGE; | |
} | |
} | |
$shell = new Mage_Shell_Cache(); | |
$shell->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment