There is a logic hook file in modules/Accounts/logic_hook.php. In that file I have the accounts after save logic added to call the exportAccount.php logic hook along with additional after_relationship_add and after_relationship_delete:
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(
1,
'export Account after save', // label
'custom/modules/Accounts/Ext/LogicHooks/exportAccount.php', // file
'exportAccount_LogicHook', // class
'export' // function
);
$hook_array['after_relationship_add'] = Array();
$hook_array['after_relationship_add'][] = Array(
1,
'addRelationship',
'custom/modules/Accounts/Ext/LogicHooks/exportAccount.php', // file
'exportAccount_LogicHook', // class
'export' // function
);
$hook_array['after_relationship_delete'] = Array();
$hook_array['after_relationship_delete'][] = Array(
1,
'deleteRelationship',
'custom/modules/Accounts/Ext/LogicHooks/exportAccount.php', // file
'exportAccount_LogicHook', // class
'export' // function
);
What I wanted was in an event of adding information in sub-panel I wanted to trigger the same action. Just sending a request to external program to process information.
The trigger works for sub-panel however the sub-panel information is not there. It looks to me like sub-panel info is saved into database after the export is triggered.
What the export does is connecting to the suitecrm database and pull necessary information and exports it to the external site.
Export hook code:
require_once 'include/SugarHttpClient.php';
class exportAccount_LogicHook
{
protected $client;
/**
* REST client
*
* @var string
*/
function __construct()
{
$this->setClient(new SugarHttpClient());
}
/**
* Set client to talk to SNIP
*
* @param SugarHttpClient $client
*/
public function setClient(SugarHttpClient $client)
{
$this->client = $client;
return $this;
}
public function export($bean, $event, $arguments)
{
$vars = [];
file_put_contents("mylogfile.log", "export func\r\n", FILE_APPEND);
if (isset($bean->fetched_row['id'])) {
file_put_contents("mylogfile.log", "- id " . $bean->fetched_row['id'] . "\r\n", FILE_APPEND);
$vars['action'] = 'modifyDealer';
$vars['key'] = 'no';
$vars['val'] = $bean->fetched_row['dealer_nbr_c'];
} else {
file_put_contents("mylogfile.log", " new dealer \r\n", FILE_APPEND);
$vars['action'] = 'modify';
$vars['flag']['new'] = true;
}
// sleep(10);
$this->exportJob($vars);
}
/**
* Execute given job
*
* @param SchedulersJob $job
*/
public function exportJob($info)
{
file_put_contents("mylogfile.log", "execute func\r\n", FILE_APPEND);
global $sugar_config;
$data = http_build_query($info);
$response = $this->client->callRest($sugar_config['export_url'], $data);
// file_put_contents("mylogfile.log", $response . "\r\n" . $data . "\r\n", FILE_APPEND);
file_put_contents("mylogfile.log", $response . "\r\n" . $data . "\r\n", FILE_APPEND);
}
}