Line 6:
Line 6:
So, to add your own code that will be triggered by a Dolibarr trigger, this is the way to process:
So, to add your own code that will be triggered by a Dolibarr trigger, this is the way to process:
+
+
1) (only for Dolibarr >= v3.2.0) in your module config file for Dolibarr (eg: /core/modules/modMyModule.class.php), add triggers->1 in module_parts:
+
<source lang="php">
+
// Defined all module parts (triggers, login, substitutions, menus, etc...) (0=disable,1=enable)
+
$this->module_parts = array('triggers' => 1);
+
//$this->module_parts = array('triggers' => 1,
+
// 'login' => 0,
+
// 'substitutions' => 0,
+
// 'menus' => 0);
+
</source>
−
1) Copy file '''htdocs/includes/triggers/interface_all_Demo.class.php''' under the new name:
+
2) Copy file '''htdocs/includes/triggers/interface_all_Demo.class.php''' under the new name:
* '''interface_all_''Xxx''.class.php'''
* '''interface_all_''Xxx''.class.php'''
or
or
Line 27:
Line 37:
−
2) Edit the file ''interface_modMyModule_Myworkflow.class.php'' to rename class ''InterfaceDemo'' by ''InterfaceMyworkflow''
+
3) Edit the file ''interface_modMyModule_Myworkflow.class.php'' to rename class ''InterfaceDemo'' by ''InterfaceMyworkflow''
Line 34:
Line 44:
−
3) Return now to edition of file to add your own code inside function ''run_trigger''.
+
4) Return now to edition of file to add your own code inside function ''run_trigger''.
This function is called at each Dolibarr business event. Put your code according to events on which you want to run. Each event is identified by a code (see following chapter to get full list of codes). So you can react or no after an event by doing just a test on variable '''$action''':
This function is called at each Dolibarr business event. Put your code according to events on which you want to run. Each event is identified by a code (see following chapter to get full list of codes). So you can react or no after an event by doing just a test on variable '''$action''':
Line 67:
Line 77:
* '''$conf''' is the object that contains all the Dolibarr configuration.
* '''$conf''' is the object that contains all the Dolibarr configuration.
−
4) Once your trigger file has been developed, last action is to test by using Dolibarr to execute the business event that should trigger your code. Warning, call of function '''run_trigger''' is encapsulated into a transaction. If your code return a KO code, the calling function may rollback the transaction (this depends on calling function).
+
5) Once your trigger file has been developed, last action is to test by using Dolibarr to execute the business event that should trigger your code. Warning, call of function '''run_trigger''' is encapsulated into a transaction. If your code return a KO code, the calling function may rollback the transaction (this depends on calling function).
Add log information inside your function '''run_trigger''' to know if your code is correctly triggered and runs correctly. For this, you can use the function
Add log information inside your function '''run_trigger''' to know if your code is correctly triggered and runs correctly. For this, you can use the function
dol_syslog("my log message", LOG_DEBUG);
dol_syslog("my log message", LOG_DEBUG);