Details

    • Type: Story
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.3.0-b1
    • Component/s: None
    • Labels:

      Description

      Our current events (e.g. Services::add) typically only trigger after the service is created.

      We should add an option for events to be triggered Before an action and After an action. Existing events will then need to be deprecated and setup to perform the Before or After action to maintain backward compatibility.

      1. We will need Before and After events available for all of the current events

        Activity

        tyson Tyson Phillips (Inactive) created issue -
        tyson Tyson Phillips (Inactive) made changes -
        Field Original Value New Value
        Story Points 8
        tyson Tyson Phillips (Inactive) made changes -
        Epic Link CORE-2764 [ 13922 ]
        jonathan Jonathan Reissmueller made changes -
        Assignee Tyson Phillips [ tyson ]
        jonathan Jonathan Reissmueller made changes -
        Fix Version/s 5.3.0-b1 [ 11711 ]
        Hide
        jonathan Jonathan Reissmueller added a comment -

        I'd love to see:

        1. A simplified way to call events
        2. Plugins having more control over the input and output of methods with events

        To that end I was thinking we could add the following method to the AppModel class:

            /**
             * Executes the given event
             *
             * @param string $event_name The name of the event to trigger
             * @param array $params The list of parameters to submit to the event handlers
             * @return array The list of parameters that were submitted along with any modifications made to them
             *  by the event handlers.  In addition a __return__ item is included with the return array.
             */
            protected function executeAndParseEvent($event_name, $params) {
                $eventFactory = $this->getFromContainer('util.events');
                $eventListener = $eventFactory->listener();
                $eventListener->register($event_name);
                $event = $eventListener->trigger(
                    $eventFactory->event($event_name, $params)
                );
        
                $return = ['__return__' => $event->getReturnValue()];
                $event_params = $event->getParams();
                if (is_array($event_params)) {
                    foreach ($event_params as $event_param => $data) {
                        if (array_key_exists($event_param, $params)) {
                            $return[$event_param] = $data;
                        }
                    }
                }
        
                return $return;
            }
        

        Then to trigger an event and allow it to update the submitted data, an event could be called as such:

         		extract($this->executeAndParseEvent('Packages.add', compact(['package_id', 'vars'])));
        

        The call to extract() would override the submitted variables with the updated version (or the same thing if no updates were made).

        Show
        jonathan Jonathan Reissmueller added a comment - I'd love to see: A simplified way to call events Plugins having more control over the input and output of methods with events To that end I was thinking we could add the following method to the AppModel class: /** * Executes the given event * * @param string $event_name The name of the event to trigger * @param array $params The list of parameters to submit to the event handlers * @ return array The list of parameters that were submitted along with any modifications made to them * by the event handlers. In addition a __return__ item is included with the return array. */ protected function executeAndParseEvent($event_name, $params) { $eventFactory = $ this ->getFromContainer('util.events'); $eventListener = $eventFactory->listener(); $eventListener->register($event_name); $event = $eventListener->trigger( $eventFactory->event($event_name, $params) ); $ return = ['__return__' => $event->getReturnValue()]; $event_params = $event->getParams(); if (is_array($event_params)) { foreach ($event_params as $event_param => $data) { if (array_key_exists($event_param, $params)) { $ return [$event_param] = $data; } } } return $ return ; } Then to trigger an event and allow it to update the submitted data, an event could be called as such: extract($ this ->executeAndParseEvent('Packages.add', compact(['package_id', 'vars']))); The call to extract() would override the submitted variables with the updated version (or the same thing if no updates were made).
        jonathan Jonathan Reissmueller made changes -
        Rank Ranked higher
        jonathan Jonathan Reissmueller made changes -
        Sprint 5.3.0 Sprint 2 [ 139 ]
        jonathan Jonathan Reissmueller made changes -
        Rank Ranked higher
        jonathan Jonathan Reissmueller made changes -
        Labels Developer
        jonathan Jonathan Reissmueller made changes -
        Assignee Jonathan Reissmueller [ jonathan ]
        jonathan Jonathan Reissmueller made changes -
        Remaining Estimate 0 minutes [ 0 ]
        Time Spent 58 minutes [ 3480 ]
        Worklog Id 15297 [ 15297 ]
        jonathan Jonathan Reissmueller made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        jonathan Jonathan Reissmueller made changes -
        Time Spent 58 minutes [ 3480 ] 3 hours, 35 minutes [ 12900 ]
        Worklog Id 15300 [ 15300 ]
        jonathan Jonathan Reissmueller made changes -
        Time Spent 3 hours, 35 minutes [ 12900 ] 3 hours, 54 minutes [ 14040 ]
        Worklog Id 15303 [ 15303 ]
        jonathan Jonathan Reissmueller made changes -
        Status In Progress [ 3 ] In Review [ 5 ]
        Resolution Fixed [ 1 ]
        jonathan Jonathan Reissmueller made changes -
        Time Spent 3 hours, 54 minutes [ 14040 ] 7 hours, 11 minutes [ 25860 ]
        Worklog Id 15305 [ 15305 ]
        jonathan Jonathan Reissmueller made changes -
        Link This issue blocks CORE-2791 [ CORE-2791 ]
        jonathan Jonathan Reissmueller made changes -
        Link This issue blocks CORE-2791 [ CORE-2791 ]
        jonathan Jonathan Reissmueller made changes -
        Status In Review [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            jonathan Jonathan Reissmueller
            Reporter:
            tyson Tyson Phillips (Inactive)
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Fix Release Date:
              27/Jan/22

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 7 hours, 11 minutes
              7h 11m

                Agile