Announcement

Collapse
No announcement yet.

Hooks not triggered from Service class save/saveEntity function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hooks not triggered from Service class save/saveEntity function

    I have custom Hook file in custom/Espo/Custom/xxx/
    (beforeSave, afterSave)

    When editing in UI, hooks are normally triggered.

    But when I use:
    $this->entityManager->saveEntity($entity, $options)
    or
    $this->getRepository($entityType)->save($entity, $options);

    in backend files (custom/Espo/Custom/Service/xxx.php),
    these hooks are not triggered !!!
    • The changes to DB are saved correctly,
    • Log file is empty
    • tried with $options = []
    • tried with $options = ['skipHooks' => false]

    The call sequence is following:
    1a) Dropdown action in detail view or
    1b) Mass action in list view
    2) client/custom/src/xxx-handler.js ->actionDoSomething -> Espo.Ajax.postRequest()
    3) route to xxx controller action
    4) Controller class function postActionDoSomething is calling Service class function
    5) Service class (extends \Espo\Core\Templates\Services\Base) function is calling
    $this->entityManager->saveEntity($entity, []);


    My questions:
    1. Is this intended behavior or bug ?
    2. What is the proper way to apply some changes in Mass or Detail view functions with respecting all the hooks ?

  • #2
    Supposed to be triggered, no matter from where you call. Try to debug starting from your service class.

    Comment


    • #3
      From my experience, the service hooks (beforeCreateEntity for example) will be triggered only for any updates made through the UI and not via ORM saves/updates or API calls (which are ORM saves/updates). But beforeSave under the Hooks/xxxxx.php will trigger all the time.

      Is this by design or a bug?

      Comment


      • #4
        I assumed the author created a regular hook (that works on ORM level). Service/Record hooks won't work for sure.

        Comment


        • #5
          I am sorry for the confusion and thank you for your fast responses.

          I have found the problem.

          I have changed the name of Hook .php files, but did not change the class names inside respectively.
          From that moment I suppose, the system stopped to process those.

          There must have been some cache reason for continuing to work from UI. (even though I cleared the cache and did rebuild after each change)

          Comment


          • #6
            Note that if you are using OpCache, you will have to clear that as well before testing out the code changes.

            Comment

            Working...
            X