New: add generic function for module parts

This commit is contained in:
Regis Houssin 2012-02-23 15:42:03 +01:00
parent 2624c7154b
commit 46ad02cbc8
2 changed files with 91 additions and 1 deletions

View File

@ -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

View File

@ -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()
{