-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Workflow] Event parameters #20789
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
[Workflow] Event parameters #20789
Conversation
Padam87
commented
Dec 6, 2016
Q | A |
---|---|
Branch? | 3.2 |
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #20774 (partially) |
License | MIT |
Doc PR | - |
de976d7
to
52eccf9
Compare
I'm not sure about this use case. You are mixing the concern here. I mean: You are using the event as a data bag and IMHO this is not the right place do it. In your example, the tracking number should be a property of the Order. With the new implement, the tracking number is volatile, and IMHO, it's not a good idea. So for now, I'm 👎 with this PR. |
Please read the issue, I have explained why this is a good option to have. Otherwise you split your code related to one logic in half. |
I might be agree that parameters could be needed. But I would like to have the opinion of @stof and / or @Nyholm before changing my vote. Anyway, about the implementation, What about using the |
Ok, let's add some flexibility here. |
52eccf9
to
f44fc7c
Compare
Hello @Padam87 Could you take time to finish this one? If you can't and if you agree, I can push directly into your fork to finish it. Just tell me ;) |
Oups. Sorry. I did not see you updated the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
(failures are not related)
* | ||
* @return Transition|null | ||
* @return null|Transition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change should be reverted
I've read the issue and Im not sure why this is needed.
I agree with this. The workflow component is not a data bag. I need help to understand why // Controller.php
if ($workflow->can($order, 'start_shipping')) {
$workflow->apply($order, 'start_shipping', ['tracking_number' => $trackingCodeService->getCode()]);
}
// EventListener.php
public function onStartShipping(Event $event)
{
/** @var Order $order */
$order = $event->getSubject();
$order->setTrackingNumber($event->getParameter('tracking_number'));
$this->orderMailer->send(/* ... */) // The mail contains the tracking code
$em->flush();
} ... is better than: // Controller.php
if ($workflow->can($order, 'start_shipping')) {
$workflow->apply($order, 'start_shipping');
}
// EventListener.php
public function onStartShipping(Event $event)
{
/** @var Order $order */
$order = $event->getSubject();
$order->setTrackingNumber($this->trackingCodeService->getCode());
$this->orderMailer->send(/* ... */) // The mail contains the tracking code
$em->flush();
} |
Just to be clear: I'm still not convinced with this PR. But it does not make the component worst ; that's why I added my vote. But actually it's a +0 ;) If someone is against it, I will change my vote. |
Right now Im not convinced that this PR is needed. But it is probably because I do not know the specific scenario that @Padam87 know. =) |
There are no specific scenarios here, every example i would give could be solved in another way. (Code in controller, another service, 2 transitions instead of 1 etc). I think parameters are a nice, uniform way to do all these, and to have every transition related change to the subject done at one place. You guys clearly have a different opinion about this, so closing... |
I've read the issue, because I have the same necessity to pass parameters trough the event to the event listener. Let me explain my use case: If there are other solutions, they are welcome. |
Hi, our use case for this is the delayed expiration of online articles. As we manage publishing and expiration through a job queue, expiring an article actually sets it in the state "going offline" and adds an expiration job to our job queue. This is done in the article's workflow subscriber so that we can be sure that as long as we're using the workflow component everywhere in our project, it takes care of adding jobs to the queue and so forth. Because of different reasons we need the ability to delay these jobs (they actually allow to set an execution time). As far as I see our options are:
The formal problem here is that standard Petri Nets don't seem to support this. Maybe there are some parallels to colored Petri nets (https://en.wikipedia.org/wiki/Coloured_Petri_net) where markings/tokens can have colors (i.e., meta data). But the meta data we're talking about in this PR is more for a single transition and not the marking store. But option (1) and (2) both don't feel right. I understand the point of @Padam87: There are other ways to solve this but having that in the Workflow component would make it so much easier, just like the meta data for the definition of transitions already helped us out a lot (e.g., we're using it to restrict certain workflow transitions to specific user roles which is easy to configure and read and works perfectly). So what would be the best way to solve this? Maybe we're overseeing a good alternative. Edit: Just found this: #29146 (comment) (its even using an article as the example). Seems like a mixture of (1) and (3) and colored Petri Nets (as the marking now holds meta data). I'd still love to leave the article entity out of this but maybe that's the most flexible way of doing this. |
Please open a new issue |