mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Add test for detecting stale workflows and enhance handler
Added a new test to check if workflows are stale in EntityWorkflowTest. Enhanced CancelStaleWorkflowHandler to handle stale workflows more accurately, including checking if workflows have transitioned recently. Updated EntityWorkflow entity to cascade remove workflow steps. Refactor tests for handler, to avoid using $kernel during tests
This commit is contained in:
@@ -56,7 +56,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
|
||||
* @var Collection<int, EntityWorkflowStep>&Selectable<int, EntityWorkflowStep>
|
||||
*/
|
||||
#[Assert\Valid(traverse: true)]
|
||||
#[ORM\OneToMany(mappedBy: 'entityWorkflow', targetEntity: EntityWorkflowStep::class, cascade: ['persist'], orphanRemoval: true)]
|
||||
#[ORM\OneToMany(mappedBy: 'entityWorkflow', targetEntity: EntityWorkflowStep::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['transitionAt' => \Doctrine\Common\Collections\Criteria::ASC, 'id' => 'ASC'])]
|
||||
private Collection&Selectable $steps;
|
||||
|
||||
@@ -488,4 +488,36 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
|
||||
{
|
||||
return $this->getCurrentStep()->getHoldsOnStep()->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the workflow has become stale after a given date.
|
||||
*
|
||||
* This function checks the creation date and the transition states of the workflow steps.
|
||||
* A workflow is considered stale if:
|
||||
* - The creation date is before the given date and no transitions have occurred since the creation.
|
||||
* - Or if there are no transitions after the given date.
|
||||
*
|
||||
* @param \DateTimeImmutable $at the date to compare against the workflow's status
|
||||
*
|
||||
* @return bool true if the workflow is stale after the given date, false otherwise
|
||||
*/
|
||||
public function isStaledAt(\DateTimeImmutable $at): bool
|
||||
{
|
||||
// if there is no transition since the creation, then the workflow is staled
|
||||
if ('initial' === $this->getCurrentStep()->getCurrentStep()
|
||||
&& null === $this->getCurrentStep()->getTransitionAt()
|
||||
) {
|
||||
if (null === $this->getCreatedAt()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->getCreatedAt() < $at) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->getCurrentStepChained()->getPrevious()->getTransitionAt() < $at;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user