Hook loops

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • rinorway
    replied
    Thank you for translating in English

    Leave a comment:


  • Kirill
    replied
    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:


  • Kirill
    replied
    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:


  • tanya
    replied
    Hi,
    try 'skipAll' option
    When i save an entity in workflow with run service action and that service saves the same entity again, the stream reports a update post twice for the same update.

    Leave a comment:


  • Kirill
    replied

    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:


  • Kirill
    started a topic Hook loops

    Hook loops


    The hook should run once after saving, but runs four times. Code of the Hook:
    Хук должен запускаться только один раз, после сохранения, но запускается четыре раза. Код хука:

    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]);
            }
        }
    }
    Log entries after the hook condition is met:
    Записи лога, после выполнения условия хука:

    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! [] [] 
    
    If there are two hooks, they are launched six or eight times. How to run the hook only once, after saving?
    Если хука два, то они запускаются шесть или восемь раз.Как запускать хук только один раз, после сохранения?
    Last edited by Kirill; 01-28-2019, 09:52 AM.
Working...