|
|
| Line 46: |
Line 46: |
| 2)编辑文件''interface_99_modMyModule_Myworkflow.class.php'',以便将''InterfaceDemo''类重命名为''InterfaceMyworkflow'' | | 2)编辑文件''interface_99_modMyModule_Myworkflow.class.php'',以便将''InterfaceDemo''类重命名为''InterfaceMyworkflow'' |
|
| |
|
| 然后转到主页->系统信息->Dolibarr->触发器。您的触发器文件应显示在无错误列表中,表明以前的操作已成功完成。
| | 然后转到 '''主页->管理工具->关于Dolibarr->触发器'''。您的触发器文件应显示在无错误清单中,表明前面的操作已成功完成。 |
|
| |
|
| Then go on page Home -> Admin Tools -> About Dolibarr ->Triggers.
| | 3) 现在返回编辑触发器文件,将代码添加到 ''run_trigger'' 函数中。此函数在每个Dolibarr业务事件中调用。根据您希望响应的事件放置代码,每个事件都由一个代码标识(代码列表请参阅下一章),您可以通过判断变量 '''$action''' 对给定事件做出反应,也可以不做出反应: |
| Your new trigger file must appears in the list without any error message. This means preceding actions have been done successfully.
| |
| | |
| | |
| 3) 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''':
| |
|
| |
|
| <syntaxhighlight lang="PHP"> | | <syntaxhighlight lang="PHP"> |
| Line 75: |
Line 70: |
| </syntaxhighlight> | | </syntaxhighlight> |
|
| |
|
| You can do what you want into this coding part, if you check that function run_trigger returns a return code according to following rule:
| | 只要 ''run_trigger'' 函数根据以下原则返回一个返回代码,您就可以在这段代码中执行任何操作: |
| | |
| <0 if KO, 0 if nothing is done, >0 if OK
| |
|
| |
|
| You can also use, inside this function, the following preinitialized variables:
| | <0 失败,0 没有执行任何操作,>0 成功 |
|
| |
|
| *'''$object''' is the object on which action is done (see next chapter)
| | 此外,在此函数中,您可以使用以下对象: |
| *'''$user''' is the object containing all information of Dolibarr user that realizes the business event.
| |
| *'''$langs''' is the object that contains the user language and translations strings
| |
| *'''$conf''' is the object that contains all the Dolibarr configuration.
| |
|
| |
|
| | *'''$object''' 是操作所针对的对象(请参阅下一章) |
| | *'''$user''' 是执行操作的dolibarr用户的对象 |
| | *'''$langs''' 是包含dolibarr用户语言的对象 |
| | *'''$conf''' 是包含整个Dolibarr配置的对象。 |
|
| |
|
| 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). | | 4) 代码开发完成后,只需在Dolibarr中触发触发事件即可进行测试。注意,函数 '''run_trigger''' 的调用被封装在事务中。如果触发器返回 KO 代码,调用函数可能会回滚事务(这取决于调用函数)。要在函数 '''run_trigger''' 中添加日志跟踪,用以确保代码运行良好。如果您愿意,可以使用函数 dol_syslog("my log message", LOG_DEBUG); |
| 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); | |
|
| |
|
| =List of known triggers actions= | | =List of known triggers actions= |