mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-26 00:24:59 +00:00
Fix Canceling of stale workflow cronjob
Refactor workflow cancellation logic to encapsulate transition checks in a dedicated method, and update CronJob handling to use entity workflows instead of IDs. Enhance test coverage to ensure proper handling and instantiate mocks for EntityManagerInterface.
This commit is contained in:
@@ -18,7 +18,9 @@ use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Clock\ClockInterface;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
|
||||
use Symfony\Component\Workflow\Metadata\MetadataStoreInterface;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use Symfony\Component\Workflow\Transition;
|
||||
|
||||
#[AsMessageHandler]
|
||||
final readonly class CancelStaleWorkflowHandler
|
||||
@@ -57,10 +59,7 @@ final readonly class CancelStaleWorkflowHandler
|
||||
$wasInInitialPosition = 'initial' === $workflow->getStep();
|
||||
|
||||
foreach ($transitions as $transition) {
|
||||
$isFinal = $metadataStore->getMetadata('isFinal', $transition);
|
||||
$isFinalPositive = $metadataStore->getMetadata('isFinalPositive', $transition);
|
||||
|
||||
if ($isFinal && !$isFinalPositive) {
|
||||
if ($this->willTransitionLeadToFinalNegative($transition, $metadataStore)) {
|
||||
$dto = new WorkflowTransitionContextDTO($workflow);
|
||||
$workflowComponent->apply($workflow, $transition->getName(), [
|
||||
'context' => $dto,
|
||||
@@ -85,4 +84,16 @@ final readonly class CancelStaleWorkflowHandler
|
||||
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
private function willTransitionLeadToFinalNegative(Transition $transition, MetadataStoreInterface $metadataStore): bool
|
||||
{
|
||||
foreach ($transition->getTos() as $place) {
|
||||
$metadata = $metadataStore->getPlaceMetadata($place);
|
||||
if (($metadata['isFinal'] ?? true) && false === ($metadata['isFinalPositive'] ?? true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user