FIX avoid error 500 on api when cache dir does not exists

This commit is contained in:
Laurent Destailleur 2025-10-31 16:44:29 +01:00
parent cb7d856aa1
commit 6e14377ba4

View file

@ -60,8 +60,14 @@ class DolibarrApi
$this->db = $db;
$production_mode = getDolGlobalBool('API_PRODUCTION_MODE');
if ($production_mode && getDolGlobalString('MAIN_API_DEBUG')) {
dol_syslog("Debug API construct::cacheDirectory=".Defaults::$cacheDirectory, LOG_DEBUG, 0, '_api');
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.
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);