Skip to content
This repository was archived by the owner on Sep 12, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/code/local/Aoe/ClassPathCache/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,18 @@ public function getUrl()
));
}

/**
* return in the admin area the url for cleanup
*
* @return string|boolean
*/
public function getAdminUrl()
{
if(Mage::app()->getStore()->isAdmin())
{
return Mage::helper('adminhtml')->getUrl('adminhtmlcpc/index/clear');
}
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
+<?php
/**
* Class path cache controller for adminhtml
*
* @author Mathis Klooss
* @since 2013-05-23
*/
class Aoe_ClassPathCache_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
/**
* Clear classpathcache
*
* @return void
*/
public function clearAction()
{
$success = true;
$this->_helper()->revalidateCache();
// check also frontend
$response = file_get_contents($this->_helper()->getUrl());
if ($response != 'OK') {
$success = false;
}
// set message
if($success)
{
$this->_session()->addSuccess($this->_helper()->__('the classpath cache was cleaned.'));
} else {
$this->_session()->addError($this->_helper()->__('could not clear classpath cache.'));
}
// redirect to referrer
$this->_redirectReferer();
}

/**
* class path helper
*
* @return Aoe_ClassPathCache_Helper_Data
*/
protected function _helper()
{
return Mage::helper('aoe_classpathcache');
}

/**
* adminhtml session
*
* @return Mage_Adminhtml_Model_Session
*/
protected function _session()
{
return Mage::getSingleton('adminhtml/session');
}
}
79 changes: 45 additions & 34 deletions app/code/local/Aoe/ClassPathCache/etc/config.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,52 @@
<?xml version="1.0"?>
<config>

<modules>
<Aoe_ClassPathCache>
<version>0.4.0</version>
</Aoe_ClassPathCache>
</modules>
<modules>
<Aoe_ClassPathCache>
<version>0.4.0</version>
</Aoe_ClassPathCache>
</modules>

<global>
<helpers>
<aoe_classpathcache>
<class>Aoe_ClassPathCache_Helper</class>
</aoe_classpathcache>
</helpers>
</global>
<global>
<helpers>
<aoe_classpathcache>
<class>Aoe_ClassPathCache_Helper</class>
</aoe_classpathcache>
</helpers>
</global>

<frontend>
<routers>
<aoe_classpathcache>
<use>standard</use>
<args>
<module>Aoe_ClassPathCache</module>
<frontName>aoeclasspathcache</frontName>
</args>
</aoe_classpathcache>
</routers>
</frontend>
<frontend>
<routers>
<aoe_classpathcache>
<use>standard</use>
<args>
<module>Aoe_ClassPathCache</module>
<frontName>aoeclasspathcache</frontName>
</args>
</aoe_classpathcache>
</routers>
</frontend>

<adminhtml>
<layout>
<updates>
<aoe_classpathcache>
<file>aoe_classpathcache/aoe_classpathcache.xml</file>
</aoe_classpathcache>
</updates>
</layout>
</adminhtml>

<admin>
<routers>
<adminhtmlcpc>
<use>admin</use>
<args>
<module>Aoe_ClassPathCache_Adminhtml</module>
<frontName>adminhtmlcpc</frontName>
</args>
</adminhtmlcpc>
</routers>
</admin>

<adminhtml>
<layout>
<updates>
<aoe_classpathcache>
<file>aoe_classpathcache/aoe_classpathcache.xml</file>
</aoe_classpathcache>
</updates>
</layout>
</adminhtml>


</config>
27 changes: 25 additions & 2 deletions app/code/local/Varien/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Varien_Autoload
static protected $_numberOfFilesAddedToCache = 0;

static public $useAPC = NULL;
static public $useXCACHE = NULL;
static protected $cacheKey = self::CACHE_KEY_PREFIX;

/* Base Path */
Expand All @@ -37,7 +38,10 @@ public function __construct()
}

// Allow APC to be disabled externally by explicitly setting Varien_Autoload::$useAPC = FALSE;
if (self::$useAPC === NULL) {
if (self::$useXCACHE === NULL) {
self::$useXCACHE = extension_loaded('XCache') && ini_get('xcache.cacher');
}
if (self::$useAPC === NULL && self::$useXCACHE == FALSE) {
self::$useAPC = extension_loaded('apc') && ini_get('apc.enabled');
}

Expand Down Expand Up @@ -171,6 +175,11 @@ static public function loadCacheContent() {
if ($value !== FALSE) {
self::setCache($value);
}
} elseif(self::isXcacheUsed()) {
$value = xcache_isset(self::getCacheKey()) ? xcache_get(self::getCacheKey()) : false;
if ($value !== FALSE) {
self::setCache($value);
}
} elseif (file_exists(self::getCacheFilePath())) {
self::setCache(unserialize(file_get_contents(self::getCacheFilePath())));
}
Expand Down Expand Up @@ -216,7 +225,7 @@ static public function searchFullPath($filename)
foreach ($paths as $path) {
$fullPath = $path . DIRECTORY_SEPARATOR . $filename;
if (file_exists($fullPath)) {
return $fullPath;
return realpath($fullPath);
}
}
return false;
Expand All @@ -232,6 +241,16 @@ public static function isApcUsed()
return self::$useAPC;
}

/**
* Check if xcache is used
*
* @return bool
*/
public static function isXcacheUsed()
{
return self::$useXCACHE;
}

/**
* Get cache key (for apc)
*
Expand Down Expand Up @@ -262,6 +281,10 @@ public function __destruct()
if (PHP_SAPI != 'cli') {
apc_store(self::getCacheKey(), self::$_cache, 0);
}
} elseif(self::isXcacheUsed()) {
if (PHP_SAPI != 'cli') {
xcache_set(self::getCacheKey(), self::$_cache, 0);
}
} else {
$fileContent = serialize(self::$_cache);
$tmpFile = tempnam(sys_get_temp_dir(), 'aoe_classpathcache');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<layout>

<adminhtml_cache_index>
<reference name="cache.additional">
<block type="core/template" name="aoe_classpathcache" template="aoe_classpathcache/aoe_classpathcache.phtml" after="-"></block>
</reference>
</adminhtml_cache_index>

<adminhtml_cache_index>
<reference name="cache.additional">
<block type="core/template" name="aoe_classpathcache" template="aoe_classpathcache/aoe_classpathcache.phtml" after="-"></block>
</reference>
</adminhtml_cache_index>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ $_helper = $this->helper('aoe_classpathcache'); /* @var $_helper Aoe_ClassPathCa
<table class="form-list">
<tr>
<td class="scope-label">
<button onclick="setLocation('<?php echo $_helper->getUrl() ?>')" type="button" class="scalable"><span><span><span><?php echo Mage::helper('adminhtml')->__('Flush Aoe_ClassPathCache') ?></span></span></span></button>
<button onclick="setLocation('<?php echo $_helper->getAdminUrl() ?>')" type="button" class="scalable"><span><span><span><?php echo Mage::helper('adminhtml')->__('Flush Aoe_ClassPathCache') ?></span></span></span></button>
</td>
<td class="scope-label">
<strong><?php echo Mage::helper('adminhtml')->__('Storage:') ?></strong>
<?php echo Varien_Autoload::isApcUsed() ? Mage::helper('adminhtml')->__('APC') : Mage::helper('adminhtml')->__('file') ?>,
<?php if(Varien_Autoload::isApcUsed()): ?>
<?php echo Mage::helper('adminhtml')->__('APC'); ?>
<?php elseif(Varien_Autoload::isXcacheUsed()): ?>
<?php echo Mage::helper('adminhtml')->__('XCache'); ?>
<?php else: ?>
<?php echo Mage::helper('adminhtml')->__('file') ?>,
<?php endif; ?>
<strong><?php echo Mage::helper('adminhtml')->__('Number of entries:') ?></strong>
<?php echo count(Varien_Autoload::getCache()) ?>
</td>
Expand Down
12 changes: 6 additions & 6 deletions app/etc/modules/Aoe_ClassPathCache.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Aoe_ClassPathCache>
<active>true</active>
<codePool>local</codePool>
</Aoe_ClassPathCache>
</modules>
<modules>
<Aoe_ClassPathCache>
<active>true</active>
<codePool>local</codePool>
</Aoe_ClassPathCache>
</modules>
</config>
86 changes: 43 additions & 43 deletions shell/aoe_classpathcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,53 +36,53 @@ public function setRevalidateFlagAction() {
}


/** ****************************************************************************************************************
* SHELL DISPATCHER
**************************************************************************************************************** */
/** ****************************************************************************************************************
* SHELL DISPATCHER
**************************************************************************************************************** */

/**
* Run script
*
* @return void
*/
public function run() {
$action = $this->getArg('action');
if (empty($action)) {
echo $this->usageHelp();
} else {
$actionMethodName = $action.'Action';
if (method_exists($this, $actionMethodName)) {
$this->$actionMethodName();
} else {
echo "Action $action not found!\n";
echo $this->usageHelp();
exit(1);
}
}
}
/**
* Run script
*
* @return void
*/
public function run() {
$action = $this->getArg('action');
if (empty($action)) {
echo $this->usageHelp();
} else {
$actionMethodName = $action.'Action';
if (method_exists($this, $actionMethodName)) {
$this->$actionMethodName();
} else {
echo "Action $action not found!\n";
echo $this->usageHelp();
exit(1);
}
}
}



/**
* Retrieve Usage Help Message
*
* @return string
*/
public function usageHelp() {
$help = 'Available actions: ' . "\n";
$methods = get_class_methods($this);
foreach ($methods as $method) {
if (substr($method, -6) == 'Action') {
$help .= ' -action ' . substr($method, 0, -6);
$helpMethod = $method.'Help';
if (method_exists($this, $helpMethod)) {
$help .= $this->$helpMethod();
}
$help .= "\n";
}
}
return $help;
}
/**
* Retrieve Usage Help Message
*
* @return string
*/
public function usageHelp() {
$help = 'Available actions: ' . "\n";
$methods = get_class_methods($this);
foreach ($methods as $method) {
if (substr($method, -6) == 'Action') {
$help .= ' -action ' . substr($method, 0, -6);
$helpMethod = $method.'Help';
if (method_exists($this, $helpMethod)) {
$help .= $this->$helpMethod();
}
$help .= "\n";
}
}
return $help;
}


}
Expand Down