diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php index a132706d7..0984a3740 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php @@ -135,6 +135,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface if (!$this->steps->contains($step)) { $this->steps[] = $step; $step->setEntityWorkflow($this); + $this->stepsChainedCache = null; } return $this; @@ -332,32 +333,26 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface public function isFinal(): bool { - $steps = $this->getStepsChained(); + foreach ($this->getStepsChained() as $step) { + if ($step->isFinal()) { + return true; + } + }; - if (1 === count($steps)) { - // the initial step cannot be finalized - return false; - } - - /** @var EntityWorkflowStep $last */ - $last = end($steps); - - return $last->isFinal(); + return false; } public function isFreeze(): bool { $steps = $this->getStepsChained(); - if (1 === count($steps)) { - // the initial step cannot be finalized - return false; + foreach ($this->getStepsChained() as $step) { + if ($step->isFreezeAfter()) { + return true; + } } - /** @var EntityWorkflowStep $last */ - $last = end($steps); - - return $last->getPrevious()->isFreezeAfter(); + return false; } public function isUserSubscribedToFinal(User $user): bool @@ -434,7 +429,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface $newStep->setCurrentStep($step); // copy the freeze - if ($this->getCurrentStep()->isFreezeAfter()) { + if ($this->isFreeze()) { $newStep->setFreezeAfter(true); } diff --git a/src/Bundle/ChillMainBundle/Tests/Entity/Workflow/EntityWorkflowTest.php b/src/Bundle/ChillMainBundle/Tests/Entity/Workflow/EntityWorkflowTest.php index c89101c5b..91783a77b 100644 --- a/src/Bundle/ChillMainBundle/Tests/Entity/Workflow/EntityWorkflowTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Entity/Workflow/EntityWorkflowTest.php @@ -24,30 +24,30 @@ final class EntityWorkflowTest extends TestCase { $entityWorkflow = new EntityWorkflow(); - $entityWorkflow->getCurrentStep()->setFinalizeAfter(true); $entityWorkflow->setStep('final'); + $entityWorkflow->getCurrentStep()->setIsFinal(true); - $this->assertTrue($entityWorkflow->isFinalize()); + $this->assertTrue($entityWorkflow->isFinal()); } public function testIsFinalizeWith4Steps() { $entityWorkflow = new EntityWorkflow(); - $this->assertFalse($entityWorkflow->isFinalize()); + $this->assertFalse($entityWorkflow->isFinal()); $entityWorkflow->setStep('two'); - $this->assertFalse($entityWorkflow->isFinalize()); + $this->assertFalse($entityWorkflow->isFinal()); $entityWorkflow->setStep('previous_final'); - $this->assertFalse($entityWorkflow->isFinalize()); + $this->assertFalse($entityWorkflow->isFinal()); - $entityWorkflow->getCurrentStep()->setFinalizeAfter(true); + $entityWorkflow->getCurrentStep()->setIsFinal(true); $entityWorkflow->setStep('final'); - $this->assertTrue($entityWorkflow->isFinalize()); + $this->assertTrue($entityWorkflow->isFinal()); } public function testIsFreeze() @@ -64,11 +64,8 @@ final class EntityWorkflowTest extends TestCase $this->assertFalse($entityWorkflow->isFreeze()); - $entityWorkflow->getCurrentStep()->setFreezeAfter(true); - - $this->assertFalse($entityWorkflow->isFreeze()); - $entityWorkflow->setStep('freezed'); + $entityWorkflow->getCurrentStep()->setFreezeAfter(true); $this->assertTrue($entityWorkflow->isFreeze());