Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK: Add onAfterHandle to CommandHookInterface #5468

Open
wants to merge 6 commits into
base: 9.0
Choose a base branch
from

Conversation

mficzel
Copy link
Member

@mficzel mficzel commented Feb 14, 2025

This allows to return additional commands after the just executed one was handled. The onAfterHandle method gets the processed command plus all resulting events.

Example use cases: Add automatic translations to a freshly created node variant. Or create translations in a review workspace when changes are published to the live workspace.

Resolves: #5469

Upgrade instructions

Review instructions

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

@@ -130,6 +131,7 @@ public function handle(CommandInterface $command): void
throw $concurrencyException;
}
}
$this->commandHook->onAfterHandle($command);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line must be executed after belows if ($fullCatchUpResult->hadErrors()) { as other-wise the cr is not up to date. Though im not sure if the hook should be run in the finally block if there was an exception like $concurrencyException ... probably not. So we need to change the finally block to be catch (\Throwable) and and run the onAfterHandle only if that was not the case.

Copy link
Member Author

@mficzel mficzel Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the hook to the end of the finally block. In case the $fullCatchUpResult->hadErrors() this is never reached because an error is thrown before. That way the behavior is equal regardless wether Events or a Generator are beeing committed.

@mficzel mficzel force-pushed the feature/addOnAfterHandleToCommandHookInterface branch from 794ba0e to ba2e393 Compare February 17, 2025 13:07
@mficzel mficzel marked this pull request as ready for review February 17, 2025 13:12
@mficzel mficzel requested a review from nezaniel February 17, 2025 15:29
This allows to return additional Commands after the just executed ones were projected.
Example. Add automatic translations to a freshly created node variant.
@mficzel mficzel force-pushed the feature/addOnAfterHandleToCommandHookInterface branch from ba2e393 to 048d5c2 Compare February 18, 2025 14:54
@mficzel mficzel requested a review from kitsunet February 18, 2025 15:00
@mficzel
Copy link
Member Author

mficzel commented Feb 18, 2025

Note: After this is merged the existing use cases should be updated as well and return empty commands onHandle.

  1. https://github.com/neos/form-builder/blob/main/Classes%2FCommandHook%2FUniqueIdentifierCommandHook.php

@mficzel mficzel requested a review from mhsdesign February 18, 2025 15:03
@mficzel mficzel force-pushed the feature/addOnAfterHandleToCommandHookInterface branch 2 times, most recently from 6882723 to 58e4166 Compare February 20, 2025 12:57
@mficzel mficzel force-pushed the feature/addOnAfterHandleToCommandHookInterface branch from 58e4166 to 11dc3c4 Compare February 20, 2025 13:45
Copy link
Member

@mhsdesign mhsdesign left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Events is not API! And contains the Decorated Event which is not api either and that makes sense as this is write only ... also the time stamps etc might be cool to have

The catchup hook or projections get:

onBeforeEvent(EventInterface $eventInstance, EventEnvelope $eventEnvelope)

But we dont have the EventEnvelope at hand at the moment as this is only a thing when fetching the events again...

as we also talked about performance maybe we dont want to have each hook load the events now ... but we could hand over them the event stream to look into it ... thought the stream is wayyy to low level and requires the internal EventNormaliser too ...

Renaming the internal Events to EventsToWrite and then introduce a Events thing with only EventInterface might be a way? For accessing its eventMetaData one would still have to use a catchup hook ...

Otherwise i really like the idea and added some cool tests 🧪 :D

as we need a new `Events` API class for `onAfterHandle` in the command hooks
We dont want to use the `DecoratedEvents` as they are only needed for the write site and internal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FEATURE: CommandHooks should be able to create additional commands
2 participants