Fixes #13226: yii cache command now warns about the fact that it's not able to flush APC cache from console

This commit is contained in:
Alexander Makarov
2017-04-26 03:19:49 +03:00
committed by GitHub
parent 3a8f702759
commit 70cd75c84e
2 changed files with 21 additions and 5 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.12 under development
--------------------------
- Enh #13226: `yii cache` command now warns about the fact that it's not able to flush APC cache from console (samdark)
- Bug #11719: Fixed `yii\db\Connection::$enableQueryCache` caused infinite loop when the same connection was used for `yii\caching\DbCache` (michaelarnauts)
- Bug #10346: Fixed "DOMException: Invalid Character Error" in `yii\web\XmlResponseFormatter::buildXml()` (sasha-ch)
- Bug #13694: `yii\widgets\Pjax` now sends `X-Pjax-Url` header with response to fix redirect (wleona3, Faryshta)

View File

@ -8,6 +8,7 @@
namespace yii\console\controllers;
use Yii;
use yii\caching\ApcCache;
use yii\console\Controller;
use yii\caching\Cache;
use yii\helpers\Console;
@ -32,7 +33,7 @@ use yii\console\Exception;
* configured are different from web application, web application cache won't be cleared. In order to fix it please
* duplicate web application cache components in console config. You can use any component names.
*
* Both APC and OpCache aren't shared between PHP processes so flushing cache from command line has no effect on web.
* APC is not shared between PHP processes so flushing cache from command line has no effect on web.
* Flushing web cache could be either done by:
*
* - Putting a php file under web root and calling it via HTTP
@ -99,7 +100,7 @@ class CacheController extends Controller
$cachesInfo[] = [
'name' => $name,
'class' => $class,
'is_flushed' => Yii::$app->get($name)->flush(),
'is_flushed' => $this->canBeFlushed($class) ? Yii::$app->get($name)->flush() : false,
];
}
@ -123,7 +124,7 @@ class CacheController extends Controller
$cachesInfo[] = [
'name' => $name,
'class' => $class,
'is_flushed' => Yii::$app->get($name)->flush(),
'is_flushed' => $this->canBeFlushed($class) ? Yii::$app->get($name)->flush() : false,
];
}
@ -178,7 +179,11 @@ class CacheController extends Controller
$this->stdout("The following caches were found in the system:\n\n", Console::FG_YELLOW);
foreach ($caches as $name => $class) {
$this->stdout("\t* $name ($class)\n", Console::FG_GREEN);
if ($this->canBeFlushed($class)) {
$this->stdout("\t* $name ($class)\n", Console::FG_GREEN);
} else {
$this->stdout("\t* $name ($class) - can not be flushed via console\n", Console::FG_YELLOW);
}
}
$this->stdout("\n");
@ -256,7 +261,7 @@ class CacheController extends Controller
$findAll = ($cachesNames === []);
foreach ($components as $name => $component) {
if (!$findAll && !in_array($name, $cachesNames)) {
if (!$findAll && !in_array($name, $cachesNames, true)) {
continue;
}
@ -281,4 +286,14 @@ class CacheController extends Controller
{
return is_subclass_of($className, Cache::className());
}
/**
* Checks if cache of a certain class can be flushed
* @param string $className class name.
* @return bool
*/
private function canBeFlushed($className)
{
return !is_a($className, ApcCache::className(), true) || php_sapi_name() !== "cli";
}
}