diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php index 664b054ebc5..3c66369028a 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 = (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/product/stats/bom.php b/htdocs/product/stats/bom.php index 851bf118823..c9a1fb2f04c 100644 --- a/htdocs/product/stats/bom.php +++ b/htdocs/product/stats/bom.php @@ -230,7 +230,7 @@ if ($id > 0 || !empty($ref)) { $bomtmp->ref = $objp->ref; $product = new Product($db); if (!empty($objp->fk_product)) { - if (!array_key_exists($product->id, $product_cache)) { + if (!array_key_exists($objp->fk_product, $product_cache)) { $resultFetch = $product->fetch($objp->fk_product); if ($resultFetch < 0) { setEventMessages($product->error, $product->errors, 'errors');