Fix init of environment for a dedicated entity in API
This commit is contained in:
parent
83440f5bbc
commit
8da7f789d8
@ -118,9 +118,12 @@ class DolibarrApiAccess implements iAuthenticate
|
|||||||
$stored_key = $obj->api_key;
|
$stored_key = $obj->api_key;
|
||||||
$userentity = $obj->entity;
|
$userentity = $obj->entity;
|
||||||
|
|
||||||
if (! defined("DOLENTITY")) // If API was not forced with HTTP_DOLENTITY, we set entity to entity of user
|
if (! defined("DOLENTITY") && $conf->entity != $obj->entity) // If API was not forced with HTTP_DOLENTITY, and user is on another entity, so we reset entity to entity of user
|
||||||
{
|
{
|
||||||
$conf->entity = ($obj->entity?$obj->entity:1);
|
$conf->entity = ($obj->entity?$obj->entity:1);
|
||||||
|
// We must also reload global conf to get params from the entity
|
||||||
|
dol_syslog("Entity was not set on http header with HTTP_DOLAPIENTITY (recommanded for performance purpose), so we switch now on entity of user (".$conf->entity .") and we have to reload configuration.", LOG_WARNING);
|
||||||
|
$conf->setValues($db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,6 +37,10 @@ if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); // Do not lo
|
|||||||
if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
|
if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
|
||||||
|
|
||||||
|
|
||||||
|
// Force entity if a value is provided into HTTP header. Otherwise, will use the entity of user of token used.
|
||||||
|
if (! empty($_SERVER['HTTP_DOLAPIENTITY'])) define("DOLENTITY", (int) $_SERVER['HTTP_DOLAPIENTITY']);
|
||||||
|
|
||||||
|
|
||||||
$res=0;
|
$res=0;
|
||||||
if (! $res && file_exists("../main.inc.php")) $res=include '../main.inc.php';
|
if (! $res && file_exists("../main.inc.php")) $res=include '../main.inc.php';
|
||||||
if (! $res) die("Include of main fails");
|
if (! $res) die("Include of main fails");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user