Add log if trigger not launched
Rename property ->workflow of a trigger by property ->disabled_if_workflow. This make code easier to understand.
This commit is contained in:
parent
d881cfafd7
commit
f43baaddf5
@ -62,7 +62,7 @@ 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);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($conf->triggers_modules as $dir)
|
foreach($conf->triggers_modules as $dir)
|
||||||
{
|
{
|
||||||
// Check if directory exists
|
// Check if directory exists
|
||||||
@ -71,13 +71,13 @@ class Interfaces
|
|||||||
$handle=opendir($dir);
|
$handle=opendir($dir);
|
||||||
$modules = array();
|
$modules = array();
|
||||||
$nbfile = $nbtotal = $nbok = $nbko = 0;
|
$nbfile = $nbtotal = $nbok = $nbko = 0;
|
||||||
|
|
||||||
while (($file = readdir($handle))!==false)
|
while (($file = readdir($handle))!==false)
|
||||||
{
|
{
|
||||||
if (is_readable($dir."/".$file) && preg_match('/^interface_([^_]+)_(.+)\.class\.php$/i',$file,$reg))
|
if (is_readable($dir."/".$file) && preg_match('/^interface_([^_]+)_(.+)\.class\.php$/i',$file,$reg))
|
||||||
{
|
{
|
||||||
$nbfile++;
|
$nbfile++;
|
||||||
|
|
||||||
$modName = "Interface".ucfirst($reg[2]);
|
$modName = "Interface".ucfirst($reg[2]);
|
||||||
//print "file=$file"; print "modName=$modName"; exit;
|
//print "file=$file"; print "modName=$modName"; exit;
|
||||||
if (in_array($modName,$modules))
|
if (in_array($modName,$modules))
|
||||||
@ -86,7 +86,7 @@ class Interfaces
|
|||||||
dol_syslog("Interface::run_triggers ".$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/includes/triggers/"),LOG_ERR);
|
dol_syslog("Interface::run_triggers ".$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/includes/triggers/"),LOG_ERR);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if trigger file is disabled by name
|
// Check if trigger file is disabled by name
|
||||||
if (preg_match('/NORUN$/i',$file))
|
if (preg_match('/NORUN$/i',$file))
|
||||||
{
|
{
|
||||||
@ -100,22 +100,27 @@ class Interfaces
|
|||||||
$constparam='MAIN_MODULE_'.strtoupper($module);
|
$constparam='MAIN_MODULE_'.strtoupper($module);
|
||||||
if (empty($conf->global->$constparam)) $qualified=false;
|
if (empty($conf->global->$constparam)) $qualified=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $qualified)
|
if (! $qualified)
|
||||||
{
|
{
|
||||||
dol_syslog("Interfaces::run_triggers Triggers for file '".$file."' need module to be enabled",LOG_INFO);
|
dol_syslog("Interfaces::run_triggers Triggers for file '".$file."' need module to be enabled",LOG_INFO);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
dol_syslog("Interfaces::run_triggers Launch triggers for file '".$file."'",LOG_INFO);
|
|
||||||
include_once($dir."/".$file);
|
include_once($dir."/".$file);
|
||||||
$objMod = new $modName($this->db);
|
$objMod = new $modName($this->db);
|
||||||
$i=0;
|
$i=0;
|
||||||
if ($objMod)
|
if ($objMod)
|
||||||
{
|
{
|
||||||
// Bypass if workflow module is enabled and if the trigger is compatible
|
// Bypass if workflow module is enabled and if the trigger asked to be disable in such case
|
||||||
if ($conf->workflow->enabled && $objMod->workflow) continue;
|
if ($conf->workflow->enabled && ! empty($objMod->disabled_if_workflow))
|
||||||
|
{
|
||||||
|
dol_syslog("Interfaces::run_triggers Launch triggers for file '".$file."'",LOG_INFO);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
dol_syslog("Interfaces::run_triggers Launch triggers for file '".$file."'",LOG_INFO);
|
||||||
|
|
||||||
$modules[$i] = $modName;
|
$modules[$i] = $modName;
|
||||||
//dol_syslog("Interfaces::run_triggers Launch triggers for file '".$file."'",LOG_INFO);
|
//dol_syslog("Interfaces::run_triggers Launch triggers for file '".$file."'",LOG_INFO);
|
||||||
$result=$objMod->run_trigger($action,$object,$user,$langs,$conf);
|
$result=$objMod->run_trigger($action,$object,$user,$langs,$conf);
|
||||||
@ -139,11 +144,15 @@ class Interfaces
|
|||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dol_syslog("Interfaces::run_triggers Failed to instantiate trigger for file '".$file."'",LOG_ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir($handle);
|
closedir($handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($nbko)
|
if ($nbko)
|
||||||
{
|
{
|
||||||
dol_syslog("Interfaces::run_triggers Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_ERR);
|
dol_syslog("Interfaces::run_triggers Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_ERR);
|
||||||
@ -155,28 +164,28 @@ class Interfaces
|
|||||||
return $nbok;
|
return $nbok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Return list of triggers.
|
* \brief Return list of triggers.
|
||||||
*/
|
*/
|
||||||
function getTriggersList($workflow=0)
|
function getTriggersList($workflow=0)
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
|
|
||||||
$html = new Form($db);
|
$html = new Form($db);
|
||||||
|
|
||||||
$files = array();
|
$files = array();
|
||||||
$modules = array();
|
$modules = array();
|
||||||
$orders = array();
|
$orders = array();
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
foreach($conf->triggers_modules as $dir)
|
foreach($conf->triggers_modules as $dir)
|
||||||
{
|
{
|
||||||
// Check if directory exists
|
// Check if directory exists
|
||||||
if (!is_dir($dir)) continue;
|
if (!is_dir($dir)) continue;
|
||||||
|
|
||||||
$handle=opendir($dir);
|
$handle=opendir($dir);
|
||||||
|
|
||||||
while (($file = readdir($handle))!==false)
|
while (($file = readdir($handle))!==false)
|
||||||
{
|
{
|
||||||
if (is_readable($dir.'/'.$file) && preg_match('/^interface_([^_]+)_(.+)\.class\.php/',$file,$reg))
|
if (is_readable($dir.'/'.$file) && preg_match('/^interface_([^_]+)_(.+)\.class\.php/',$file,$reg))
|
||||||
@ -188,7 +197,7 @@ class Interfaces
|
|||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
print '<div class="error">'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/includes/triggers/").'</div>';
|
print '<div class="error">'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/includes/triggers/").'</div>';
|
||||||
$objMod = new $modName($db);
|
$objMod = new $modName($db);
|
||||||
|
|
||||||
$modules[$i] = $modName;
|
$modules[$i] = $modName;
|
||||||
$files[$i] = $file;
|
$files[$i] = $file;
|
||||||
$orders[$i] = $objMod->family; // Tri par famille
|
$orders[$i] = $objMod->family; // Tri par famille
|
||||||
@ -198,7 +207,7 @@ class Interfaces
|
|||||||
{
|
{
|
||||||
include_once($dir.'/'.$file);
|
include_once($dir.'/'.$file);
|
||||||
$objMod = new $modName($db);
|
$objMod = new $modName($db);
|
||||||
|
|
||||||
$modules[$i] = $modName;
|
$modules[$i] = $modName;
|
||||||
$files[$i] = $file;
|
$files[$i] = $file;
|
||||||
$orders[$i] = $objMod->family; // Tri par famille
|
$orders[$i] = $objMod->family; // Tri par famille
|
||||||
@ -208,12 +217,12 @@ class Interfaces
|
|||||||
}
|
}
|
||||||
closedir($handle);
|
closedir($handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
asort($orders);
|
asort($orders);
|
||||||
|
|
||||||
$triggers = array();
|
$triggers = array();
|
||||||
$j = 0;
|
$j = 0;
|
||||||
|
|
||||||
// Loop on each trigger
|
// Loop on each trigger
|
||||||
foreach ($orders as $key => $value)
|
foreach ($orders as $key => $value)
|
||||||
{
|
{
|
||||||
@ -224,7 +233,7 @@ class Interfaces
|
|||||||
// Bypass if workflow module is enabled and if the trigger is compatible
|
// Bypass if workflow module is enabled and if the trigger is compatible
|
||||||
if ($workflow && !$objMod->workflow) continue;
|
if ($workflow && !$objMod->workflow) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define disabledbyname and disabledbymodule
|
// Define disabledbyname and disabledbymodule
|
||||||
$disabledbyname=0;
|
$disabledbyname=0;
|
||||||
$disabledbymodule=1;
|
$disabledbymodule=1;
|
||||||
@ -238,13 +247,13 @@ class Interfaces
|
|||||||
if (strtolower($reg[1]) == 'all') $disabledbymodule=0;
|
if (strtolower($reg[1]) == 'all') $disabledbymodule=0;
|
||||||
else if (empty($conf->global->$constparam)) $disabledbymodule=2;
|
else if (empty($conf->global->$constparam)) $disabledbymodule=2;
|
||||||
}
|
}
|
||||||
|
|
||||||
$triggers[$j]['picto'] = $objMod->picto?img_object('',$objMod->picto):img_object('','generic');
|
$triggers[$j]['picto'] = $objMod->picto?img_object('',$objMod->picto):img_object('','generic');
|
||||||
$triggers[$j]['file'] = $files[$key];
|
$triggers[$j]['file'] = $files[$key];
|
||||||
$triggers[$j]['version'] = $objMod->getVersion();
|
$triggers[$j]['version'] = $objMod->getVersion();
|
||||||
$triggers[$j]['status'] = img_tick();
|
$triggers[$j]['status'] = img_tick();
|
||||||
if ($disabledbyname > 0 || $disabledbymodule > 1) $triggers[$j]['status'] = " ";
|
if ($disabledbyname > 0 || $disabledbymodule > 1) $triggers[$j]['status'] = " ";
|
||||||
|
|
||||||
$text ='<b>'.$langs->trans("Description").':</b><br>';
|
$text ='<b>'.$langs->trans("Description").':</b><br>';
|
||||||
$text.=$objMod->getDesc().'<br>';
|
$text.=$objMod->getDesc().'<br>';
|
||||||
$text.='<br><b>'.$langs->trans("Status").':</b><br>';
|
$text.='<br><b>'.$langs->trans("Status").':</b><br>';
|
||||||
@ -259,7 +268,7 @@ class Interfaces
|
|||||||
if ($disabledbymodule == 1) $text.=$langs->trans("TriggerActiveAsModuleActive",$module).'<br>';
|
if ($disabledbymodule == 1) $text.=$langs->trans("TriggerActiveAsModuleActive",$module).'<br>';
|
||||||
if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'<br>';
|
if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'<br>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$triggers[$j]['info'] = $html->textwithpicto('',$text);
|
$triggers[$j]['info'] = $html->textwithpicto('',$text);
|
||||||
$j++;
|
$j++;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user