CleanupGdprCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 28
c 1
b 0
f 0
dl 0
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 19 1
A execute() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace DERHANSEN\SfEventMgt\Command;
13
14
use DERHANSEN\SfEventMgt\Service\MaintenanceService;
15
use Symfony\Component\Console\Attribute\AsCommand;
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Input\InputOption;
20
use Symfony\Component\Console\Output\OutputInterface;
21
use Symfony\Component\Console\Style\SymfonyStyle;
22
use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24
#[AsCommand(
25
    'sf_event_mgt:cleanup:gdpr',
26
    'Delete registrations of expired events (registrations for events with no enddate will be ignored).'
27
)]
28
class CleanupGdprCommand extends Command
29
{
30
    public function configure(): void
31
    {
32
        $this
33
            ->addArgument(
34
                'days',
35
                InputArgument::REQUIRED,
36
                'Amount of days reduced from todays date for expired event selection'
37
            )
38
            ->addOption(
39
                'softDelete',
40
                's',
41
                InputOption::VALUE_NONE,
42
                'If set, registration will not be deleted hard, but only flagged as deleted'
43
            )
44
            ->addOption(
45
                'ignoreEventRestriction',
46
                'i',
47
                InputOption::VALUE_NONE,
48
                'If set, simply all available registrations will be selected and deleted. Use with care!'
49
            );
50
    }
51
52
    protected function execute(InputInterface $input, OutputInterface $output): int
53
    {
54
        $maintenanceService = GeneralUtility::makeInstance(MaintenanceService::class);
55
        $io = new SymfonyStyle($input, $output);
56
        $io->title($this->getDescription());
57
        $days = (int)$input->getArgument('days');
58
        $softDelete = (bool)$input->getOption('softDelete');
59
        $ignoreEventRestriction = (bool)$input->getOption('ignoreEventRestriction');
60
        $amountDeleted = $maintenanceService->processGdprCleanup($days, $softDelete, $ignoreEventRestriction);
61
        $io->success($amountDeleted . ' registrations deleted.');
62
63
        return Command::SUCCESS;
64
    }
65
}
66