Skip to content

Commit

Permalink
New: Trigger now have a priority to define sort execution order.
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jan 31, 2012
1 parent 7d0a41f commit 0011b1d
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 2,562 deletions.
2 changes: 1 addition & 1 deletion build/exe/doliwamp/doliwamp.iss
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Source: "C:\Program Files\Wamp\bin\mysql\mysql5.0.45\*.*"; DestDir: "{app}\bin\m
; Mysql data files (does not overwrite if exists)
Source: "build\exe\doliwamp\mysql\*.*"; DestDir: "{app}\bin\mysql\data\mysql"; Flags: onlyifdoesntexist ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db"
; Dolibarr
Source: "htdocs\*.*"; DestDir: "{app}\www\dolibarr\htdocs"; Flags: ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db,custom\*,custom2\*,telephonie\*,*\conf.php,*\conf.php.mysql,*\conf.php.old,*\conf.php.postgres,*\install.forced.php,*\modBookmark4u.class.php,*\modDocument.class.php,*\modDroitPret.class.php,*\modEditeur.class.php,*\modPostnuke.class.php,*\modTelephonie.class.php,*\interface_modEditeur_Editeur.class.php*,*\bureau2crea,*\rodolphe"
Source: "htdocs\*.*"; DestDir: "{app}\www\dolibarr\htdocs"; Flags: ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db,custom\*,custom2\*,telephonie\*,*\conf.php,*\conf.php.mysql,*\conf.php.old,*\conf.php.postgres,*\install.forced.php"
Source: "dev\*.*"; DestDir: "{app}\www\dolibarr\dev"; Flags: ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db,dbmodel\*,fpdf\*,initdata\*,iso-normes\*,licence\*,phpcheckstyle\*,phpunit\*,samples\*,test\*,uml\*,xdebug\*"
Source: "doc\*.*"; DestDir: "{app}\www\dolibarr\doc"; Flags: ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db,wiki\*,plaquette\*,dev\*,images\dolibarr_screenshot2.png,images\dolibarr_screenshot3.png,images\dolibarr_screenshot4.png,images\dolibarr_screenshot5.png,images\dolibarr_screenshot6.png,images\dolibarr_screenshot7.png,images\dolibarr_screenshot8.png,images\dolibarr_screenshot9.png,images\dolibarr_screenshot10.png,images\dolibarr_screenshot11.png,images\dolibarr_screenshot12.png"
Source: "scripts\*.*"; DestDir: "{app}\www\dolibarr\scripts"; Flags: ignoreversion recursesubdirs; Excludes: ".cvsignore,.project,CVS\*,Thumbs.db,product\materiel.net.php,product\import-product.php"
Expand Down
8 changes: 4 additions & 4 deletions build/makepack-dolibarrmodule.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Goal: Goal of module
# Version: 1.0
# Author: Copyright 2008 - Author name here
# Licence: Not yet defined
# Licence: GPL
# Install: Just unpack content of module package in Dolibarr directory.
# Setup: Go on Dolibarr setup - modules page to enable module.
# Setup: Go on Dolibarr setup - modules to enable module.
#
# Files in module
htdocs/core/modules/modMyModule.class.php
htdocs/core/triggers/interface_mymodule.class.php
htdocs/mymodule/core/modules/modMyModule.class.php
htdocs/mymodule/core/triggers/interface_mymodule.class.php
htdocs/mymodule/page1.php
htdocs/mymodule/page2.php
htdocs/mymodule/sql/script1.sql
Expand Down
9 changes: 0 additions & 9 deletions build/tgz/tar_exclude.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ htdocs/conf/conf.php.mysql
htdocs/conf/conf.php.old
htdocs/conf/conf.php.postgres
htdocs/avoir
htdocs/core/modules/modBookmark4u.class.php
htdocs/core/modules/modDocument.class.php
htdocs/core/modules/modDroitPret.class.php
htdocs/core/modules/modEditeur.class.php
htdocs/core/modules/modPostnuke.class.php
htdocs/core/modules/modTelephonie.class.php
htdocs/core/triggers/interface_user.class.php
htdocs/core/triggers/interface_contractfrombill.class.php-NORUN
htdocs/core/triggers/interface_modEditeur_Editeur.class.php-NORUN
htdocs/custom
htdocs/custom2
htdocs/customleave
Expand Down
9 changes: 0 additions & 9 deletions build/zip/zip_exclude.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
*/htdocs/conf/conf.php.mysql
*/htdocs/conf/conf.php.old
*/htdocs/conf/conf.php.postgres
*/htdocs/core/modules/modBookmark4u.class.php
*/htdocs/core/modules/modClickToDial.class.php
*/htdocs/core/modules/modDocument.class.php
*/htdocs/core/modules/modDomain.class.php
*/htdocs/core/modules/modDroitPret.class.php
*/htdocs/core/modules/modEditeur.class.php
*/htdocs/core/modules/modPostnuke.class.php
*/htdocs/core/triggers/interface_user.class.php
*/htdocs/core/triggers/interface_contractfrombill.class.php-NORUN
*/htdocs/custom/*
*/htdocs/custom2/*
*/htdocs/document/*
Expand Down
2 changes: 1 addition & 1 deletion htdocs/admin/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

require("../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
require_once(DOL_DOCUMENT_ROOT."/core/triggers/interface_modNotification_Notification.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/triggers/interface_50_modNotification_Notification.class.php");

$langs->load("admin");
$langs->load("other");
Expand Down
12 changes: 7 additions & 5 deletions htdocs/admin/triggers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2005-2007 Laurent Destailleur <[email protected]>
/* Copyright (C) 2005-2012 Laurent Destailleur <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -17,21 +17,21 @@

/**
* \file htdocs/admin/triggers.php
* \brief Page de configuration et activation des triggers
* \brief Page to view triggers
*/

require("../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/interfaces.class.php");

$langs->load("admin");

if (!$user->admin)
accessforbidden();
if (!$user->admin) accessforbidden();

/*
* Action
*/

// None


/*
Expand All @@ -50,9 +50,11 @@
$template_dir = DOL_DOCUMENT_ROOT.'/core/tpl/';

$interfaces = new Interfaces($db);
$triggers = $interfaces->getTriggersList(0);
$triggers = $interfaces->getTriggersList(0,'priority');

include($template_dir.'triggers.tpl.php');

llxFooter();

$db->close();
?>
178 changes: 94 additions & 84 deletions htdocs/core/class/interfaces.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ function run_triggers($action,$object,$user,$langs,$conf)
dol_syslog(get_class($this).'::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_WARNING);
}

$nbfile = $nbtotal = $nbok = $nbko = 0;

$files = array();
$modules = array();
$orders = array();
$i=0;

foreach($conf->triggers_modules as $reldir)
{
$dir=dol_buildpath($reldir,0);
Expand All @@ -76,111 +83,116 @@ function run_triggers($action,$object,$user,$langs,$conf)
if (!is_dir($dir)) continue;

$handle=opendir($dir);
$modules = array();
$nbfile = $nbtotal = $nbok = $nbko = 0;
if (is_resource($handle))
{
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_([0-9]+)_([^_]+)_(.+)\.class\.php$/i',$file,$reg))
{
$part1=$reg[1];
$part2=$reg[2];
$part3=$reg[3];

$nbfile++;

$modName = "Interface".ucfirst($reg[2]);
$modName = "Interface".ucfirst($reg[3]);
//print "file=$file"; print "modName=$modName"; exit;
if (in_array($modName,$modules))
{
$langs->load("errors");
dol_syslog("Interface::run_triggers action=".$action." ".$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/core/triggers/"),LOG_ERR);
dol_syslog(get_class($this)."::run_triggers action=".$action." ".$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/core/triggers/"),LOG_ERR);
continue;
}

// Check if trigger file is disabled by name
if (preg_match('/NORUN$/i',$file))
else
{
continue;
include_once($dir.'/'.$file);
}

// Check if trigger file is disabled by name
if (preg_match('/NORUN$/i',$file)) continue;
// Check if trigger file is for a particular module
$qualified=true;
if (strtolower($reg[1]) != 'all')
if (strtolower($reg[2]) != 'all')
{
$module=preg_replace('/^mod/i','',$reg[1]);
$module=preg_replace('/^mod/i','',$reg[2]);
$constparam='MAIN_MODULE_'.strtoupper($module);
if (empty($conf->global->$constparam)) $qualified=false;
}

if (! $qualified)
{
dol_syslog("Interfaces::run_triggers action=".$action." Triggers for file '".$file."' need module to be enabled",LOG_INFO);
dol_syslog(get_class($this)."::run_triggers action=".$action." Triggers for file '".$file."' need module to be enabled",LOG_INFO);
continue;
}

include_once($dir."/".$file);
$objMod = new $modName($this->db);
$i=0;
if ($objMod)
{
// Bypass if workflow module is enabled and if the trigger asked to be disable in such case
if (! empty($conf->workflow->enabled) && ! empty($objMod->disabled_if_workflow))
{
dol_syslog("Interfaces::run_triggers action=".$action." Bypass triggers for file '".$file."'",LOG_INFO);
continue;
}

dol_syslog("Interfaces::run_triggers action=".$action." Launch triggers for file '".$file."'",LOG_INFO);

$modules[$i] = $modName;
//dol_syslog("Interfaces::run_triggers Launch triggers for file '".$file."'",LOG_INFO);
$result=$objMod->run_trigger($action,$object,$user,$langs,$conf);
if ($result > 0)
{
// Action OK
$nbtotal++;
$nbok++;
}
if ($result == 0)
{
// Aucune action faite
$nbtotal++;
}
if ($result < 0)
{
// Action KO
$nbtotal++;
$nbko++;
$this->errors[]=$objMod->error;
}
$i++;
}
else
{
dol_syslog("Interfaces::run_triggers action=".$action." Failed to instantiate trigger for file '".$file."'",LOG_ERR);
}

$modules[$i] = $modName;
$files[$i] = $file;
$orders[$i] = $part1.'_'.$part2.'_'.$part3; // Set sort criteria value

$i++;
}
}
closedir($handle);
}
}

asort($orders);

// Loop on each trigger
foreach ($orders as $key => $value)
{
$modName = $modules[$key];
if (empty($modName)) continue;

$objMod = new $modName($this->db);
if ($objMod)
{
dol_syslog(get_class($this)."::run_triggers action=".$action." Launch triggers for file '".$files[$key]."'",LOG_INFO);

$result=$objMod->run_trigger($action,$object,$user,$langs,$conf);
if ($result > 0)
{
// Action OK
$nbtotal++;
$nbok++;
}
if ($result == 0)
{
// Aucune action faite
$nbtotal++;
}
if ($result < 0)
{
// Action KO
$nbtotal++;
$nbko++;
$this->errors[]=$objMod->error;
}
}
else
{
dol_syslog(get_class($this)."::run_triggers action=".$action." Failed to instantiate trigger for file '".$files[$key]."'",LOG_ERR);
}
}

if ($nbko)
{
dol_syslog("Interfaces::run_triggers action=".$action." Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_ERR);
dol_syslog(get_class($this)."::run_triggers action=".$action." Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_ERR);
return -$nbko;
}
else
{
//dol_syslog("Interfaces::run_triggers Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_DEBUG);
//dol_syslog(get_class($this)."::run_triggers Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_DEBUG);
return $nbok;
}
}

/**
* Return list of triggers. Function used by admin page htdoc/admin/triggers
* Return list of triggers. Function used by admin page htdoc/admin/triggers.
* List is sorted by trigger filename so by priority to run.
*
* @param int $workflow 0=Return all triggers, 1=Return only triggers not disabled if workflow module activated
* @return array Array list of triggers
*/
function getTriggersList($workflow=0)
function getTriggersList()
{
global $conf, $langs;

Expand All @@ -204,31 +216,29 @@ function getTriggersList($workflow=0)
{
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_([0-9]+)_([^_]+)_(.+)\.class\.php/',$file,$reg))
{
$modName = 'Interface'.ucfirst($reg[2]);
$part1=$reg[1];
$part2=$reg[2];
$part3=$reg[3];

$modName = 'Interface'.ucfirst($reg[3]);
//print "file=$file"; print "modName=$modName"; exit;
if (in_array($modName,$modules))
{
$langs->load("errors");
print '<div class="error">'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/core/triggers/").'</div>';
$objMod = new $modName($this->db);

$modules[$i] = $modName;
$files[$i] = $file;
$orders[$i] = $objMod->family; // Tri par famille
$i++;
}
else
{
include_once($dir.'/'.$file);
$objMod = new $modName($this->db);

$modules[$i] = $modName;
$files[$i] = $file;
$orders[$i] = $objMod->family; // Tri par famille
$i++;
}

$files[$i] = $file;
$modules[$i] = $modName;
$orders[$i] = $part1.'_'.$part2.'_'.$part3; // Set sort criteria value

$i++;
}
}
closedir($handle);
Expand All @@ -244,27 +254,27 @@ function getTriggersList($workflow=0)
foreach ($orders as $key => $value)
{
$modName = $modules[$key];
if ($modName)
{
$objMod = new $modName($this->db);
// Bypass if workflow module is enabled and if the trigger is compatible
if ($workflow && ! empty($objMod->disabled_if_workflow)) continue;
}
if (empty($modName)) continue;

$objMod = new $modName($this->db);

// Define disabledbyname and disabledbymodule
$disabledbyname=0;
$disabledbymodule=1;
$module='';

// Check if trigger file is disabled by name
if (preg_match('/NORUN$/i',$files[$key])) $disabledbyname=1;
if (preg_match('/^interface_([^_]+)_(.+)\.class\.php/i',$files[$key],$reg))
// Check if trigger file is for a particular module
if (preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/i',$files[$key],$reg))
{
// Check if trigger file is for a particular module
$module=preg_replace('/^mod/i','',$reg[1]);
$module=preg_replace('/^mod/i','',$reg[2]);
$constparam='MAIN_MODULE_'.strtoupper($module);
if (strtolower($reg[1]) == 'all') $disabledbymodule=0;
if (strtolower($reg[2]) == 'all') $disabledbymodule=0;
else if (empty($conf->global->$constparam)) $disabledbymodule=2;
}

// We set info of modules
$triggers[$j]['picto'] = $objMod->picto?img_object('',$objMod->picto):img_object('','generic');
$triggers[$j]['file'] = $files[$key];
$triggers[$j]['version'] = $objMod->getVersion();
Expand Down
Loading

0 comments on commit 0011b1d

Please sign in to comment.