Add: define the constant directory if requested
example : $this->dirs[$r][0] = "output"; $this->dirs[$r][1] = "/logs"; $this->dirs[$r][2] = 1; // create the constante in llx_const
This commit is contained in:
parent
288497a55f
commit
f65f1d3ba7
@ -151,7 +151,7 @@ class Conf
|
||||
|
||||
$rootfordata = DOL_DATA_ROOT;
|
||||
// If multicompany module is enabled, we redefine the root of data
|
||||
if (! empty($this->global->MULTICOMPANY) && ! empty($this->entity)) $rootfordata.='/'.$this->entity;
|
||||
if (! empty($this->global->MAIN_MODULE_MULTICOMPANY) && ! empty($this->entity)) $rootfordata.='/'.$this->entity;
|
||||
|
||||
// Define default dir_output and dir_temp for directories of modules
|
||||
foreach($this->modules as $module)
|
||||
|
||||
@ -169,6 +169,9 @@ class DolibarrModules
|
||||
|
||||
// Remove module's menus
|
||||
if (! $err) $err+=$this->delete_menus();
|
||||
|
||||
// Remove module's directories
|
||||
if (! $err) $err+=$this->delete_dirs();
|
||||
|
||||
// Run complementary sql requests
|
||||
for ($i = 0 ; $i < sizeof($array_sql) ; $i++)
|
||||
@ -965,27 +968,94 @@ class DolibarrModules
|
||||
{
|
||||
foreach ($this->dirs as $key => $value)
|
||||
{
|
||||
$name = $this->const_name."_DIR_".strtoupper($this->dirs[$key][0]);
|
||||
$dir = $this->dirs[$key][1];
|
||||
$name = $this->const_name."_DIR_".strtoupper($this->dirs[$key][0]);
|
||||
$dir = $this->dirs[$key][1];
|
||||
$const = $this->dirs[$key][2];
|
||||
|
||||
// Define directory full path
|
||||
if (empty($conf->entity)) $dir = DOL_DATA_ROOT.'/'.$dir;
|
||||
else $dir = DOL_DATA_ROOT."/".$conf->entity.'/'.$dir;
|
||||
if (empty($conf->entity)) $fulldir = DOL_DATA_ROOT.$dir;
|
||||
else $fulldir = DOL_DATA_ROOT."/".$conf->entity.$dir;
|
||||
// Create dir if it does not exists
|
||||
if ($dir && ! file_exists($dir))
|
||||
if ($fulldir && ! file_exists($fulldir))
|
||||
{
|
||||
if (create_exdir($dir) < 0)
|
||||
if (create_exdir($fulldir) < 0)
|
||||
{
|
||||
$this->error = $langs->trans("ErrorCanNotCreateDir",$dir);
|
||||
$this->error = $langs->trans("ErrorCanNotCreateDir",$fulldir);
|
||||
dol_syslog("DolibarrModules::_init ".$this->error, LOG_ERR);
|
||||
$err++;
|
||||
}
|
||||
}
|
||||
// define the constant if requested
|
||||
if (isset($const) && $const)
|
||||
{
|
||||
$result = $this->insert_dirs($name,$dir);
|
||||
if ($result) $err++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $err;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Insert directories in llx_const
|
||||
* \return int Number of errors (0 if OK)
|
||||
*/
|
||||
function insert_dirs($name,$dir)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$err=0;
|
||||
|
||||
$sql = "SELECT count(*)";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."const";
|
||||
$sql.= " WHERE name ='".$name."'";
|
||||
$sql.= " AND entity = ".$conf->entity;
|
||||
|
||||
$result=$this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$row = $this->db->fetch_row($result);
|
||||
|
||||
if ($row[0] == 0)
|
||||
{
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,note,visible,entity)";
|
||||
$sql.= " VALUES ('".$name."','chaine','".$dir."','Directory for module ".$this->name."','0',".$conf->entity.")";
|
||||
|
||||
dol_syslog("DolibarrModules::insert_dir_output sql=".$sql);
|
||||
$resql=$this->db->query($sql);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$err++;
|
||||
}
|
||||
|
||||
return $err;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Remove directory entries
|
||||
* \return int Nombre d'erreurs (0 si ok)
|
||||
*/
|
||||
function delete_dirs()
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$err=0;
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
|
||||
$sql.= " WHERE name like '".$this->const_name."_DIR_%'";
|
||||
$sql.= " AND entity = ".$conf->entity;
|
||||
|
||||
dol_syslog("DolibarrModules::delete_tabs sql=".$sql);
|
||||
if (! $this->db->query($sql))
|
||||
{
|
||||
$err++;
|
||||
}
|
||||
|
||||
return $err;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
@ -80,6 +80,7 @@ class modSociete extends DolibarrModules
|
||||
$r++;
|
||||
$this->dirs[$r][0] = "logos";
|
||||
$this->dirs[$r][1] = "/societe/logos";
|
||||
$this->dirs[$r][2] = 1;
|
||||
|
||||
// Dependances
|
||||
$this->depends = array();
|
||||
|
||||
@ -62,6 +62,7 @@ class modSyslog extends DolibarrModules
|
||||
|
||||
$this->dirs[$r][0] = "output";
|
||||
$this->dirs[$r][1] = "/logs";
|
||||
$this->dirs[$r][2] = 1;
|
||||
|
||||
// Config pages
|
||||
$this->config_page_url = array("syslog.php");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user