Fix: store triggers path to $conf

This commit is contained in:
Regis Houssin 2010-04-02 17:09:26 +00:00
parent b484519393
commit 0bee9e9362
5 changed files with 88 additions and 44 deletions

View File

@ -70,13 +70,16 @@ class modMyModule extends DolibarrModules
// If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
// If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
$this->picto='generic';
// Defined if the directory /mymodule/inc/triggers/ contains triggers or not
$this->triggers = 0;
// Data directories to create when module is enabled.
// Example: this->dirs = array("/mymodule/temp");
$this->dirs = array();
$r=0;
// Relative path to module style sheet if exists. Example: '/mymodule/mycss.css'.
// Relative path to module style sheet if exists. Example: '/mymodule/css/mycss.css'.
$this->style_sheet = '';
// Config pages. Put here list of php page names stored in admmin directory used to setup module.

View File

@ -23,7 +23,6 @@
*/
require("../main.inc.php");
include_once(DOL_DOCUMENT_ROOT ."/interfaces.class.php");
if (!$user->admin)
accessforbidden();
@ -56,17 +55,13 @@ print " <td align=\"center\">".$langs->trans("Active")."</td>\n";
print " <td align=\"center\">&nbsp;</td>\n";
print "</tr>\n";
// Define dir directory
$interfaces=new Interfaces($db);
$interfaces->getModulesTriggers();
$handle=opendir($dir);
$files = array();
$modules = array();
$orders = array();
$i = 0;
foreach($interfaces->dir as $dir)
foreach($conf->triggers_modules as $dir)
{
// Check if directory exists
if (!is_dir($dir)) continue;

View File

@ -53,12 +53,13 @@ class Conf
//! Used to store entity for multi-company (default 1)
var $entity=1;
var $css_modules = array();
var $tabs_modules = array();
var $need_smarty = array();
var $modules = array();
var $css_modules = array();
var $tabs_modules = array();
var $triggers_modules = array();
var $need_smarty = array();
var $modules = array();
var $logbuffer = array();
var $logbuffer = array();
/**
* Constructor
@ -80,6 +81,9 @@ class Conf
function setValues($db)
{
dol_syslog("Conf::setValues");
// Directory of core triggers
$this->triggers_modules[] = DOL_DOCUMENT_ROOT . "/includes/triggers";
// Avoid warning if not defined
if (empty($this->db->dolibarr_main_db_encryption)) $this->db->dolibarr_main_db_encryption=0;
@ -124,6 +128,13 @@ class Conf
$this->tabs_modules[$params[0]][]=$value;
//print 'xxx'.$params[0].'-'.$value;
}
// If this is constant for triggers activated by a module
if (preg_match('/^MAIN_MODULE_([A-Z]+)_TRIGGERS$/i',$key,$regs) && $value)
{
$modulename = strtolower($regs[1]);
$pathoftrigger = DOL_DOCUMENT_ROOT.'/'.$modulename.'/inc/triggers/';
$this->triggers_modules[] = $pathoftrigger;
}
// If this is constant to force a module directories (used to manage some exceptions)
// Should not be used by modules
if (preg_match('/^MAIN_MODULE_([A-Z_]+)_DIR_/i',$key,$reg) && $value)

View File

@ -89,6 +89,9 @@ class DolibarrModules
// Insert new pages for tabs into llx_const
if (! $err) $err+=$this->insert_tabs();
// Insert activation triggers
if (! $err) $err+=$this->insert_triggers();
// Insere les constantes associees au module dans llx_const
if (! $err) $err+=$this->insert_const();
@ -181,6 +184,9 @@ class DolibarrModules
// Remove activation of module's new tabs
if (! $err) $err+=$this->delete_tabs();
// Remove activation of module's triggers
if (! $err) $err+=$this->delete_triggers();
// Remove list of module's available boxes
if (! $err && $options != 'noboxes') $err+=$this->delete_boxes();
@ -1199,6 +1205,66 @@ class DolibarrModules
return $err;
}
/**
* \brief Insert activation triggers from modules in llx_const
* \return int Number of errors (0 if ok)
*/
function insert_triggers()
{
global $conf;
$err=0;
if (! empty($this->triggers))
{
$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."_TRIGGERS",1);
$sql.= ", 'chaine'";
$sql.= ", ".$this->db->encrypt($this->triggers,1);
$sql.= ", null";
$sql.= ", '0'";
$sql.= ", ".$conf->entity;
$sql.= ")";
dol_syslog("DolibarrModules::insert_triggers sql=".$sql);
$resql=$this->db->query($sql);
}
return $err;
}
/**
* \brief Remove activation triggers from modules in llx_const
* \return int Nombre d'erreurs (0 si ok)
*/
function delete_triggers()
{
global $conf;
$err=0;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name')." LIKE '".$this->const_name."_TRIGGERS'";
$sql.= " AND entity = ".$conf->entity;
dol_syslog("DolibarrModules::delete_triggers sql=".$sql);
if (! $this->db->query($sql))
{
$this->error=$this->db->lasterror();
dol_syslog("DolibarrModules::delete_triggers ".$this->error, LOG_ERR);
$err++;
}
return $err;
}
}
?>

View File

@ -62,11 +62,8 @@ class Interfaces
{
dol_syslog('interface::run_triggers was called with wrong parameters object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_WARNING);
}
// Load the list of directories containing triggers
$this->getModulesTriggers();
foreach($this->dir as $dir)
foreach($conf->triggers_modules as $dir)
{
// Check if directory exists
if (!is_dir($dir)) continue;
@ -155,34 +152,6 @@ class Interfaces
return $nbok;
}
}
/**
* \brief Returns the list of directories containing triggers.
* \return array List of directories.
*/
function getModulesTriggers()
{
global $conf;
// Directory of core triggers
$this->dir[] = DOL_DOCUMENT_ROOT . "/includes/triggers";
foreach($conf->global as $key => $value)
{
if (preg_match('/^MAIN_TRIGGER_/',$key))
{
if ($value)
{
if (preg_match('/^MAIN_TRIGGER_([[:alnum:]]*)$/',$key,$regs))
{
$modulename = strtolower($regs[1]);
$pathoftrigger = DOL_DOCUMENT_ROOT.'/'.$modulename.'/inc/triggers/';
$this->dir[] = $pathoftrigger;
}
}
}
}
}
}
?>