Passed
Pull Request — master (#123)
by
unknown
05:01
created

IndexTask::execute()   A

Complexity

Conditions 6
Paths 16

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 18
c 1
b 0
f 0
nc 16
nop 0
dl 0
loc 27
rs 9.0444
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 index a document.
20
 *
21
 * @package TYPO3
22
 * @subpackage dlf
23
 *
24
 * @access public
25
 */
26
class IndexTask extends BaseTask
27
{
28
    public function execute()
29
    {
30
        $inputArray = [];
31
        if ($this->dryRun) {
32
            $inputArray['--dry-run'] = true;
33
        }
34
        $inputArray['-d'] = $this->doc;
35
        $inputArray['-p'] = $this->pid;
36
        $inputArray['-s'] = $this->solr;
37
        if (!empty($this->owner)) {
38
            $inputArray['-o'] = $this->owner;
39
        }
40
41
        $indexCommand = GeneralUtility::makeInstance(\Kitodo\Dlf\Command\IndexCommand::class);
42
        $inputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Input\ArrayInput::class, $inputArray);
43
        if (Environment::isCli()) {
44
            $outputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Output\ConsoleOutput::class);
45
        } else {
46
            $outputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Output\BufferedOutput::class);
47
        }
48
49
        $return = $indexCommand->run($inputInterface, $outputInterface);
50
51
        if (!Environment::isCli()) {
52
            $this->outputFlashMessages($outputInterface->fetch(), $return ? FlashMessage::ERROR : FlashMessage::OK);
53
        }
54
        return !$return;
55
    }
56
}
57