From 6409cc06ae8d3827610497c8bda26b6671482080 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 22 Jul 2019 11:42:25 +0200 Subject: [PATCH 1/2] FIX duplicate on the check (TODO field $onetrtd not used ?) --- htdocs/core/class/commonobject.class.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 7cf3273b818..b2826737d0d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6289,7 +6289,7 @@ abstract class CommonObject * @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan) * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names) * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names) - * @param string $onetrtd All fields in same tr td + * @param string $onetrtd All fields in same tr td (TODO field not used ?) * @return string */ function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='', $onetrtd=0) @@ -6386,10 +6386,7 @@ abstract class CommonObject $out .= ''; - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) - { - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan='0'; } - } + if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan='0'; } if ($action == 'selectlines') { $colspan++; } From e92c6c87a0f20fda7690480d465c968fc469abf0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 26 Jul 2019 13:16:49 +0200 Subject: [PATCH 2/2] FIX API return 404 sometimes even if API exists --- htdocs/api/index.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index e55a30304a4..6788b208a2e 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -88,17 +88,22 @@ if (preg_match('/api\/index\.php\/explorer/', $_SERVER["PHP_SELF"]) && ! empty($ // index.php/xxx called by any REST client to run API +$reg=array(); preg_match('/index\.php\/([^\/]+)(.*)$/', $_SERVER["PHP_SELF"], $reg); // .../index.php/categories?sortfield=t.rowid&sortorder=ASC // Set the flag to say to refresh (when we reload the explorer, production must be for API call only) -$refreshcache=false; +/*$refreshcache=false; if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root')) { $refreshcache=true; -} - +}*/ +// When in production mode, a file api/temp/routes.php is created with the API available of current call. +// But, if we set $refreshcache to false, so it may have only one API in the routes.php file if we make a call for one API without +// using the explorer. And when we make another call for another API, the API is not into the api/temp/routes.php and a 404 is returned. +// So we force refresh to each call. +$refreshcache=true; $api = new DolibarrApi($db, '', $refreshcache); //var_dump($api->r->apiVersionMap); @@ -115,7 +120,7 @@ UploadFormat::$allowedMimeTypes = array('image/jpeg', 'image/png', 'text/plain', -// Call Explorer file for all APIs definitions +// Call Explorer file for all APIs definitions (this part is slow) if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root')) { // Scan all API files to load them @@ -253,5 +258,6 @@ if (! empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' && //var_dump($api->r->apiVersionMap); //exit; -// Call API (we suppose we found it) +// Call API (we suppose we found it). +// The handle will use the file api/temp/routes.php to get data to run the API. If the file exists and the entry for API is not found, it will return 404. $api->r->handle();