Skip to content

[Workflow] Digging in to the workflow component #19605

@Nyholm

Description

@Nyholm

I just started to dig in to the workflow component in order to add some documentation. I noticed some strange behaviors and I would like to ask @lyrixx (or someone else) about these.

The workflow has the concept of "places" which I first intrepid as "states". The main issue is that you can be on two places at once.

// +---+     +----+     +---+     +----+     +----+     +----+     +----+
// | a | --> | t1 | --> | b | --> | t2 | --> | c  | --> | t4 | --> | f  |
// +---+     +----+     +---+     +----+     +----+     +----+     +----+
//             |                                          ^
//             |                                          |
//             |                                          |
//             v        +---+     +----+     +----+       |
//             -------> | d | --> | t3 | --> | e  | ------
//                      +---+     +----+     +----+

When preforming t1 I will be in both place 'b' and 'd'. There is no way for me to fetch all subjects in state 'b'. Which, sure, that could be fine in some applications. But why do I need to separate 'b' and 'd'?

But as a consequence of this, we run into other issues. Say that I'm writing a blog and want a workflow for the blog post. One could imagine the following states: init, draft, review, published, trash, rejected.

You could also imagine the following translations:

  • init => draft
  • draft => review
  • trash => review
  • rejected => review
  • draft => trash
  • rejected => trash
  • review => published

Since a transaction can have multiple "froms" and "tos" it makes sense to create Transactions like:

$definition = new Definition();
$definition->addPlaces(['init', 'draft', 'review', 'published', 'trash', 'rejected']);
$definition->addTransition(new Transition('to_draft', 'init', 'draft'));
$definition->addTransition(new Transition('to_review', ['draft', 'trash', 'rejected'], 'review'));
$definition->addTransition(new Transition('to_trash', ['draft', 'rejected'], 'trash'));
$definition->addTransition(new Transition('to_publish', 'review', 'publish'));

So whenever you have a BlogPost you could check if it is possible to put this in the "review" place.

This is however not possible because the "to_review" transaction expects you to be in all "from" places ('draft', 'trash', 'rejected'). (See source)

With the current implementation you need to define transactions like:

$definition->addTransition(new Transition('to_review_from_draft', 'draft', 'review'));
$definition->addTransition(new Transition('to_review_from_trash', 'trash', 'review'));
$definition->addTransition(new Transition('to_review_from_rejected', 'rejected', 'review'));

Is this really the intention?

I suggest we should behave more like state machines and do not allow one to be in two places/states at the same time. I suggest to removing the possibility for a transaction to have multiple "to". A transaction should be something that takes you from one or more places to a defined place. This would make my initial graph look like this:

// +---+     +----+     +---+     +----+     +----+     +----+     +----+
// | a | --> | t1 | --> | b | --> | t2 | --> | c  | --> | t4 | --> | f  |
// +---+     +----+     +---+     +----+     +----+     +----+     +----+
//                        |                               ^
//                        |                               |
//                        |                               |
//                        v       +----+     +----+       |
//                        ------> | t3 | --> | e  | ------
//                                +----+     +----+

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRFC = Request For Comments (proposals about features that you want to be discussed)Workflow

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions