Completed
Push — typo3v9 ( 0dcd72...98ac46 )
by Tomas Norre
06:11
created

FlushQueueCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 31
ccs 0
cts 28
cp 0
crap 2
rs 9.424
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
namespace AOE\Crawler\Command;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2019 AOE GmbH <[email protected]>
9
 *
10
 *  All rights reserved
11
 *
12
 *  This script is part of the TYPO3 project. The TYPO3 project is
13
 *  free software; you can redistribute it and/or modify
14
 *  it under the terms of the GNU General Public License as published by
15
 *  the Free Software Foundation; either version 3 of the License, or
16
 *  (at your option) any later version.
17
 *
18
 *  The GNU General Public License can be found at
19
 *  http://www.gnu.org/copyleft/gpl.html.
20
 *
21
 *  This script is distributed in the hope that it will be useful,
22
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 *  GNU General Public License for more details.
25
 *
26
 *  This copyright notice MUST APPEAR in all copies of the script!
27
 ***************************************************************/
28
29
use AOE\Crawler\Controller\CrawlerController;
30
use Symfony\Component\Console\Input\InputInterface;
31
use Symfony\Component\Console\Input\InputOption;
32
use Symfony\Component\Console\Output\OutputInterface;
33
use Symfony\Component\Console\Command\Command;
34
use TYPO3\CMS\Core\Utility\GeneralUtility;
35
use TYPO3\CMS\Core\Utility\MathUtility;
36
use TYPO3\CMS\Extbase\Object\ObjectManager;
37
38
class FlushQueueCommand extends Command
39
{
40
    protected function configure(): void
41
    {
42
        $this->setHelp(
43
            'Try "typo3 help crawler:flushQueue" to see your options' . chr(10) . chr(10) .
44
            'Works as a CLI interface to some functionality from the Web > Info > Site Crawler module;
45
It will remove queue entries and perform a cleanup.' . chr(10) . chr(10) .
46
            '
47
            Examples:
48
              --- Remove all finished queue-entries in the sub-branch of page 5
49
              $ typo3 crawler:flushQueue --mode finished --page 5
50
             
51
              --- Remove all pending queue-entries for all pages
52
              $ typo3 crawler:flushQueue --mode pending
53
            '
54
        );
55
        $this->addOption(
56
            'mode',
57
            'm',
58
            InputOption::VALUE_OPTIONAL,
59
            'Output mode',
60
            'finished'
61
		);
62
63
        $this->addOption(
64
            'page',
65
            'p',
66
            InputOption::VALUE_OPTIONAL,
67
            'Page to start',
68
            0
69
        );
70
    }
71
72
    /**
73
     * Crawler Command - Cleaning up the queue.
74
     *
75
     * Works as a CLI interface to some functionality from the Web > Info > Site Crawler module;
76
     * It will remove queue entries and perform a cleanup.
77
     *
78
     * Examples:
79
     *
80
     * --- Remove all finished queue-entries in the sub-branch of page 5
81
     * $ typo3 crawler:flushQueue --mode finished --page 5
82
     *
83
     * --- Remove all pending queue-entries for all pages
84
     * $ typo3 crawler:flushQueue --mode pending
85
     *
86
     */
87
    protected function execute(InputInterface $input, OutputInterface $output)
88
    {
89
        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
90
91
        /** @var CrawlerController $crawlerController */
92
        $crawlerController = $objectManager->get(CrawlerController::class);
93
94
        $pageId = MathUtility::forceIntegerInRange($input->getOption('page'), 0);
95
        $fullFlush = ($pageId === 0);
96
97
        switch ($input->getOption('mode')) {
98
            case 'all':
99
                $crawlerController->getLogEntriesForPageId($pageId, '', true, $fullFlush);
100
                break;
101
            case 'finished':
102
            case 'pending':
103
                $crawlerController->getLogEntriesForPageId($pageId, $input->getOption('mode'), true, $fullFlush);
104
                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
111
112
}
113