-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCleanTokenCommand.php
More file actions
60 lines (47 loc) · 1.65 KB
/
CleanTokenCommand.php
File metadata and controls
60 lines (47 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* NovaeZProtectedContentBundle.
*
* @package Novactive\Bundle\eZProtectedContentBundle
*
* @author Novactive
* @copyright 2023 Novactive
* @license https://github.com/Novactive/eZProtectedContentBundle/blob/master/LICENSE MIT Licence
*/
declare(strict_types=1);
namespace Novactive\Bundle\eZProtectedContentBundle\Command;
use Novactive\Bundle\eZProtectedContentBundle\Repository\ProtectedTokenStorageRepository;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class CleanTokenCommand extends Command
{
public function __construct(
protected ProtectedTokenStorageRepository $protectedTokenStorageRepository,
) {
parent::__construct();
}
protected function configure(): void
{
$this
->setName('novaezprotectedcontent:cleantoken')
->setDescription('Remove expired token in the DB');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$entities = $this->protectedTokenStorageRepository->findExpired();
$io->comment(sprintf('%d entities to delete', count($entities)));
foreach ($entities as $entity) {
$this->protectedTokenStorageRepository->remove($entity);
}
$this->protectedTokenStorageRepository->flush();
$io->success(sprintf('%d entities deleted', count($entities)));
$io->success('Done.');
return Command::SUCCESS;
}
}