feat: complete confirmed dispositions after assignment has ended
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user