From 46ad02cbc8c92695a4b464e5820a4df5b50bf6e0 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 23 Feb 2012 15:42:03 +0100 Subject: [PATCH] New: add generic function for module parts --- htdocs/core/class/conf.class.php | 2 +- htdocs/core/modules/DolibarrModules.class.php | 90 +++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 9168aafe590..af5eb08a77b 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -182,7 +182,7 @@ class Conf $modulename = strtolower($reg[1]); $partname = strtolower($reg[2]); $varname = $partname.'_modules'; - $this->$varname[$modulename] = '/'.$modulename.'/core/'.$partname.'/'; + $this->$varname = array_merge($this->$varname, array($modulename => '/'.$modulename.'/core/'.$partname.'/')); } // TODO All of this part could be mutualized into one generic part diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index ca8aea1d169..a7fa450a69c 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -82,6 +82,9 @@ abstract class DolibarrModules // Insert activation login method if (! $err) $err+=$this->insert_login_method(); + + // Insert activation of module's parts + if (! $err) $err+=$this->insert_module_parts(); // Insert constant defined by modules, into llx_const if (! $err) $err+=$this->insert_const(); @@ -179,6 +182,9 @@ abstract class DolibarrModules // Remove activation of module's authentification method (MAIN_MODULE_MYMODULE_LOGIN in llx_const) if (! $err) $err+=$this->delete_login_method(); + + // Remove activation of module's parts (MAIN_MODULE_MYMODULE_XXX in llx_const) + if (! $err) $err+=$this->delete_module_parts(); // Remove constants defined by modules if (! $err) $err+=$this->delete_const(); @@ -1335,10 +1341,88 @@ abstract class DolibarrModules return $err; } + /** + * Insert activation of generic parts from modules in llx_const + * + * @return int Nb of errors (0 if OK) + */ + function insert_module_parts() + { + global $conf; + + $err=0; + + if (is_array($this->module_parts) && ! empty($this->module_parts)) + { + foreach($this->module_parts as $key => $value) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."const ("; + $sql.= "name"; + $sql.= ", type"; + $sql.= ", value"; + $sql.= ", note"; + $sql.= ", visible"; + $sql.= ", entity"; + $sql.= ")"; + $sql.= " VALUES ("; + $sql.= $this->db->encrypt($this->const_name."_".strtoupper($key),1); + $sql.= ", 'chaine'"; + $sql.= ", ".$this->db->encrypt($value,1); + $sql.= ", null"; + $sql.= ", '0'"; + $sql.= ", ".$conf->entity; + $sql.= ")"; + + dol_syslog(get_class($this)."::insert_".$key." sql=".$sql); + $resql=$this->db->query($sql); + if (! $resql) + { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::insert_".$key." ".$this->error); + } + } + } + return $err; + } + + /** + * Remove activation of generic parts from modules in llx_const + * + * @return int Nb of errors (0 if OK) + */ + function delete_module_parts() + { + global $conf; + + $err=0; + + if (is_array($this->module_parts) && ! empty($this->module_parts)) + { + foreach($this->module_parts as $key => $value) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; + $sql.= " WHERE ".$this->db->decrypt('name')." LIKE '".$this->const_name."_".strtoupper($key)."'"; + $sql.= " AND entity = ".$conf->entity; + + dol_syslog(get_class($this)."::delete_".$key." sql=".$sql); + if (! $this->db->query($sql)) + { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::delete_".$key." ".$this->error, LOG_ERR); + $err++; + } + } + } + + return $err; + } + /** * Insert activation triggers from modules in llx_const * * @return int Nb of errors (0 if OK) + * @deprecated + * @see insert_module_parts() */ function insert_triggers() { @@ -1380,6 +1464,8 @@ abstract class DolibarrModules * Remove activation triggers from modules in llx_const * * @return int Nb of errors (0 if OK) + * @deprecated + * @see delete_module_parts() */ function delete_triggers() { @@ -1406,6 +1492,8 @@ abstract class DolibarrModules * Insert activation login method from modules in llx_const * * @return int Number of errors (0 if ok) + * @deprecated + * @see insert_module_parts() */ function insert_login_method() { @@ -1447,6 +1535,8 @@ abstract class DolibarrModules * Remove activation login method from modules in llx_const * * @return int Nombre d'erreurs (0 si ok) + * @deprecated + * @see delete_module_parts() */ function delete_login_method() {