Working With SugarCRM Logic Hooks

There are two ways of installing logic hooks: one works fine, the other seems to cause problems.

The way not to use is a log_hooks array within the manifest file as follows.

'logic_hooks' => array(
array(
'module' => 'Emails',
'hook' => 'after_save',
'order' => 200,
'description' => 'This logic hook looks at a saved email and adds a       history record.',
'file' => 'custom/include/classes/History.class.php',
'class' => 'History',
'function' => 'addHistory',
),

You are much better to user the copy process as follows. Follow exactly the directory names.
Also, make the actual file name something unique, so that it doesn’t match an existing file for other logic hooks.

'copy' => array (
0 => array (
'from' => '/Files/custom/Extension/modules/Emails/Ext/LogicHooks/history_logic_hooks.php',
'to' => 'custom/Extension/modules/Emails/Ext/LogicHooks/history_logic_hooks.php',
),

Where the file referred to (eg.history_logic_hooks.php) holds the definition like this.

// logic hook to handle history // 3-oct-2017
$hook_array['after_save'][]
= Array( 200, 'Save History', 'custom/include/classes/history.class.php', 'History', 'addHistory' );

Of course you also have to copy the class file you refer to.

SugarCRM Module Loader Issue

When trying to unload a new module I kept getting a bank screen, and errors in sugarcrm.log. The upload uses sys_get_temp_dir() to get the temp directory and this was set outside the document root, hence the error.

But how do yo set the system temp directly? Finally I tracked it down. You need to add the following to the php.ini file. You think it would be there, commented out, like lots of other parameters.

sys_temp_dir = "/Users/gregambrose/tmp"

Obviously, restart apache.

I hope that helps somebody

Greg

SugarCRM Relationships

There are plenty of examples on-line of working with relationships between modules in Sugar using load_relationship, but one problem I’ve recently solved is, how do you know the name of the relationship you want to load. Contacts, Cases etc are easy but there are lots of others you may be interested in.

Well the answer is simple, so long as you can debug your code with something like X-debug. If you can’t you should be as it makes life for a developer very easy.

load_relationship is within the SugarBean class (data/SugarBean.php). Step into it and break just after this line.

$fieldDefs = $this->getFieldDefinitions();

Now look through all the $fieldDefs until you find the relationship you are interested in. I’m interested in membership, so this is the one I want. The {name} is what you use {relationship} is the name you will see when you look at relationships in Studio.

I hope this helps someone.

SugarCRM Inbound Emails

I’ve just recently been asked to add a logic hook to inbound emails, so that the emails could be used to be updated the associated contacts. I’m not going to provide the full details here but just a few hints.

Firstly when you set up Inbound Emails, you must make the mailbox a group mailbox, if you want to use logic hooks. Non group emails go to the table email_cache not emails.

Note also that it is the scheduled task that polls the email account for new emails, so you need to wait for it run, normally once a minute.

Also, inbound emails only get imported if they remain unread. Read emails are ignored. Once Sugar has imported them, they are set as read on the server.

To setup a logic hook, you need to do it on after_save on the Emails module.

Thats all, but I can provide source if you need it.

Greg