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:
2024-10-21 17:39:31 +02:00
parent 1d708a481d
commit 527cf23d4f
6 changed files with 73 additions and 29 deletions

View File

@@ -205,13 +205,13 @@ class EntityWorkflowRepository implements ObjectRepository
*
* @param \DateTimeImmutable $olderThanDate the date to compare against
*
* @return list<int> the list of workflow IDs that meet the criteria
* @return iterable<EntityWorkflow>
*/
public function findWorkflowsWithoutFinalStepAndOlderThan(\DateTimeImmutable $olderThanDate): array
public function findWorkflowsWithoutFinalStepAndOlderThan(\DateTimeImmutable $olderThanDate): iterable
{
$qb = $this->repository->createQueryBuilder('sw');
$qb->select('sw.id')
$qb->select('sw')
// only the workflow which are not finalized
->where(sprintf('NOT EXISTS (SELECT 1 FROM %s ews WHERE ews.isFinal = TRUE AND ews.entityWorkflow = sw.id)', EntityWorkflowStep::class))
->andWhere(
@@ -227,7 +227,7 @@ class EntityWorkflowRepository implements ObjectRepository
->setParameter('initial', 'initial')
;
return $qb->getQuery()->getResult();
return $qb->getQuery()->toIterable();
}
public function getClassName(): string