ok logic hooks are driving me insane at this point.
I have a couple of them built up in one module with the logic_hooks.php file itself stored at /custom/modulename/ext/LogicHooks/filename… and the code behind for the logic hook itself stored at /custom/modulename/file - that all works fine, they’re after_save logic hooks, can throw as much there as I want with different files.
Now I’m trying to add a file to a different module for logic hooks. Currently the logic file itself just does a write to debug logger to say “hey it worked!” kind of thing. Tried the above path for file location, it errors. Tried using extended with a logic_hooks.ext.php as noted to do - errors, tried just logic_hooks.php inside /custom/extended/modules/modulename etc… errors. Tried adding it directly to the custom/modules/logic_hooks.php file… errors, all with multiple variations on where I store the actual logic file (custom module folder or not). Tried throwing the logic_hooks.php file directly at /custom/modules/modulename/logic_hooks.php, which I was seeing multiple instances of where it would call to the logic file at /modules/modulename/logicfile.php (projects is one I saw multiple instances of this) .
All of them result in the same, I go into a record within the module, click edit, save… it says “error saving record”…
Log file shows
Creating new instance of hook class MoveDataFromClient without parameters
Hook called: ::server_round_trip
Calling MySQLi::disconnect()
No useful debug information there though, nothing in php error logs either.
Will be spinning over to my 7.12.7 instance to test similar, but wondering if anyone else has had this issue? Is it that my initial logic hook file is in the wrong spot, but it works… as long as I don’t add more? Also noticed if I try to create even a before_save logic hook, added to the array of the file that I have after_save logic hooks working (new array created, set as before_save - all fine), that it gives me the same issue on error saving record.
I’ve read through the logic_hooks documentation, it throws a quick mention to use the extended framework AFTER it walks you through setting up a logic hook. Have looked through extension framework documentation as well - which lead me to the above variations of testing, and all resulting in issues. After trying on 7.x to see if it’s maybe another code change related to 8.x, will be starting by recreating my working Logic hook file via ext to see if that has any affect, but wanted to swing through here first to see if there is anything glaring I’m missing.
Can you clarify a working path related to file save locations when working with multiple logic hooks?
Should I be creating the logic_hooks.php file in /custom/extenstions/modules/modulename/ext/logichooks/file…
Then the actual logical file should be saved at
/custom/modules/modulename/filename.php
Is that correct? that seems to be the common path for overrides and adding items… but it seems to not be working when I add a second file … I have one working at say /custom/extensions/modules/module1/ext/logichooks/logic_hooks.php
and the file at /custom/modules/module1/logicalfile.php
but if I go to add a new logic hook file to /custom/extensions/modules/module2/ext/logichooks/logic_hooks.php with a logic file at /custom/modules/module2/logicalfile2.php … it errors.
Should note within both of them at /custom/modules/modulename/ext/logichooks there is a logic_hooks.ext.php file created… so it LOOKS like the logic hook file override is working correctly… but even if I add a new array to module1 with a different trigger point such as before_save… it still errors.
Is this an issue specific to 8, or my file set up?
What about the contents of your file, sometimes people clear the hookArray twice (thus preventing the first hook from taking effect, because the second one clears it).
The place for the file with the actual hook class and code is irrelevant, as long as you reference it correctly in the logic hook definition.
The definition files go in custom/Extension/modules/<TheModule>/Ext/LogicHooks/
and an important thing to do is to check (after a QR&R) that they all got consolidated into a file somewhere under custom/modules/<TheModule>/Ext/
<?php
// Do not store anything in this file that is not part of the array or the hook
//version. This file will be automatically rebuilt in the future.
$hook_version = 1;
$hook_array = Array();
// position, file, function
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(
71,
'MoveDataFromClientToAuthServ',
'custom/modules/SVCS_Auth_Svcs/LH_MoveDataFromClient.php',
'MoveDataFromClient',
'movedatafromclient');
logic file is like the below - most of it is commented out so it just writes a log message, but still errors.
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class MoveDataFromClient
{
function movedatafromclient($bean, $event, $arguments)
{
$GLOBALS['log']->debug('MovinClientBeans is in the function');
/*
$check = $bean->isupdated_c;
if($check == 0)
{
$firstNote_id = $bean->id;
$GLOBALS['log']->debug('MovinClientBeans auth id is' . $firstNote_id);
//Get client bean id
$clientbean = $bean->get_linked_beans('clnts_clients_svcs_auth_svcs','clnts_clients_svcs_auth_svcs');
//Loop it
foreach($clientbean as $clients)
{
$clientid = $clients->id;
$GLOBALS['log']->debug('MovinClientBeans id is' . $firstNote_id);
}
}
*/
}
}
consolidated file is the logichooks.ext.php file - it’s there in the module/ext/ folder as expected. Also tried a change to the logic file path in the above code and QR&R’d it and verified that the file path change showed up in the logichooks.ext. php file… so it IS picking it up correctly.
Only one instance of the $hook_array = Array();
Then also the individual $hook_array[‘after_save’] = Array(); for each type of event called.
SuiteCRM logs do show that the new instance of the method / class is called, but then it results in a mySQL disconnect and on the front end just shows “error saving record”…
Any possible folder/file permissions that would be causing this? Have the standard 755 set with the 775 set on custom, cache, and such… Doesn’t make sense that I can build all the after_save I want on one module, but if I try to create it using the same path on a different module, it errors. Or if I try creating a before_save (not setting a second hook_array= Array()) and it errors still.