Passed
Pull Request — master (#123)
by
unknown
11:14
created

ReindexTask::execute()   B

Complexity

Conditions 8
Paths 64

Size

Total Lines 32
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 21
c 1
b 0
f 0
nc 64
nop 0
dl 0
loc 32
rs 8.4444
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 ReindexTask extends BaseTask
27
{
28
    public function execute()
29
    {
30
        $inputArray = [];
31
        if ($this->dryRun) {
32
            $inputArray['--dry-run'] = true;
33
        }
34
        if (count($this->coll)) {
35
            $inputArray['-c'] = implode(',', $this->coll);
36
        }
37
        $inputArray['-p'] = $this->pid;
38
        $inputArray['-s'] = $this->solr;
39
        if (!empty($this->owner)) {
40
            $inputArray['-o'] = $this->owner;
41
        }
42
        if ($this->all) {
43
            $inputArray['--all'] = true;
44
        }
45
46
        $reindexCommand = GeneralUtility::makeInstance(\Kitodo\Dlf\Command\ReindexCommand::class);
47
        $inputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Input\ArrayInput::class, $inputArray);
48
        if (Environment::isCli()) {
49
            $outputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Output\ConsoleOutput::class);
50
        } else {
51
            $outputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Output\BufferedOutput::class);
52
        }
53
54
        $return = $reindexCommand->run($inputInterface, $outputInterface);
55
56
        if (!Environment::isCli()) {
57
            $this->outputFlashMessages($outputInterface->fetch(), $return ? FlashMessage::ERROR : FlashMessage::OK);
58
        }
59
        return !$return;
60
    }
61
}
62