Enh: Flush also assets directory on cache delete

This commit is contained in:
Lucas Bartholemy 2016-07-12 17:03:38 +02:00
parent 0a4a91cb5a
commit 23147e3b62
3 changed files with 41 additions and 1 deletions

View File

@ -0,0 +1,39 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2016 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\components;
use yii\helpers\FileHelper;
/**
* AssetManager
*
* @inheritdoc
* @author Luke
*/
class AssetManager extends \yii\web\AssetManager
{
/**
* Clears all currently published assets
*/
public function clear()
{
if ($this->basePath == '') {
return;
}
foreach (scandir($this->basePath) as $file) {
if (substr($file, 0, 1) === '.') {
continue;
}
FileHelper::removeDirectory($this->basePath . DIRECTORY_SEPARATOR . $file);
}
}
}

View File

@ -84,6 +84,7 @@ $config = [
],
],
'assetManager' => [
'class' => '\humhub\components\AssetManager',
'appendTimestamp' => true,
],
'view' => [

View File

@ -149,7 +149,7 @@ class SettingController extends Controller
$form = new \humhub\modules\admin\models\forms\CacheSettingsForm;
if ($form->load(Yii::$app->request->post()) && $form->validate() && $form->save()) {
Yii::$app->cache->flush();
Yii::$app->assetManager->clear();
Yii::$app->getSession()->setFlash('data-saved', Yii::t('AdminModule.controllers_SettingController', 'Saved and flushed cache'));
return $this->redirect(['/admin/setting/caching']);
}