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

DeleteTask   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 24 5
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 DeleteTask extends BaseTask
27
{
28
    public function execute()
29
    {
30
        $inputArray = [];
31
        $inputArray['-d'] = $this->doc;
32
        $inputArray['-p'] = $this->pid;
33
        $inputArray['-s'] = $this->solr;
34
        if (!empty($this->softCommit)) {
35
            $inputArray['--softCommit'] = true;
36
        }
37
38
        $deleteCommand = GeneralUtility::makeInstance(\Kitodo\Dlf\Command\DeleteCommand::class);
39
        $inputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Input\ArrayInput::class, $inputArray);
40
        if (Environment::isCli()) {
41
            $outputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Output\ConsoleOutput::class);
42
        } else {
43
            $outputInterface = GeneralUtility::makeInstance(\Symfony\Component\Console\Output\BufferedOutput::class);
44
        }
45
46
        $return = $deleteCommand->run($inputInterface, $outputInterface);
47
48
        if (!Environment::isCli()) {
49
            $this->outputFlashMessages($outputInterface->fetch(), $return ? FlashMessage::ERROR : FlashMessage::OK);
50
        }
51
        return !$return;
52
    }
53
}
54