Merge pull request #17998 from OPEN-DSI/fix_00008

FIX: Reload values of the specified entity when change entity in the execution of cron jobs
This commit is contained in:
Laurent Destailleur 2021-11-18 18:41:06 +01:00 committed by GitHub
commit 8477c0a3f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 8 deletions

View File

@ -161,6 +161,23 @@ class Conf
$this->productbatch = new stdClass();
}
/**
* Load setup values into conf object (read llx_const) for a specified entity
* Note that this->db->xxx, this->file->xxx and this->multicompany have been already loaded when setValues is called.
*
* @param DoliDB $db Database handler
* @param int $entity Entity to get
* @return int < 0 if KO, >= 0 if OK
*/
public function setEntityValues($db, $entity)
{
if ($this->entity != $entity) {
$this->entity = $entity;
return $this->setValues($db);
}
return 0;
}
/**
* Load setup values into conf object (read llx_const)
@ -173,6 +190,58 @@ class Conf
{
dol_syslog(get_class($this)."::setValues");
// Unset all old modules values
if (!empty($this->modules)) {
foreach ($this->modules as $m) {
if (isset($this->$m)) unset($this->$m);
}
}
// Properly declare multi-modules objects.
$this->global = new stdClass();
$this->multicompany = new stdClass();
// First level object
// TODO Remove this part.
$this->expedition_bon = new stdClass();
$this->delivery_note = new stdClass();
$this->fournisseur = new stdClass();
$this->product = new stdClass();
$this->service = new stdClass();
$this->contrat = new stdClass();
$this->actions = new stdClass();
$this->agenda = new stdClass();
$this->commande = new stdClass();
$this->propal = new stdClass();
$this->facture = new stdClass();
$this->contrat = new stdClass();
$this->usergroup = new stdClass();
$this->adherent = new stdClass();
$this->bank = new stdClass();
$this->notification = new stdClass();
$this->mailing = new stdClass();
$this->expensereport = new stdClass();
$this->productbatch = new stdClass();
$this->modules = array();;
$this->modules_parts = array(
'css' => array(),
'js' => array(),
'tabs' => array(),
'triggers' => array(),
'login' => array(),
'substitutions' => array(),
'menus' => array(),
'theme' => array(),
'sms' => array(),
'tpl' => array(),
'barcode' => array(),
'models' => array(),
'societe' => array(),
'hooks' => array(),
'dir' => array(),
'syslog' => array(),
);
if (!is_null($db) && is_object($db)) {
// Define all global constants into $this->global->key=value
$sql = "SELECT ".$db->decrypt('name')." as name,";

View File

@ -1081,7 +1081,7 @@ class Cronjob extends CommonObject
dol_syslog("We try to run a job in entity ".$this->entity." when we are in entity ".$conf->entity, LOG_WARNING);
}
$savcurrententity = $conf->entity;
$conf->entity = $this->entity;
$conf->setEntityValues($this->db, $this->entity);
dol_syslog(get_class($this)."::run_jobs entity for running job is ".$conf->entity);
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
@ -1090,13 +1090,13 @@ class Cronjob extends CommonObject
if ($result < 0) {
$this->error = "User Error:".$user->error;
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$conf->entity = $savcurrententity;
$conf->setEntityValues($this->db, $savcurrententity);
return -1;
} else {
if (empty($user->id)) {
$this->error = " User user login:".$userlogin." do not exists";
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$conf->entity = $savcurrententity;
$conf->setEntityValues($this->db, $savcurrententity);
return -1;
}
}
@ -1126,7 +1126,7 @@ class Cronjob extends CommonObject
$result = $this->update($user); // This include begin/commit
if ($result < 0) {
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$conf->entity = $savcurrententity;
$conf->setEntityValues($this->db, $savcurrententity);
return -1;
}
@ -1241,7 +1241,7 @@ class Cronjob extends CommonObject
if ($ret === false) {
$this->error = $langs->trans('CronCannotLoadLib').': '.$libpath;
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$conf->entity = $savcurrententity;
$conf->setEntityValues($this->db, $savcurrententity);
return -1;
}
@ -1250,7 +1250,7 @@ class Cronjob extends CommonObject
$result = $langs->load($this->module_name.'@'.$this->module_name); // If this->module_name was an existing language file, this will make nothing
if ($result < 0) { // If technical error
dol_syslog(get_class($this)."::run_jobs Cannot load module langs".$langs->error, LOG_ERR);
$conf->entity = $savcurrententity;
$conf->setEntityValues($this->db, $savcurrententity);
return -1;
}
@ -1316,11 +1316,11 @@ class Cronjob extends CommonObject
$result = $this->update($user); // This include begin/commit
if ($result < 0) {
dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR);
$conf->entity = $savcurrententity;
$conf->setEntityValues($this->db, $savcurrententity);
return -1;
}
$conf->entity = $savcurrententity;
$conf->setEntityValues($this->db, $savcurrententity);
return $error ?-1 : 1;
}