diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 8766d68c25b..ed919be568c 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -151,6 +151,19 @@ 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 + */ + function setEntityValues($db, $entity) + { + $this->entity = $entity; + $this->setValues($db); + } /** * Load setup values into conf object (read llx_const) @@ -161,6 +174,60 @@ class Conf */ public function setValues($db) { + global $conf; + + // 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(), + ); + dol_syslog(get_class($this)."::setValues"); //Define all global constants into $this->global->key=value diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index 2ffce20a924..e2b7c2da47b 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -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; }