Skip to content

Commit

Permalink
moved cache flush functionality into separate controller
Browse files Browse the repository at this point in the history
  • Loading branch information
eluhr committed Jun 10, 2020
1 parent c5056e9 commit 083523b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
35 changes: 35 additions & 0 deletions src/controllers/CacheController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* @link http://www.diemeisterei.de/
* @copyright Copyright (c) 2020 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace dmstr\modules\backend\controllers;


use yii\web\Controller;
use Yii;

class CacheController extends Controller
{
/**
* flush cache
*
* if APCu is used as cache we cannot flush cache from cli command
* see: https://github.com/yiisoft/yii2/issues/8647
*
* @return \yii\web\Response
*/
public function actionFlush()
{
if (\Yii::$app->cache->flush()) {
\Yii::$app->session->addFlash('success', Yii::t('backend-module','Cache cleared'));
} else {
\Yii::$app->session->addFlash('error', Yii::t('backend-module','Cannot clear cache'));
}
return $this->redirect(['default/index']);
}
}
18 changes: 0 additions & 18 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,4 @@ public function renderDashboardMenu($item = [])
return $menuItems;
}

/**
* flush cache
*
* if APCu is used as cache we cannot flush cache from cli command
* see: https://github.com/yiisoft/yii2/issues/8647
*
* @return \yii\web\Response
*/
public function actionCacheFlush()
{
if (Yii::$app->cache->flush()) {
Yii::$app->session->addFlash('success', Yii::t('backend-module','Cache cleared'));
} else {
Yii::$app->session->addFlash('error', Yii::t('backend-module','Cannot clear cache'));
}
return $this->goBack(['index']);
}

}
2 changes: 1 addition & 1 deletion src/views/default/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
<div class="icon">
<i class="ion ion-grid"></i>
</div>
<a data-confirm="<?=Yii::t('backend-module', 'Are you sure?')?>" href="<?= \yii\helpers\Url::to(['default/cache-flush']) ?>" class="small-box-footer">
<a data-confirm="<?=Yii::t('backend-module', 'Are you sure?')?>" href="<?= \yii\helpers\Url::to(['cache/flush']) ?>" class="small-box-footer">
<?=Yii::t('backend-module', 'Flush')?> <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
Expand Down

0 comments on commit 083523b

Please sign in to comment.