Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Workflow] Allow transition when many places in transition froms #22017

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 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Symfony/Component/Workflow/Tests/WorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ public function testGetEnabledTransitions()

$subject->marking = array('c' => 1, 'e' => 1);
$transitions = $workflow->getEnabledTransitions($subject);
$this->assertCount(1, $transitions);
$this->assertSame('t5', $transitions[0]->getName());
$this->assertCount(2, $transitions);
$this->assertSame('t2', $transitions[0]->getName());
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @sebdec this change is not valid. To apply t2, the subject must be in all froms, in this case "b" and "c", but only "c" is marked.

Copy link
Contributor Author

@sebdec sebdec Mar 16, 2017

Choose a reason for hiding this comment

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

I was thinking it was a bug
Is there a solution to apply t2 if the subject is at least in one from ("b" or "c")?

$this->assertSame('t5', $transitions[1]->getName());
}

public function testGetEnabledTransitionsWithSameNameTransition()
Expand Down
20 changes: 13 additions & 7 deletions src/Symfony/Component/Workflow/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,25 @@ public function getDefinition()
return $this->definition;
}

/**
* Check if this marking has at least one place in the froms transition.
* Check also if the transition is guarded for this marking.
*
* @param object $subject
* @param Marking $marking
* @param Transition $transition
*
* @return bool
*/
private function doCan($subject, Marking $marking, Transition $transition)
{
foreach ($transition->getFroms() as $place) {
if (!$marking->has($place)) {
return false;
if ($marking->has($place) && true !== $this->guardTransition($subject, $marking, $transition)) {
return true;
}
}

if (true === $this->guardTransition($subject, $marking, $transition)) {
return false;
}

return true;
return false;
}

/**
Expand Down