Logic Hook Help.....Beginner...Sorry :(

I’m not getting my logic hook to call the class/method for some reason.
I’m SURE I’m doing something really stupid…not a highly seasoned OOP PHP guy.

In general, I’m trying to run some custom code when an Account record is saved. (Essentially updating a field in the Account record with some external data.)

For some reason, the logic_hook.php file executes, but the accountsDomainExp.php file ‘seems’ not to fire.

Can anyone point me in the right direction?

logic_hooks.php in custom/accounts folder:

$hook_array[‘after_save’][] = Array(81, ‘updateDomainExpirationDate’, ‘custom/modules/Accounts/accountsDomainExp.php’,‘accountsDomainExp’, ‘updateDomainExpDate’);

file_put_contents(‘custom/modules/Accounts/hookFile.txt’, "Before Method Called!! " . date(“l jS \of F Y h:i:s A”) . “\n”, FILE_APPEND);

I’m Using the file_put_contents function just to see if it’s firing…and THIS ONE Above “IS” actually firing (3 times actually…which may be a separate issue all togehter.)

**Class file - accountsDomainExp.php **
I’m using the file_put_contents as a way to ‘see’ if/where the code is firing…BUT, I’m simply NOT getting any of them to fire.

<?php /* Commented out just to make sure it wasn't preventing anything if (!defined('sugarEntry') || !sugarEntry) { die('Not A Valid Entry Point'); } */ file_put_contents('custom/modules/Accounts/classsFileLoad.txt', 'Class File Called', FILE_APPEND); echo 'TOP of the Class File Here!!!'; class accountsDomainExp { file_put_contents("custom/modules/Accounts/testRun.txt", "Inside Class!!", FILE_APPEND); public function updateDomainExpDate() // Commented out the one with the parameter just to see if it made a difference // public function updateDomainExpDate($bean, $event, $arguments) { //Custom Logic file_put_contents("custom/modules/Accounts/methodCalled.txt", "The Method was Called!!", FILE_APPEND); } updateDomainExpDate(); } ?>

Sorry for the newby question…
Thanks for any point in the right direction!!

I’m not a programmer - but i’m not sure the file-put function proves the logic hook is working. This works for me…

in custom/modules/Accounts/logic_hooks.php

$hook_version = 1;
$hook_array[‘after_save’] = Array();
$hook_array[‘after_save’][] = Array(81, ‘updateDomainExpirationDate’, ‘custom/modules/Accounts/accountsDomainExp.php’, ‘accountsDomainExp’, ‘updateDomainExpDate’);

and in custom/modules/Accounts/accountsDomainExp.php

if (!defined(‘sugarEntry’) || !sugarEntry) die(‘Not A Valid Entry Point’);

class accountsDomainExp
function updateDomainExpDate($bean, $event, $arguments) {
$GLOBALS[‘log’]->debug(‘My Logic Hook works’);

Now search the log file for ’ My Logic Hook works

Thank you so much for the reply!
I actually got the problem solved.
You’re right, by me inserting all those file put contents functions it interrupted the class. I did that trying to troubleshoot an earlier problem where I had the path incorrect to that file. So I had actually solved the problem and not realized it.

Thank you again for the help everybody!

Happy days! I can’t tell you how many hours i’ve spent wrestling with an issue and as soon as i click submit to post a question - the solution arrives.

It’s almost like writing the problem down is some sort of cathartic exercise.

1 Like

Ha Haaaa!!!

Thanks again!!!