Why won't this hook work?
Collapse
X
-
Thank you. The hook works GREAT now. I made a change in case anyone ever wants a hook that will write a string to a file. Each time an account record is added or changed and saved, I write a string to a little text file. Each night each of my backup bash scripts scan that file to see if that particular backups should run. The backup script sees "espobak" in there and it will run the script that creates a mysql dump of the production file and loads it into the backup file. Thanks for your help.
Code:<?php namespace Espo\Custom\Hooks\Account; use Espo\ORM\Entity; class MyHook { // An optional parameter, defines in which order hooks will be processed. // Lesser value means sooner. //public static int $order = 5; //public function __construct( // Define needed dependencies. //) {} public function afterSave(Entity $entity, array $options): void { $myfile = fopen("/usr/home/xxx/bak-scripts/switch-file.txt", "a") or die("Unable to open file!"); $txt = "espobak\n"; fwrite($myfile, $txt); fclose($myfile); } } Last edited by dev77; 03-16-2023, 11:09 PM. -
it won't work because you simply have the wrong namespace
it should namespace Espo\Custom\Hooks\Account; (Account) with s.
It should work if remove the s.Leave a comment:
-
Why won't this hook work?
Via a hook, I'm trying to 'touch' a file when I update an account record. This is my first attempt to use a hook. The hook does not work. Can anyone tell me why? Here is the code:
Maybe EspoCRM does not let you do anything outside the system via hooks?Code:<?php namespace Espo\Custom\Hooks\Accounts; use Espo\ORM\Entity; class MyHook { // An optional parameter, defines in which order hooks will be processed. // Lesser value means sooner. //public static int $order = 5; //public function __construct( // Define needed dependencies. //) {} public function afterSave(Entity $entity, array $options): void { $filename = "/usr/home/xxxxx/public_html/xxxx.com/XXX-test-php.txt"; touch($filename); } }
Help is appreciated.Tags: None

Leave a comment: