Passed
Push — master ( 0d18d8...40235e )
by Torben
28:04 queued 24:57
created

CleanupGdprCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
nc 1
nop 2
dl 0
loc 12
rs 9.9666
c 1
b 0
f 0
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\Command\Command;
16
use Symfony\Component\Console\Input\InputArgument;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
use Symfony\Component\Console\Style\SymfonyStyle;
21
use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23
/**
24
 * Class CleanupGdprCommand
25
 */
26
class CleanupGdprCommand extends Command
27
{
28
    /**
29
     * Configuring the command options
30
     */
31
    public function configure()
32
    {
33
        $this
34
            ->addArgument(
35
                'days',
36
                InputArgument::REQUIRED,
37
                'Amount of days reduced from todays date for expired event selection'
38
            )
39
            ->addOption(
40
                'softDelete',
41
                's',
42
                InputOption::VALUE_NONE,
43
                'If set, registration will not be deleted hard, but only flagged as deleted'
44
            )
45
            ->addOption(
46
                'ignoreEventRestriction',
47
                'i',
48
                InputOption::VALUE_NONE,
49
                'If set, simply all available registrations will be selected and deleted. Use with care!'
50
            );
51
    }
52
53
    /**
54
     * Execute the cleanup command
55
     *
56
     * @param InputInterface $input
57
     * @param OutputInterface $output
58
     * @return int
59
     */
60
    protected function execute(InputInterface $input, OutputInterface $output)
61
    {
62
        $maintenanceService = GeneralUtility::makeInstance(MaintenanceService::class);
63
        $io = new SymfonyStyle($input, $output);
64
        $io->title($this->getDescription());
65
        $days = (int)$input->getArgument('days');
66
        $softDelete = (bool)$input->getOption('softDelete');
67
        $ignoreEventRestriction = (bool)$input->getOption('ignoreEventRestriction');
68
        $amountDeleted = $maintenanceService->processGdprCleanup($days, $softDelete, $ignoreEventRestriction);
69
        $io->success($amountDeleted . ' registrations deleted.');
70
71
        return 0;
72
    }
73
}
74