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

HarvestTask   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 9

1 Method

Rating   Name   Duplication   Size   Complexity  
B execute() 0 36 9
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 harvesting documents.
20
 *
21
 * @package TYPO3
22
 * @subpackage dlf
23
 *
24
 * @access public
25
 */
26
class HarvestTask extends BaseTask
27
{
28
    public function execute()
29
    {
30
        $inputArray = [];
31
        if ($this->dryRun) {
32
            $inputArray['--dry-run'] = true;
33
        }
34
        $inputArray['-l'] = $this->lib;
35
        $inputArray['-p'] = $this->pid;
36
        $inputArray['-s'] = $this->solr;
37
        if (!empty($this->from)) {
38
            $inputArray['--from'] = $this->from;
39
        }
40
        if (!empty($this->until)) {
41
            $inputArray['--until'] = $this->until;
42
        }
43
        if (!empty($this->set)) {
44
            $inputArray['--set'] = $this->set;
45
        }
46
        if (!empty($this->softCommit)) {
47
            $inputArray['--softCommit'] = true;
48
        }
49
50
        $harvestCommand = GeneralUtility::makeInstance(\Kitodo\Dlf\Command\HarvestCommand::class);
51
        $inputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Input\ArrayInput::class, $inputArray);
52
        if (Environment::isCli()) {
53
            $outputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Output\ConsoleOutput::class);
54
        } else {
55
            $outputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Output\BufferedOutput::class);
56
        }
57
58
        $return = $harvestCommand->run($inputInterface, $outputInterface);
59
60
        if (!Environment::isCli()) {
61
            $this->outputFlashMessages($outputInterface->fetch(), $return ? FlashMessage::ERROR : FlashMessage::OK);
62
        }
63
        return !$return;
64
    }
65
}
66