Skip to content

[WIP] [Workflow] Choose which Workflow events should be dispatched #36633

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

Closed
wants to merge 7 commits into from
Closed

[WIP] [Workflow] Choose which Workflow events should be dispatched #36633

wants to merge 7 commits into from

Conversation

stewartmalik
Copy link
Contributor

@stewartmalik stewartmalik commented Apr 30, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #36617
License MIT
Doc PR WIP

Allow users to specify which events should be dispatched when calling workflow->apply().


  • still requires configuration method to be discussed
  • submit changes to the documentation

@@ -6,7 +6,7 @@ CHANGELOG

* Added context to `TransitionException` and its child classes whenever they are thrown in `Workflow::apply()`
* Added `Registry::has()` to check if a workflow exists
* Added support for `$context[Workflow::DISABLE_ANNOUNCE_EVENT] = true` when calling `workflow->apply()` to not fire the announce event
* Added support for specifying which events should be dispatched when calling `workflow->apply()`
Copy link
Contributor

@noniagriconomie noniagriconomie Apr 30, 2020

Choose a reason for hiding this comment

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

💎
But i think you should write a BC somewhere as devs need to rewrite with the new way

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, this is a BC Break.

IHMO, you should merge the default configuration (the one passed to the construct) with the one in the $context

@nicolas-grekas nicolas-grekas added this to the next milestone May 1, 2020
@@ -324,6 +326,22 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->defaultValue([])
->prototype('scalar')->end()
->end()
->arrayNode('dispatched_events')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could definitely use input on configuration here, this is my first time working on the Symfony code base and this was somewhat confusing.

I ran into issues with a number of things such as expressing an empty array in the XML configuration format, as well as having a default null value for arrayNodes.

I have worked around this by specifying all and none as allowed values for this configuration option however these are mostly hidden from the end user. The only exception is with the XML configuration where you need to specify none to remove all events from being fired.

stewartmalik and others added 4 commits May 3, 2020 00:04
Events are fired for Transitions however configured Workflow wide. Transition does make more sense in this instance.

Co-authored-by: Antoine Makdessi <antoine.makdessi@agriconomie.com>
@stewartmalik
Copy link
Contributor Author

Will be rebased when ready for final review.

@fabpot
Copy link
Member

fabpot commented Jun 24, 2020

/cc @lyrixx

Copy link
Contributor

@noniagriconomie noniagriconomie left a comment

Choose a reason for hiding this comment

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

Some minor comments :)

* Passing an array with WorkflowEvents will allow only those events to be dispatched plus
* the Guard Event.
*
* @var array|string[]
Copy link
Contributor

Choose a reason for hiding this comment

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

null also needed here

Copy link
Member

Choose a reason for hiding this comment

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

inded 👍

and please, move this property after $metadataStore (I always sort the property declaration in the same order as the construct arguments)

{
// If we don't have a dispatcher we can't dispatch the
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment is a little useless
Also if you use constants for next comparaison, comments may also be useless

Copy link
Member

Choose a reason for hiding this comment

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

I agree

Copy link
Member

@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

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

Sorry for the delay.

I left some comments about the design. Could you look at it?

Thanks

@@ -324,6 +325,22 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->defaultValue([])
->prototype('scalar')->end()
->end()
->arrayNode('dispatched_events')
->beforeNormalization()
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should handle many way to configure the same thing.
to me, the perfect config would be:

  1. no configuration => all
  2. an empty array => non
  3. an array with few items => only theses items

So I would remove the case for string. And it would allow to remove special cases for all and none.

@@ -6,7 +6,7 @@ CHANGELOG

* Added context to `TransitionException` and its child classes whenever they are thrown in `Workflow::apply()`
* Added `Registry::has()` to check if a workflow exists
* Added support for `$context[Workflow::DISABLE_ANNOUNCE_EVENT] = true` when calling `workflow->apply()` to not fire the announce event
* Added support for specifying which events should be dispatched when calling `workflow->apply()`
Copy link
Member

Choose a reason for hiding this comment

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

Indeed, this is a BC Break.

IHMO, you should merge the default configuration (the one passed to the construct) with the one in the $context

* Passing an array with WorkflowEvents will allow only those events to be dispatched plus
* the Guard Event.
*
* @var array|string[]
Copy link
Member

Choose a reason for hiding this comment

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

inded 👍

and please, move this property after $metadataStore (I always sort the property declaration in the same order as the construct arguments)

@@ -32,7 +42,7 @@ final class Definition
* @param Transition[] $transitions
* @param string|string[]|null $initialPlaces
*/
public function __construct(array $places, array $transitions, $initialPlaces = null, MetadataStoreInterface $metadataStore = null)
public function __construct(array $places, array $transitions, $initialPlaces = null, MetadataStoreInterface $metadataStore = null, array $dispatchedEvents = null)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this should be hold by the definition. It's only related to the Workflow implementation, isn't ?

{
// If we don't have a dispatcher we can't dispatch the
Copy link
Member

Choose a reason for hiding this comment

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

I agree

@noniagriconomie
Copy link
Contributor

@stewartmalik hello, do you need help to finish this one?
i would really use this feature :)
thx!

@lyrixx
Copy link
Member

lyrixx commented Aug 12, 2020

For the record, I'm working on this PR (I'll reuse all the current, then cleaning it). I'll reopen a new PR ASAP

@lyrixx
Copy link
Member

lyrixx commented Aug 12, 2020

Closing in favor of #37815

@stewartmalik Thanks a lot for your first contribution, and for your issue. I opened a new PR, where I rebased and squashed your work. So don't worry for the ownership of the feature :)

@lyrixx lyrixx closed this Aug 12, 2020
fabpot added a commit that referenced this pull request Aug 13, 2020
…atched (stewartmalik, lyrixx)

This PR was merged into the 5.2-dev branch.

Discussion
----------

[Workflow] Choose which Workflow events should be dispatched

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #36633 ; Fix #36617
| License       | MIT
| Doc PR        |

Commits
-------

cfc53ad [Workflow] Choose which Workflow events should be dispatched (fix previous commit)
d700747 [Workflow] Choose which Workflow events should be dispatched
@nicolas-grekas nicolas-grekas removed this from the next milestone Oct 5, 2020
@nicolas-grekas nicolas-grekas added this to the 5.2 milestone Oct 5, 2020
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.

[Workflow] Choose which Workflow events should be dispatched
6 participants