FlushQueueCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 66.04%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 45
c 2
b 0
f 0
dl 0
loc 79
ccs 35
cts 53
cp 0.6604
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 31 5
A configure() 0 29 1
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
57 3
        $this->addOption(
58 3
            'page',
59 3
            'p',
60 3
            InputOption::VALUE_OPTIONAL,
61 3
            'Page to start - deprecated since v9.1.5, will be removed in v11.x',
62 3
            '0'
63
        );
64 3
    }
65
66
    /**
67
     * Crawler Command - Cleaning up the queue.
68
     *
69
     * Works as a CLI interface to some functionality from the Web > Info > Site Crawler module;
70
     * It will remove queue entries and perform a cleanup.
71
     *
72
     * Examples:
73
     *
74
     * --- Remove all finished queue-entries in the sub-branch of page 5
75
     * $ typo3 crawler:flushQueue finished --page 5
76
     *
77
     * --- Remove all pending queue-entries for all pages
78
     * $ typo3 crawler:flushQueue pending
79
     */
80 3
    protected function execute(InputInterface $input, OutputInterface $output): int
81
    {
82 3
        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
83
84 3
        $queueFilter = new QueueFilter($input->getArgument('mode'));
85
86
        /** @var QueueRepository $queueRepository */
87 3
        $queueRepository = $objectManager->get(QueueRepository::class);
88
89 3
        $pageId = $input->getOption('page');
90 3
        if ($pageId) {
91
            $output->writeln('<error>The --page option is deprecated since v9.1.5 and will be removed in v11.x</error>');
92
            trigger_error('The --page option is deprecated since v9.1.5 and will be removed in v11.x', E_USER_DEPRECATED);
93
        }
94
95 3
        switch ($queueFilter) {
96 3
            case 'all':
97 1
                $queueRepository->flushQueue($queueFilter);
98 1
                $output->writeln('<info>All entries in Crawler queue will be flushed</info>');
99 1
                break;
100 2
            case 'finished':
101 1
            case 'pending':
102 2
                $queueRepository->flushQueue($queueFilter);
103 2
                $output->writeln('<info>All entries in Crawler queue, with status: "' . $queueFilter . '" will be flushed</info>');
104 2
                break;
105
            default:
106
                $output->writeln('<info>No matching parameters found.' . PHP_EOL . 'Try "typo3 help crawler:flushQueue" to see your options</info>');
107
                break;
108
        }
109
110 3
        return 0;
111
    }
112
}
113