Skip to content

Commit 6cfefc9

Browse files
committed
Fix regression with block caching if cache is not available. #88
1 parent 4c1f8fd commit 6cfefc9

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file. This project make usage of the [Yii Versioning Strategy](https://github.com/yiisoft/yii2/blob/master/docs/internals/versions.md). In order to read more about upgrading and BC breaks have a look at the [UPGRADE Document](UPGRADE.md).
44

5+
## 1.0.5.1 (in progress)
6+
7+
### Fixed
8+
9+
+ [#88](https://github.com/luyadev/luya-module-cms/issues/88) Fix regression with block caching if cache is not available.
10+
511
## 1.0.5 (5. June 2018)
612

713
### Fixed

src/base/PhpBlock.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function renderAdmin()
7575
*/
7676
public function onRegister()
7777
{
78-
if ($this->getIsCacheEnabled()) {
78+
if ($this->getIsCacheEnabled() && $this->isCachingEnabled()) {
7979
$phpBlockView = $this->getView();
8080

8181
$blockId = $this->getEnvOption('id');
@@ -100,14 +100,27 @@ public function onRegister()
100100
*/
101101
public function onRegisterFromCache()
102102
{
103-
$blockId = $this->getEnvOption('id');
104-
105-
$cacheKeyAssets = ['blockassets', $blockId];
106-
$cacheKeyAssetBundles = ['blockassetbundles', $blockId];
103+
if ($this->isCachingEnabled()) {
104+
$blockId = $this->getEnvOption('id');
105+
106+
$cacheKeyAssets = ['blockassets', $blockId];
107+
$cacheKeyAssetBundles = ['blockassetbundles', $blockId];
108+
109+
$assets = Yii::$app->cache->get($cacheKeyAssets) ?: [];
110+
$assetBundles = Yii::$app->cache->get($cacheKeyAssetBundles) ?: [];
111+
112+
PhpBlockView::registerToAppView($assets, $assetBundles);
113+
}
114+
}
107115

108-
$assets = Yii::$app->cache->get($cacheKeyAssets) ?: [];
109-
$assetBundles = Yii::$app->cache->get($cacheKeyAssetBundles) ?: [];
110116

111-
PhpBlockView::registerToAppView($assets, $assetBundles);
117+
/**
118+
* Will be replaced with cachable trait in future.
119+
*
120+
* @return boolean
121+
*/
122+
private function isCachingEnabled()
123+
{
124+
return Yii::$app->has('cache');
112125
}
113126
}

0 commit comments

Comments
 (0)