Passed
Push — wip/remove-deprecations-for-v1... ( f97f5b )
by Tomas Norre
05:15
created

FlushQueueCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 65.85%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 35
c 2
b 0
f 0
dl 0
loc 65
ccs 27
cts 41
cp 0.6585
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 21 1
A execute() 0 25 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AOE\Crawler\Command;
6
7
/*
8
 * (c) 2020 AOE GmbH <[email protected]>
9
 *
10
 * This file is part of the TYPO3 Crawler Extension.
11
 *
12
 * It is free software; you can redistribute it and/or modify it under
13
 * the terms of the GNU General Public License, either version 2
14
 * of the License, or any later version.
15
 *
16
 * For the full copyright and license information, please read the
17
 * LICENSE.txt file that was distributed with this source code.
18
 *
19
 * The TYPO3 project - inspiring people to share!
20
 */
21
22
use AOE\Crawler\Domain\Repository\QueueRepository;
23
use AOE\Crawler\Value\QueueFilter;
24
use Symfony\Component\Console\Command\Command;
25
use Symfony\Component\Console\Input\InputArgument;
26
use Symfony\Component\Console\Input\InputInterface;
27
use Symfony\Component\Console\Input\InputOption;
28
use Symfony\Component\Console\Output\OutputInterface;
29
use TYPO3\CMS\Core\Utility\GeneralUtility;
30
use TYPO3\CMS\Extbase\Object\ObjectManager;
31
32
class FlushQueueCommand extends Command
33
{
34 3
    protected function configure(): void
35
    {
36 3
        $this->setDescription('Remove queue entries and perform a cleanup');
37
38 3
        $this->setHelp(
39 3
            'Try "typo3 help crawler:flushQueue" to see your options' . chr(10) . chr(10) .
40 3
            'Works as a CLI interface to some functionality from the Web > Info > Site Crawler module;
41 3
It will remove queue entries and perform a cleanup.' . chr(10) . chr(10) .
42 3
            '
43
            Examples:
44
              --- Remove all finished queue-entries in the sub-branch of page 5
45
              $ typo3 crawler:flushQueue finished --page 5
46
47
              --- Remove all pending queue-entries for all pages
48
              $ typo3 crawler:flushQueue pending
49
            '
50
        );
51 3
        $this->addArgument(
52 3
            'mode',
53 3
            InputArgument::REQUIRED,
54 3
            'What to clear: all, finished, pending'
55
        );
56 3
    }
57
58
    /**
59
     * Crawler Command - Cleaning up the queue.
60
     *
61
     * Works as a CLI interface to some functionality from the Web > Info > Site Crawler module;
62
     * It will remove queue entries and perform a cleanup.
63
     *
64
     * Examples:
65
     *
66
     * --- Remove all finished queue-entries in the sub-branch of page 5
67
     * $ typo3 crawler:flushQueue finished --page 5
68
     *
69
     * --- Remove all pending queue-entries for all pages
70
     * $ typo3 crawler:flushQueue pending
71
     */
72 3
    protected function execute(InputInterface $input, OutputInterface $output): int
73
    {
74 3
        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
75
76 3
        $queueFilter = new QueueFilter($input->getArgument('mode'));
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('mode') can also be of type null and string[]; however, parameter $queueFilter of AOE\Crawler\Value\QueueFilter::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

76
        $queueFilter = new QueueFilter(/** @scrutinizer ignore-type */ $input->getArgument('mode'));
Loading history...
77
78
        /** @var QueueRepository $queueRepository */
79 3
        $queueRepository = $objectManager->get(QueueRepository::class);
80
81 3
        switch ($queueFilter) {
82 3
            case 'all':
83 1
                $queueRepository->flushQueue($queueFilter);
84 1
                $output->writeln('<info>All entries in Crawler queue will be flushed</info>');
85 1
                break;
86 2
            case 'finished':
87 1
            case 'pending':
88 2
                $queueRepository->flushQueue($queueFilter);
89 2
                $output->writeln('<info>All entries in Crawler queue, with status: "' . $queueFilter . '" will be flushed</info>');
90 2
                break;
91
            default:
92
                $output->writeln('<info>No matching parameters found.' . PHP_EOL . 'Try "typo3 help crawler:flushQueue" to see your options</info>');
93
                break;
94
        }
95
96 3
        return 0;
97
    }
98
}
99