From 7bb7a383e9cc94c890387a6c9c10d7578c4f483a Mon Sep 17 00:00:00 2001 From: William Mortada Date: Tue, 21 Nov 2023 10:22:52 +0000 Subject: [PATCH] Set cache folder for dompdf --- CRM/Utils/PDF/Utils.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/CRM/Utils/PDF/Utils.php b/CRM/Utils/PDF/Utils.php index decc1b39ea..847af31e82 100644 --- a/CRM/Utils/PDF/Utils.php +++ b/CRM/Utils/PDF/Utils.php @@ -258,8 +258,35 @@ class CRM_Utils_PDF_Utils { $settings[$setting] = $value; } } + + // core#4791 - Set cache dir to prevent files being generated in font dir + $cacheDir = self::getCacheDir($settings); + if ($cacheDir !== "") { + $settings['font_cache'] = $cacheDir; + } $options->set($settings); return $options; } + /** + * Get location of cache folder. + * + * @param array $settings + * @return string + */ + private static function getCacheDir(array $settings): string { + // Use subfolder of custom font dir if it is writable + if (isset($settings['font_dir']) && is_writable($settings['font_dir'])) { + $cacheDir = $settings['font_dir'] . DIRECTORY_SEPARATOR . 'font_cache'; + } + else { + $cacheDir = Civi::paths()->getPath('[civicrm.files]/upload/font_cache'); + } + // Try to create dir if it doesn't exist or return empty string + if ((!is_dir($cacheDir)) && (!mkdir($cacheDir))) { + $cacheDir = ""; + } + return $cacheDir; + } + } -- 2.25.1