mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 10:33:49 +00:00
Add command to remove old draft accompanying periods
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Command;
|
||||
|
||||
use Chill\PersonBundle\Service\AccompanyingPeriod\OldDraftAccompanyingPeriodRemoverInterface;
|
||||
use DateInterval;
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class RemoveOldDraftAccompanyingPeriodCommand extends Command
|
||||
{
|
||||
private LoggerInterface $logger;
|
||||
|
||||
private OldDraftAccompanyingPeriodRemoverInterface $remover;
|
||||
|
||||
public function __construct(LoggerInterface $logger, OldDraftAccompanyingPeriodRemoverInterface $remover)
|
||||
{
|
||||
parent::__construct('chill:person:remove-old-draft-period');
|
||||
|
||||
$this->logger = $logger;
|
||||
$this->remover = $remover;
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->setDescription('Remove draft accompanying period which are still draft and unused')
|
||||
->addArgument('interval', InputArgument::OPTIONAL, 'The interval for unactive periods', 'P15D');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->logger->info('[' . $this->getName() . '] started', [
|
||||
'interval' => $input->getArgument('interval'),
|
||||
]);
|
||||
|
||||
try {
|
||||
$interval = new DateInterval($input->getArgument('interval'));
|
||||
} catch (Exception $e) {
|
||||
$this->logger->error('[' . $this->getName() . '] bad interval');
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->remover->remove($interval);
|
||||
|
||||
$this->logger->info('[' . $this->getName() . '] end of command');
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user