feat: complete confirmed dispositions after assignment has ended
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Command;
|
namespace App\Command;
|
||||||
|
|
||||||
|
use App\Service\Cron\DispositionStatusService;
|
||||||
use App\Service\Cron\FeedbackReminderService;
|
use App\Service\Cron\FeedbackReminderService;
|
||||||
use App\Service\Cron\FlushLogsService;
|
use App\Service\Cron\FlushLogsService;
|
||||||
use App\Service\Cron\UploadReminderService;
|
use App\Service\Cron\UploadReminderService;
|
||||||
@@ -20,7 +21,8 @@ class CronCommand extends Command
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly FlushLogsService $flushLogsService,
|
private readonly FlushLogsService $flushLogsService,
|
||||||
private readonly UploadReminderService $uploadReminderService,
|
private readonly UploadReminderService $uploadReminderService,
|
||||||
private readonly FeedbackReminderService $feedbackReminderService
|
private readonly FeedbackReminderService $feedbackReminderService,
|
||||||
|
private readonly DispositionStatusService $dispositionStatusService
|
||||||
) {
|
) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
@@ -45,6 +47,9 @@ class CronCommand extends Command
|
|||||||
$message = $this->feedbackReminderService->sendFeedbackReminders();
|
$message = $this->feedbackReminderService->sendFeedbackReminders();
|
||||||
$io->info($message);
|
$io->info($message);
|
||||||
|
|
||||||
|
$message = $this->dispositionStatusService->setEndedStatus();
|
||||||
|
$io->info($message);
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,4 +208,33 @@ class DispositionRepository extends ServiceEntityRepository
|
|||||||
->getResult()
|
->getResult()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Disposition[]|array
|
||||||
|
*/
|
||||||
|
public function findEndedDispositions(): array
|
||||||
|
{
|
||||||
|
$qb = $this->createQueryBuilder('disposition');
|
||||||
|
|
||||||
|
return $qb
|
||||||
|
->innerJoin('disposition.assignment', 'assignment')
|
||||||
|
->innerJoin('assignment.destination', 'destination')
|
||||||
|
->where($qb->expr()->andX(
|
||||||
|
$qb->expr()->neq('disposition.status', ':status'),
|
||||||
|
$qb->expr()->orX(
|
||||||
|
$qb->expr()->andX(
|
||||||
|
$qb->expr()->isNotNull('assignment.dateTo'),
|
||||||
|
$qb->expr()->lte('assignment.dateTo', ':dateTo')
|
||||||
|
),
|
||||||
|
$qb->expr()->lte('destination.dateTo', ':dateTo')
|
||||||
|
)
|
||||||
|
))
|
||||||
|
->setParameters([
|
||||||
|
'status' => Disposition::STATUS_COMPLETED,
|
||||||
|
'dateTo' => new \DateTimeImmutable(),
|
||||||
|
])
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class DispositionVoter extends Voter
|
|||||||
$disposition = $subject;
|
$disposition = $subject;
|
||||||
|
|
||||||
return match ($attribute) {
|
return match ($attribute) {
|
||||||
static::VIEW, static::EDIT, static::CONTRACT, static::INVOICE => $this->assertAdministrativeAccess() || $this->assertTeamerAccess($token, $disposition),
|
static::VIEW, static::EDIT, static::CONTRACT, static::INVOICE => $this->assertAdministrativeAccess() || $this->assertTeamerAccess($disposition),
|
||||||
static::DELETE => $this->assertAdminAccess(),
|
static::DELETE => $this->assertAdminAccess(),
|
||||||
static::FEEDBACK => $this->assertHouseManagerAccess($token, $disposition),
|
static::FEEDBACK => $this->assertHouseManagerAccess($token, $disposition),
|
||||||
default => false,
|
default => false,
|
||||||
@@ -85,12 +85,12 @@ class DispositionVoter extends Voter
|
|||||||
&& $destination->getDateTo() < new \DateTimeImmutable();
|
&& $destination->getDateTo() < new \DateTimeImmutable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function assertTeamerAccess(TokenInterface $token, Disposition $disposition): bool
|
private function assertTeamerAccess(Disposition $disposition): bool
|
||||||
{
|
{
|
||||||
if (false === $this->security->isGranted('ROLE_TEAMER')) {
|
if (false === $this->security->isGranted('ROLE_TEAMER')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $token->getUser()->getTeamer() === $disposition->getTeamer();
|
return $this->security->getUser()->getTeamer() === $disposition->getTeamer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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