Using after_relationship_add/delete in Users

Hi guys,

I was trying to use the after_relationship_add hook to catch when a Role or a Team is added to an User. I had no problem with Roles, but with Teams, I couldn't make it work.

Here is an example of what I have:

  • The logic_hooks.php file
<?php
$hook_version = 1;
$hook_array = Array();

$hook_array['after_relationship_add'] = Array();
$hook_array['after_relationship_add'][] = Array(1, 'Example', 'custom/modules/Users/UsersRelationshipAdd/UsersRelationshipAdd.php','AuditRolesTeamsUsersAdd', 'createAuditRegistry');

$hook_array['after_relationship_delete'] = Array();
$hook_array['after_relationship_delete'][] = Array(1, 'Example', 'custom/modules/Users/UsersRelationshipDelete/UsersRelationshipDelete.php','AuditRolesTeamsUsersDelete', 'createAuditRegistry');


?>
  • And an example of the hook file for the relationship_add event:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class AuditRolesTeamsUsersAdd{ 
    
     function createAuditRegistry(&$bean, $event, $args){
         
          $GLOBALS['log']->fatal("It works!");
         
          if($args['related_module'] == 'ACLRoles'){
               $GLOBALS['log']->fatal("It works for Roles");
              
          }
         
          if($args['related_module'] == 'Teams'){
               $GLOBALS['log']->fatal("It works for Teams");
          }
     }
}
?>

As I said before, it works for Roles but not for Teams. So, can you tell me if this works in Sugar 6.7?. If not, what other alternative I have for catching what Team was added to an User?

Thanks!

Matt Marum

Tevfik Tümer

Angel Magana