feat: complete confirmed dispositions after assignment has ended

This commit is contained in:
Björn Fromme
2024-03-14 12:18:08 +01:00
parent 2c7747fc98
commit 217996d535
4 changed files with 82 additions and 4 deletions
@@ -0,0 +1,44 @@
<?php
namespace App\Service\Cron;
use App\Entity\Disposition;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Workflow\WorkflowInterface;
class DispositionStatusService
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly WorkflowInterface $dispositionStateMachine,
private readonly LoggerInterface $logger
) {
}
public function setEndedStatus(): string
{
$endedDispositions = $this
->entityManager
->getRepository(Disposition::class)->findEndedDispositions()
;
if (0 === $count = count($endedDispositions)) {
return 'No ended dispositions to update';
}
foreach ($endedDispositions as $disposition) {
if ($this->dispositionStateMachine->can($disposition, 'complete')) {
$this->dispositionStateMachine->apply($disposition, 'complete');
}
}
$this->entityManager->flush();
$message = 'Ended '.$count.' dispositions';
$this->logger->info($message);
return $message;
}
}