-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCleanTokenCommand.php
More file actions
65 lines (53 loc) · 1.89 KB
/
CleanTokenCommand.php
File metadata and controls
65 lines (53 loc) · 1.89 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
61
62
63
64
65
<?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 Doctrine\ORM\EntityManagerInterface;
use Novactive\Bundle\eZProtectedContentBundle\Entity\ProtectedTokenStorage;
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
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
parent::__construct();
$this->entityManager = $entityManager;
}
protected function configure(): void
{
$this
->setName('novaezprotectedcontent:cleantoken')
->setDescription('Remove expired token in the DB');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
/** @var ProtectedTokenStorageRepository $protectedTokenStorageRepository */
$protectedTokenStorageRepository = $this->entityManager->getRepository(ProtectedTokenStorage::class);
$entities = $protectedTokenStorageRepository->findExpired();
foreach ($entities as $entity) {
$this->entityManager->remove($entity);
}
$this->entityManager->flush();
$io->success(sprintf('%d entities deleted', count($entities)));
$io->success('Done.');
}
}