feat: cli command to update teamer status on a yearly basis
closes #8699yr1eh
This commit is contained in:
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use App\Entity\Disposition;
|
||||||
|
use App\Entity\Teamer;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
#[AsCommand(name: 'app:teamer-status', description: 'Updates status of teamers depending on their disposition')]
|
||||||
|
class TeamerStatusCommand extends Command
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly EntityManagerInterface $entityManager,
|
||||||
|
private readonly LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$qb = $this
|
||||||
|
->entityManager
|
||||||
|
->getRepository(Teamer::class)
|
||||||
|
->createQueryBuilder('teamer')
|
||||||
|
;
|
||||||
|
|
||||||
|
$teamersToUpdate = $qb
|
||||||
|
->innerJoin('teamer.dispositions', 'disposition')
|
||||||
|
->where($qb->expr()->andX(
|
||||||
|
$qb->expr()->eq('teamer.status', ':teamer_status'),
|
||||||
|
$qb->expr()->eq('disposition.status', ':disposition_status')
|
||||||
|
))
|
||||||
|
->groupBy('teamer.id')
|
||||||
|
->setParameters([
|
||||||
|
'teamer_status' => Teamer::STATUS_NEW,
|
||||||
|
'disposition_status' => Disposition::STATUS_COMPLETED,
|
||||||
|
])
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
|
||||||
|
$teamersCount = count($teamersToUpdate);
|
||||||
|
|
||||||
|
if (0 === $teamersCount) {
|
||||||
|
$output->writeln('<info>No teamer status to update</info>');
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($teamersToUpdate as $teamer) {
|
||||||
|
$teamer->setStatus(Teamer::STATUS_EXISTING);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
$output->writeln('<info>Updated '.$teamersCount.' teamer status</info>');
|
||||||
|
|
||||||
|
$this->logger->info('Update teamers status', [
|
||||||
|
'teamers_count' => $teamersCount,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user