Issue description
It should be possible to define triggers (or event handlers?). Code should be held in a directory triggers next to the directories domain and services.
Developer comments
Triggers are created on the command line with the new [http://www.topincs.com/adminreference/topincs.create-trigger, create-trigger] command. This creates a topic of type _Topincs trigger_ with id %ID% writes a file into %STORE_DIR%/php/triggers/%ID%.php. The user has to 1) specify when the trigger is run and 2) code what the trigger should do.
1) *Specify:* edit the trigger topic to specify which events the trigger is triggered by. Currently there is four events: _name event_, _occurrence event_, _role event_, and _topic event_. For each of those events a respective type has to be specified and at least one event type out of: before insert, before update, before delete, after insert, after update, after delete.
2) *Code:* the trigger is passed on execution the id of the topic in the variable %$topic_id%. From there he usually will get the Tobject and do whatever he needs to do, e.g. to calculate the duration of a works session:
[%$session = Tobject::get($topic_id);
if ($session->has_start() && $session->has_end()) {
$session->set_duration($session->get_start()->diff($session->get_end());
}%]
Use cases
When a work session in the issue store is finalized (the end date is set), the working time on the corresponding issue should be updated.
When an issue in the issues store is resolved (resolving date is set), the corresponding product version should be updated.
|
Work sessions4
Start |
2011-11-16T09:42:09
|
End |
2011-11-16T10:23:49
|
Participant |
Robert Cerny
|
Start |
2011-11-17T08:15:24
|
End |
2011-11-17T16:55:05
|
Participant |
Robert Cerny
|
Start |
2011-11-18T10:08:22
|
End |
2011-11-18T11:43:56
|
Participant |
Robert Cerny
|
Start |
2011-11-18T14:36:21
|
End |
2011-11-18T14:56:42
|
Participant |
Robert Cerny
|
|