From 35f73df5e50b31c86db75ae9c2c8b3b16093b64e Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Mon, 18 Mar 2024 09:45:56 -0400 Subject: [PATCH] Create asset pipeline cache directory on demand. (#3525) --- .../src/VuFindTheme/View/Helper/ConcatTrait.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/module/VuFindTheme/src/VuFindTheme/View/Helper/ConcatTrait.php b/module/VuFindTheme/src/VuFindTheme/View/Helper/ConcatTrait.php index 48aac650f07..853e89602c1 100644 --- a/module/VuFindTheme/src/VuFindTheme/View/Helper/ConcatTrait.php +++ b/module/VuFindTheme/src/VuFindTheme/View/Helper/ConcatTrait.php @@ -227,7 +227,7 @@ protected function filterItems() /** * Get the path to the directory where we can cache files generated by - * this trait. + * this trait. The directory will be created if it does not already exist. * * @return string */ @@ -238,7 +238,14 @@ protected function getResourceCacheDir() 'Asset pipeline feature depends on the LOCAL_CACHE_DIR constant.' ); } - return LOCAL_CACHE_DIR . '/public/'; + // TODO: it might be better to use \VuFind\Cache\Manager here. + $cacheDir = LOCAL_CACHE_DIR . '/public/'; + if (!is_dir($cacheDir) && !file_exists($cacheDir)) { + if (!mkdir($cacheDir)) { + throw new \Exception("Unexpected problem creating cache directory: $cacheDir"); + } + } + return $cacheDir; } /**