Clean code

This commit is contained in:
Laurent Destailleur 2021-11-18 19:25:07 +01:00
parent 8477c0a3f1
commit 0649dc598d
4 changed files with 38 additions and 33 deletions

View File

@ -110,10 +110,12 @@ class Conf
// Common objects that are not modules // Common objects that are not modules
$this->mycompany = new stdClass(); $this->mycompany = new stdClass();
$this->admin = new stdClass(); $this->admin = new stdClass();
$this->browser = new stdClass();
$this->medias = new stdClass(); $this->medias = new stdClass();
$this->global = new stdClass(); $this->global = new stdClass();
// Common objects that are not modules and set by the main and not into the this->setValues()
$this->browser = new stdClass();
$this->cache = array(); $this->cache = array();
$this->modules = array(); $this->modules = array();
$this->modules_parts = array( $this->modules_parts = array(
@ -152,7 +154,6 @@ class Conf
$this->facture = new stdClass(); $this->facture = new stdClass();
$this->contrat = new stdClass(); $this->contrat = new stdClass();
$this->user = new stdClass(); $this->user = new stdClass();
$this->usergroup = new stdClass();
$this->adherent = new stdClass(); $this->adherent = new stdClass();
$this->bank = new stdClass(); $this->bank = new stdClass();
$this->notification = new stdClass(); $this->notification = new stdClass();
@ -165,15 +166,15 @@ class Conf
* Load setup values into conf object (read llx_const) for a specified entity * 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. * 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 * @param int $entity Entity to get
* @return int < 0 if KO, >= 0 if OK * @return int < 0 if KO, >= 0 if OK
*/ */
public function setEntityValues($db, $entity) public function setEntityValues($entity)
{ {
if ($this->entity != $entity) { if ($this->entity != $entity) {
// If we ask to reload setup for a new entity
$this->entity = $entity; $this->entity = $entity;
return $this->setValues($db); return $this->setValues($this->db);
} }
return 0; return 0;
@ -197,12 +198,18 @@ class Conf
} }
} }
// Properly declare multi-modules objects. // Common objects that are not modules
$this->mycompany = new stdClass();
$this->admin = new stdClass();
$this->medias = new stdClass();
$this->global = new stdClass(); $this->global = new stdClass();
$this->multicompany = new stdClass();
// Common objects that are not modules and set by the main and not into the this->setValues()
//$this->browser = new stdClass(); // This is set by main and not into this setValues(), so we keep it intact.
// First level object // First level object
// TODO Remove this part. // TODO Remove this part.
$this->syslog = new stdClass();
$this->expedition_bon = new stdClass(); $this->expedition_bon = new stdClass();
$this->delivery_note = new stdClass(); $this->delivery_note = new stdClass();
$this->fournisseur = new stdClass(); $this->fournisseur = new stdClass();
@ -215,13 +222,15 @@ class Conf
$this->propal = new stdClass(); $this->propal = new stdClass();
$this->facture = new stdClass(); $this->facture = new stdClass();
$this->contrat = new stdClass(); $this->contrat = new stdClass();
$this->usergroup = new stdClass(); $this->user = new stdClass();
$this->adherent = new stdClass(); $this->adherent = new stdClass();
$this->bank = new stdClass(); $this->bank = new stdClass();
$this->notification = new stdClass(); $this->notification = new stdClass();
$this->mailing = new stdClass(); $this->mailing = new stdClass();
$this->expensereport = new stdClass(); $this->expensereport = new stdClass();
$this->productbatch = new stdClass(); $this->productbatch = new stdClass();
$this->cache = array();
$this->modules = array();; $this->modules = array();;
$this->modules_parts = array( $this->modules_parts = array(
'css' => array(), 'css' => array(),
@ -470,10 +479,6 @@ class Conf
$this->user->dir_output = $rootforuser."/users"; $this->user->dir_output = $rootforuser."/users";
$this->user->dir_temp = $rootfortemp."/users/temp"; $this->user->dir_temp = $rootfortemp."/users/temp";
// For usergroup storage
$this->usergroup->dir_output = $rootforuser."/usergroups";
$this->usergroup->dir_temp = $rootfortemp."/usergroups/temp";
// For proposal storage // For proposal storage
$this->propal->multidir_output = array($this->entity => $rootfordata."/propale"); $this->propal->multidir_output = array($this->entity => $rootfordata."/propale");
$this->propal->multidir_temp = array($this->entity => $rootfortemp."/propale/temp"); $this->propal->multidir_temp = array($this->entity => $rootfortemp."/propale/temp");

View File

@ -258,7 +258,7 @@ class doc_generic_usergroup_odt extends ModelePDFUserGroup
} }
} }
$dir = $conf->usergroup->dir_output; $dir = $conf->user->dir_output.'/usergroups';
$objectref = dol_sanitizeFileName($object->ref); $objectref = dol_sanitizeFileName($object->ref);
if (!preg_match('/specimen/i', $objectref)) { if (!preg_match('/specimen/i', $objectref)) {
$dir .= "/".$objectref; $dir .= "/".$objectref;

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

View File

@ -237,7 +237,7 @@ if (empty($reshook)) {
} }
// Actions to build doc // Actions to build doc
$upload_dir = $conf->usergroup->dir_output; $upload_dir = $conf->user->dir_output.'/usergroups';
$permissiontoadd = $user->rights->user->user->creer; $permissiontoadd = $user->rights->user->user->creer;
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
} }
@ -478,7 +478,7 @@ if ($action == 'create') {
*/ */
$filename = dol_sanitizeFileName($object->ref); $filename = dol_sanitizeFileName($object->ref);
$filedir = $conf->usergroup->dir_output."/".dol_sanitizeFileName($object->ref); $filedir = $conf->user->dir_output."/usergroups/".dol_sanitizeFileName($object->ref);
$urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
$genallowed = $user->rights->user->user->creer; $genallowed = $user->rights->user->user->creer;
$delallowed = $user->rights->user->user->supprimer; $delallowed = $user->rights->user->user->supprimer;