Hook loops
Collapse
X
-
I find error in my code it's option - 'ignoreHook'! Must be 'skipHooks'
PHP Code:$this->getEntityManager()->saveEntity($entity, ['skipWorkflow' => true, 'skipHooks' => true]);Leave a comment:
-
The skipAll option fixed the Hook restart error. Thanks!
Опция skipAll исправила ошибку зацикливания хука. Благодарю!
Final code:
Конечный код:
PHP Code:<?php namespace Espo\Custom\Hooks\Account; use Espo\ORM\Entity; class AccountNew extends \Espo\Core\Hooks\Base { public function afterSave(Entity $entity, array $options = array()) { $GLOBALS['log']->warning('AccountNew - working!'); if ($entity->isNew()&& empty($entity->get('website'))) { $GLOBALS['log']->warning('AccountNew - website is empty!'); $entity->set('website', 'www.website.com'); $this->getEntityManager()->saveEntity($entity, ['skipAll' => true]); } } }Leave a comment:
-
Disconnected all workflows, the number of repetitions was reduced to two.
Отключил все рабочие потоки, количество повторений сократилось до двух.
I save entities in workflows and hooks as follows:
Сохраняю сущности в рабочих потоках и хуках следующим образом:PHP Code:$this->getEntityManager()->saveEntity($entity, array('skipWorkflow' => true, 'ignoreHook' => true));Leave a comment:
-
Hook loops
The hook should run once after saving, but runs four times. Code of the Hook:
Хук должен запускаться только один раз, после сохранения, но запускается четыре раза. Код хука:
Log entries after the hook condition is met:PHP Code:<?php namespace Espo\Custom\Hooks\Account; use Espo\ORM\Entity; class AccountNew extends \Espo\Core\Hooks\Base { public function afterSave(Entity $entity, array $options = array()) { $GLOBALS['log']->warning('AccountNew - working!'); if ($entity->isNew()&& empty($entity->get('website')) && empty($options['ignoreHook'])) { $GLOBALS['log']->warning('AccountNew - website is empty!'); $entity->set('website', 'www.website.com'); $this->getEntityManager()->saveEntity($entity, ['ignoreHook' => true]); } } }
Записи лога, после выполнения условия хука:
If there are two hooks, they are launched six or eight times. How to run the hook only once, after saving?PHP Code:[2019-01-28 07:51:01] Espo.WARNING: AccountNew - working! [] [] [2019-01-28 07:51:01] Espo.WARNING: AccountNew - website is empty! [] [] [2019-01-28 07:51:01] Espo.WARNING: AccountNew - working! [] [] [2019-01-28 07:51:02] Espo.WARNING: AccountNew - working! [] [] [2019-01-28 07:51:18] Espo.WARNING: AccountNew - working! [] []
Если хука два, то они запускаются шесть или восемь раз.Как запускать хук только один раз, после сохранения?Last edited by Kirill; 01-28-2019, 09:52 AM.

Leave a comment: