Add cronjob and repository method to find and cancel stale workflows every other day

This commit is contained in:
2024-08-12 11:45:27 +02:00
committed by Julien Fastré
parent 34edb02cd0
commit 29fec50515
2 changed files with 68 additions and 0 deletions

View File

@@ -198,6 +198,19 @@ class EntityWorkflowRepository implements ObjectRepository
return $this->repository->findOneBy($criteria);
}
public function findWorkflowsWithoutFinalStepAndOlderThan(\DateTimeImmutable $olderThanDate)
{
$qb = $this->repository->createQueryBuilder('sw');
$qb->select('sw.id')
->where('NOT EXISTS (SELECT 1 FROM chill_main_entity_workflow_step ews WHERE ews.isFinal = TRUE AND ews.entityWorkflow = sw.id)')
->andWhere(':olderThanDate > ALL (SELECT ews.transitionAt FROM chill_main_entity_workflow_step ews WHERE ews.transitionAt IS NOT NULL AND ews.entityWorkflow = sw.id)')
->andWhere('sw.createdAt < :olderThanDate')
->setParameter('olderThanDate', $olderThanDate);
return $qb->getQuery()->getResult();
}
public function getClassName(): string
{
return EntityWorkflow::class;