From 71ec381d3e4b6da13503f257aa51ec6e4e80494b Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Mon, 10 Nov 2025 10:56:07 +0100 Subject: [PATCH 1/2] FIX re-create API temp dir after purging temp files --- htdocs/core/class/utils.class.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/utils.class.php b/htdocs/core/class/utils.class.php index 285b88cd52a..b7a851aaa30 100644 --- a/htdocs/core/class/utils.class.php +++ b/htdocs/core/class/utils.class.php @@ -168,8 +168,25 @@ class Utils } // Recreate temp dir that are not automatically recreated by core code for performance purpose, we need them - if (!empty($conf->api->enabled)) { - dol_mkdir($conf->api->dir_temp); + if (isModEnabled('api')) { + if (isModEnabled('multicompany')) { + global $mc; + + if (is_object($mc)) { + $entitiesList = $mc->getEntitiesList(); + foreach ($entitiesList as $entityId => $entity) { + if ($entityId > 1) { + $apiDir = DOL_DATA_ROOT.'/'.$entityId.'/api'; + if (is_dir($apiDir)) { // only create API temp directory of entity (can create routes.php file from Restler API) if Restler API is enabled (API directory exists) + $apiTempDir = DOL_DATA_ROOT.'/'.$entityId.'/api/temp/'; + dol_mkdir($apiTempDir); + } + } + } + } + } + + dol_mkdir($conf->api->dir_temp); // create API temp directory for main entity (can create routes.php file from Restler API) } dol_mkdir($conf->user->dir_temp); From c2ae7d2da1d6d5d925184ac4314d85ba50ee74b1 Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Thu, 13 Nov 2025 14:01:34 +0100 Subject: [PATCH 2/2] FIX create API temp directory in Dolibarr API constructor --- htdocs/api/class/api.class.php | 12 ++++++++++++ htdocs/core/class/utils.class.php | 19 +------------------ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php index e4f093be87f..ae9db369744 100644 --- a/htdocs/api/class/api.class.php +++ b/htdocs/api/class/api.class.php @@ -58,6 +58,18 @@ class DolibarrApi $this->db = $db; $production_mode = (empty($conf->global->API_PRODUCTION_MODE) ? false : true); + + if ($production_mode) { + // Create the directory Defaults::$cacheDirectory if it does not exist. If dir does not exist, 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)); diff --git a/htdocs/core/class/utils.class.php b/htdocs/core/class/utils.class.php index b7a851aaa30..dc4174eb3aa 100644 --- a/htdocs/core/class/utils.class.php +++ b/htdocs/core/class/utils.class.php @@ -169,24 +169,7 @@ class Utils // Recreate temp dir that are not automatically recreated by core code for performance purpose, we need them if (isModEnabled('api')) { - if (isModEnabled('multicompany')) { - global $mc; - - if (is_object($mc)) { - $entitiesList = $mc->getEntitiesList(); - foreach ($entitiesList as $entityId => $entity) { - if ($entityId > 1) { - $apiDir = DOL_DATA_ROOT.'/'.$entityId.'/api'; - if (is_dir($apiDir)) { // only create API temp directory of entity (can create routes.php file from Restler API) if Restler API is enabled (API directory exists) - $apiTempDir = DOL_DATA_ROOT.'/'.$entityId.'/api/temp/'; - dol_mkdir($apiTempDir); - } - } - } - } - } - - dol_mkdir($conf->api->dir_temp); // create API temp directory for main entity (can create routes.php file from Restler API) + dol_mkdir($conf->api->dir_temp); } dol_mkdir($conf->user->dir_temp);