Is it possible to create a global after_save logic hook?

I need to create an after_save logic hook that will run on all or a list of modules (array of module names to check) when a record in any of them is saved.

Instead of copying and pasting logic hook definitions to each and every module, is there a way to create such a hook globally? What kind of files should I put where?

I understand that global logic hooks are placed in ./custom/modules/logic_hooks.php, but is there any way to trigger a global logic hook on the save actions of any module?

I can see that an after_save logic hook in that logic_hooks.php file does work, but it does not seem right for my situation since in my log I can see that it triggers several times on a simple page load.
Is this because SugarCRM is based on modules and making a global after_save logic hook makes it trigger on many underlying system modules that are not even touched by the user directly?

I wonder if it would cause performance implications if I simply had a condition that allows the hook to only continue if the module that triggers it is in a list of allowed modules.

Edit: Actually the problem I have now is that I am unable to log function arguments and whenever I try to Sugar tells me "there was an error while connecting to the server".

According to the documentation the after_save logic hook should have arugments $bean, $event and $arguments, but like I said - none of them can be logged and when it tries to log it the saving is actually completely prevented.

Parents Reply Children
  • I've got it that far, but my problem is currently that I cannot get any arguments in the logic hook function.

    I would normally check the $bean argument for the module name, but as I described in an edit of my original post - I can't get any arguments in the first place.

    I've managed to figure out that the function arguments I was trying to log were too large. I can log $bean->name, but I need a reference for what other properties a bean has. Is there a list of properties for it anywhere?

    So far the only way that worked for me to get anything like the module's name was get_class($bean), but I know that some modules have class names that are different than the actual module name.