From c343758d7c16c6758e64703eb9c055f2b9ec9532 Mon Sep 17 00:00:00 2001 From: Christian Willing Date: Wed, 6 Jul 2016 11:21:15 +0200 Subject: [PATCH] asset cache fix --- modules/system/classes/CombineAssets.php | 63 +++++++++++++----------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/modules/system/classes/CombineAssets.php b/modules/system/classes/CombineAssets.php index eede1b799..6f15e91ff 100644 --- a/modules/system/classes/CombineAssets.php +++ b/modules/system/classes/CombineAssets.php @@ -267,7 +267,7 @@ class CombineAssets } /** - * Combines asset file references of a single type to produce + * Combines asset file references of a single type to produce * a URL reference to the combined contents. * @var array List of asset files. * @var string File extension, used for aesthetic purposes only. @@ -313,38 +313,45 @@ class CombineAssets * Returns the combined contents from a prepared cache identifier. * @return string Combined file contents. */ - protected function prepareCombiner(array $assets, $rewritePath = null) - { - /* - * Extensibility - */ - Event::fire('cms.combiner.beforePrepare', [$this, $assets]); + protected function prepareCombiner(array $assets, $rewritePath = null) + { + /* + * Extensibility + */ + Event::fire('cms.combiner.beforePrepare', [$this, $assets]); - $files = []; - $filesSalt = null; - foreach ($assets as $asset) { - $filters = $this->getFilters(File::extension($asset)) ?: []; - $path = File::symbolizePath($asset, null) ?: $this->localPath . $asset; - $files[] = new FileAsset($path, $filters, public_path()); - $filesSalt .= $this->localPath . $asset; - } - $filesSalt = md5($filesSalt); + $files = []; + $filesSalt = null; + foreach ($assets as $asset) { + $filters = $this->getFilters(File::extension($asset)) ?: []; + $path = File::symbolizePath($asset, null) ?: $this->localPath . $asset; + $files[] = new FileAsset($path, $filters, public_path()); + $filesSalt .= $this->localPath . $asset; + } + $filesSalt = md5($filesSalt); - $collection = new AssetCollection($files, [], $filesSalt); - $collection->setTargetPath($this->getTargetPath($rewritePath)); + $collection = new AssetCollection($files, [], $filesSalt); + $collection->setTargetPath($this->getTargetPath($rewritePath)); - if ($this->storagePath === null) { - return $collection; - } + if ($this->storagePath === null) { + return $collection; + } - if (!File::isDirectory($this->storagePath)) { - File::makeDirectory($this->storagePath); - } + if (!File::isDirectory($this->storagePath)) { + File::makeDirectory($this->storagePath); + } - $cache = new FilesystemCache($this->storagePath); - $cachedCollection = new AssetCache($collection, $cache); - return $cachedCollection; - } + $cache = new FilesystemCache($this->storagePath); + + $cachedFiles = []; + foreach ($files as $file) { + $cachedFiles[] = new AssetCache($file, $cache); + } + + $cachedCollection = new AssetCollection($cachedFiles, [], $filesSalt); + $cachedCollection->setTargetPath($this->getTargetPath($rewritePath)); + return $cachedCollection; + } /** * Returns the URL used for accessing the combined files.