From 6145bcc4495ee1e325ad883f41cbfa5ff4dac6b7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 31 Oct 2025 16:59:09 +0100 Subject: [PATCH] FIX Error 500 on api if cache is on and directory does not exists --- htdocs/api/class/api.class.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php index 5781871d098..e041389a066 100644 --- a/htdocs/api/class/api.class.php +++ b/htdocs/api/class/api.class.php @@ -59,6 +59,18 @@ class DolibarrApi $this->db = $db; $production_mode = getDolGlobalBool('API_PRODUCTION_MODE'); + + if ($production_mode) { + // Create the directory Defaults::$cacheDirectory if it does not exists. If dir does not exists, using production_mode generates an error 500. + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + if (!dol_is_dir(Defaults::$cacheDirectory)) { + dol_mkdir(Defaults::$cacheDirectory, DOL_DATA_ROOT); + } + if (getDolGlobalString('MAIN_API_DEBUG')) { + dol_syslog("Debug API construct::cacheDirectory=".Defaults::$cacheDirectory, LOG_DEBUG, 0, '_api'); + } + } + $this->r = new Restler($production_mode, $refreshCache); $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));