equivalent as RecordHook but Global ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • item
    Active Community Member
    • Mar 2017
    • 1476

    equivalent as RecordHook but Global ?

    Hi,

    as i work in healthcare, we need to log all action of user.
    for this, i have create a new entity as out-of-box ActionHistoryLog. (with same field + other).

    is there any solution for make "RecordHook" Global as a Global Hook avaible for all entity ?

    i will too use :
    https://github.com/espocrm/espocrm/issues/2718 Entity Manager custom parameters
    So, i can ​select witch entity i will "log"
    if (entity->customLog == true) then log. (i don't know actually if i can access so to this custom param !?)

    With these question, i have a second :
    i will make a report panel, and display as side panel in the entity, so assignedUser can see witch other user have do some action. (read...)
    i have try with relation "children->to->parent", but the result as table in side panel is not as i will.
    So my question is : do i need to create one->to->many relation will all entity i will "log" ?

    And last question :

    can we log, "downloaded" file.. is there a equivalent of "RecordHook" who capture "download/view inline browser" ?

    Thanks
    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​
  • Kharg
    Senior Member
    • Jun 2021
    • 410

    #2
    Hi,

    Global hooks maybe?

    Comment

    • yuri
      Member
      • Mar 2014
      • 8453

      #3
      No global record hooks. You can specify the same Hook class for all entity types. As of v8.0 there are entity manager tool hooks https://github.com/espocrm/documenta...ity-manager.md. You can manipulate metadata on entity type create/update/delete, checking your custom parameter there.
      If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

      Comment

      • yuri
        Member
        • Mar 2014
        • 8453

        #4
        > can we log, "downloaded"

        The only way at the moment, is to define custom Download entryPoint in the custom directory (through I don't like such way of customization).
        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

        Comment


        • item
          item commented
          Editing a comment
          Hi Yuri,
          i understand... i will wait if one day you add this kind of functionnality.. else i will live without
          Thanks.

        • yuri
          yuri commented
          Editing a comment
          Unlikely there will be ever a special hook for Download. Better use custom Download entry point. Pass the default Download Entry Point in a constructor and call it in the run method. Try not to use class inheritance (extend) whenever it possible.
      • item
        Active Community Member
        • Mar 2017
        • 1476

        #5
        Hi Kharg,

        Global hook is when a "event" occur, like : beforeSave, beforeRemove, ...

        when a user "read" the record, there are not a hook who fire.
        I need same as global hook, but "globally beforeReadHookClassNameList + beforeUpdateHookClassNameList​"


        actually i have only this for Contact

        PHP Code:
        "beforeReadHookClassNameList": [
                "__APPEND__",
                "Espo\\Custom\\Classes\\RecordHooks\\Contact\\BeforeReadTracking"
            ],
        else i need to write manually in each recordDefs of all entity i will track :
        sample :

        PHP Code:
            "beforeReadHookClassNameList": [
                "__APPEND__",
                "Espo\\Custom\\Classes\\RecordHooks\\Common\\BeforeReadTracking"
            ],
            "beforeUpdateHookClassNameList": [
                "__APPEND__",
                "Espo\\Custom\\Classes\\RecordHooks\\Common\\BeforeUpdateTracking"
            ],
            "beforeDownloadFileHookClassNameList": [  // this don't exist of course
                "__APPEND__",
                "Espo\\Custom\\Classes\\RecordHooks\\Common\\BeforeDownloadFileTracking"
            ],​​​ 
        
        for sample code who work :

        PHP Code:
        $track = $this->metadata->get(['entityDefs', $entity->getEntityType(), 'entityTracking']);
        
                if ($track){
                    $this->em->createEntity('Tracking', [
                        'name' => $entity->get('name') .'::' .$this->user->get('userName'),
                        'action' => 'Read',
                        'userId' => $this->user->getId(),
                        'assignedUserId' => $entity->get('assignedUserId'),
                        'contactId' => $entity->getId(),
                        'date' => date('Y-m-d H:i:s'),
                        'teamsIds' => [$this->user->get('defaultTeam')],
                        'ip' => $this->getIp(),
                    ]);
                }
        Last edited by item; 07-25-2023, 10:57 AM.
        If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

        Comment

        • ThomasB
          Senior Member
          • Mar 2022
          • 163

          #6
          Originally posted by yuri
          No global record hooks. You can specify the same Hook class for all entity types. As of v8.0 there are entity manager tool hooks https://github.com/espocrm/documenta...ity-manager.md. You can manipulate metadata on entity type create/update/delete, checking your custom parameter there.
          Noticed a small spelling error in the docs:

          Hooks processed when a new custom entity type is craeted.

          craeted​ -> created

          Comment


          • yuri
            yuri commented
            Editing a comment
            Fixed. Thanks.
        • yuri
          Member
          • Mar 2014
          • 8453

          #7
          I added ActionLogger interface, one can bind a custom one for additional logging. https://github.com/espocrm/espocrm/c...be7ff461e91a8a
          If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

          Comment


          • rabii
            rabii commented
            Editing a comment
            this is very elegant, thanks Yuri
        • item
          Active Community Member
          • Mar 2017
          • 1476

          #8
          Thank you Yuri,
          with your advice, i have learn and understand many.
          and with the interface.. it's wonderfull

          the following respect all your advice

          $this->coreDownload->run( $request, $response );
          If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

          Comment

          Working...