vtigerCRM-Spain

vtigerCRM-Spain::Filtering Events

http://forums.vtiger.com/viewtopic.php?t=27223

On 9/16/09, admin@a-g-c.de admin@a-g-c.de wrote:

Hi all,
I guess I found a bug in the eventing logic, or I just do not know how to use it properly. In the latter case we might have a bug in the documentation ;-)

Assuming:

  • I have two custom modules (A and B).
  • Both custom modules implement own event handlers (AHandler, BHandler) for the events vtiger.entity.aftersave and vtiger.entity.beforesave.
  • I do have the according entries in the tables vtiger_eventhandlers and vtiger_eventhandler_module as well.

After implementing the eventhandler of module B for event vtiger.entity.beforesave I realized that this event handler is executed when module A is saved (and also when module B is saved).

I had a look at the according event sources and it seems to me that there is no logic implemented that checks which event handler to use for which module. It just catches the next event handler class from the table vtiger_eventhandlers, without considering the data stored in table vtiger_eventhandlers_module (which handler to use for which module).

There is a method implemented to read vtiger_eventhandlers_module, but it is not used at all in vtiger 5.1.0!

Any clues?
Is this an open development topic?

Kind Regards
Andreas


Hi Andreas,

What you noticed is partially correct. All the events from vtiger_eventhandlers are picked up one by one and executed irrespective of the module for which it is created.

For which modules should each of the event handler be triggered, is controlled by the condition part of the event handler.

It is also possible for you to specify conditions that restrict when the handler will be executed. You might want an event to be fired only for changes in a particular module. Currently the conditions are restricted to selecting module names

Example:

require 'include/events/include.inc';
$em = new VTEventsManager($adb);
$em->registerHandler($eventName, $filePath, $className, 'moduleName in ['Contacts', 'Accounts']);

In the above example the event will only be triggered if the triggering entity is of the module Contacts or Accounts.


Regards,
Asha
vtiger Team