mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
More conditions to find staled workflows
This commit is contained in:
parent
b97eabf0d2
commit
ee9530d03f
@ -198,13 +198,28 @@ class EntityWorkflowRepository implements ObjectRepository
|
||||
return $this->repository->findOneBy($criteria);
|
||||
}
|
||||
|
||||
public function findWorkflowsWithoutFinalStepAndOlderThan(\DateTimeImmutable $olderThanDate)
|
||||
/**
|
||||
* Finds workflows that are not finalized and are older than the specified date.
|
||||
*
|
||||
* @param \DateTimeImmutable $olderThanDate the date to compare against
|
||||
*
|
||||
* @return list<int> the list of workflow IDs that meet the criteria
|
||||
*/
|
||||
public function findWorkflowsWithoutFinalStepAndOlderThan(\DateTimeImmutable $olderThanDate): array
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('sw');
|
||||
|
||||
$qb->select('sw.id')
|
||||
// only the workflow which are not finalized
|
||||
->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(
|
||||
$qb->expr()->orX(
|
||||
// only the workflow where all the last transition is older than transitionAt
|
||||
':olderThanDate > ALL (SELECT ews.transitionAt FROM chill_main_entity_workflow_step ews WHERE ews.transitionAt IS NOT NULL AND ews.entityWorkflow = sw.id)',
|
||||
// or the workflow which have only the initial step, with no transition
|
||||
'1 = (SELECT COUNT(ews.id) FROM chill_main_entity_workflow_step ews WHERE ews.step = :initial AND ews.transitionAt IS NULL AND ews.createdAt < :olderThanDate AND ews.entityWorkflow = sw.id)',
|
||||
)
|
||||
)
|
||||
->andWhere('sw.createdAt < :olderThanDate')
|
||||
->setParameter('olderThanDate', $olderThanDate);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user