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
  • Just to make you aware on the manifest you need to do something like this example below.

    <?php
    
    $installdefs = array(
       
      'logic_hooks' => array(
        
        // global logic hook
        array( 
          'module' => '',
          'hook' => 'before_save',
          'order' => 60,
          'description' => 'Do global work SON!',
          'file' => 'custom/modules/Contacts/test.php',
          'class' => 'Global_logic_hook_class',
          'function' => 'Global_logic_hook_method',
        ),
      ),    
    );
     

    Rodrigo Manara

    Sr. Developer

Reply
  • Just to make you aware on the manifest you need to do something like this example below.

    <?php
    
    $installdefs = array(
       
      'logic_hooks' => array(
        
        // global logic hook
        array( 
          'module' => '',
          'hook' => 'before_save',
          'order' => 60,
          'description' => 'Do global work SON!',
          'file' => 'custom/modules/Contacts/test.php',
          'class' => 'Global_logic_hook_class',
          'function' => 'Global_logic_hook_method',
        ),
      ),    
    );
     

    Rodrigo Manara

    Sr. Developer

Children
No Data