Completed
Push — develop ( c60de3...4fc294 )
by Susi
05:38
created

TruncateCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
declare(strict_types=1);
3
4
namespace T3G\Elasticorn\Commands\Type;
5
6
7
use Psr\Log\LogLevel;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use T3G\Elasticorn\Commands\BaseCommand;
13
14
/**
15
 * Class TruncateCommand
16
 *
17
 * Command to truncate specified document type from index
18
 *
19
 * @package T3G\Elasticorn\Commands
20
 */
21
class TruncateCommand extends BaseCommand
22
{
23
    /**
24
     * Configure the init command
25
     *
26
     * @return void
27
     */
28
    protected function configure()
29
    {
30
        parent::configure();
31
        $this
32
            ->setName('type:truncate')
33
            ->setDescription('Truncates given document type (removes all documents of type).');
34
35
        $this->addArgument('indexName', InputArgument::REQUIRED, 'The index name.');
36
        $this->addArgument('documentType', InputArgument::REQUIRED, 'The document type to truncate.');
37
    }
38
39
    /**
40
     * @param InputInterface $input
41
     * @param OutputInterface $output
42
     *
43
     * @return void
44
     */
45
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        try {
48
            $this->documentTypeService->deleteDocumentsOfType();
49
        } catch (\InvalidArgumentException $e) {
50
            $output->writeln('<error>' . $e->getMessage() . '</error>');
51
        }
52
    }
53
54
}