Passed
Pull Request — master (#123)
by
unknown
04:19
created

OptimizeTask   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 25 6
1
<?php
2
3
/**
4
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
5
 *
6
 * This file is part of the Kitodo and TYPO3 projects.
7
 *
8
 * @license GNU General Public License version 3 or later.
9
 * For the full copyright and license information, please read the
10
 * LICENSE.txt file that was distributed with this source code.
11
 */
12
namespace Kitodo\Dlf\Task;
13
14
use TYPO3\CMS\Core\Core\Environment;
15
use TYPO3\CMS\Core\Messaging\FlashMessage;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
18
/**
19
 * Task for reindexing documents.
20
 *
21
 * @package TYPO3
22
 * @subpackage dlf
23
 *
24
 * @access public
25
 */
26
class OptimizeTask extends BaseTask
27
{
28
    public function execute()
29
    {
30
        $inputArray = [];
31
        $inputArray['-s'] = $this->solr;
32
        if (!empty($this->commit)) {
33
            $inputArray['--commit'] = true;
34
        }
35
        if (!empty($this->optimize)) {
36
            $inputArray['--optimize'] = true;
37
        }
38
39
        $optimizeCommand = GeneralUtility::makeInstance(\Kitodo\Dlf\Command\OptimizeCommand::class);
40
        $inputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Input\ArrayInput::class, $inputArray);
41
        if (Environment::isCli()) {
42
            $outputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Output\ConsoleOutput::class);
43
        } else {
44
            $outputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Output\BufferedOutput::class);
45
        }
46
47
        $return = $optimizeCommand->run($inputInterface, $outputInterface);
48
49
        if (!Environment::isCli()) {
50
            $this->outputFlashMessages($outputInterface->fetch(), $return ? FlashMessage::ERROR : FlashMessage::OK);
51
        }
52
        return !$return;
53
    }
54
}
55