Completed
Push — master ( 561e2a...f3a4fe )
by Christian
04:31
created

RecreateTriggersCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 2
cbo 2
dl 0
loc 52
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A inject() 0 4 1
B execute() 0 23 4
1
<?php
2
/**
3
 * @copyright Copyright (c) 1999-2017 netz98 GmbH (http://www.netz98.de)
4
 *
5
 * @see PROJECT_LICENSE.txt
6
 */
7
8
namespace N98\Magento\Command\Indexer;
9
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class RecreateTriggersCommand extends AbstractIndexerCommand
14
{
15
    /**
16
     * @var \Magento\Indexer\Model\Config
17
     */
18
    private $indexerCollection;
19
20
    protected function configure()
21
    {
22
        $this
23
            ->setName('index:trigger:recreate')
24
            ->setDescription('ReCreate all triggers')
25
        ;
26
    }
27
28
    /**
29
     * @param \Magento\Indexer\Model\Config $indexerCollection
0 ignored issues
show
Documentation introduced by
Should the type for parameter $indexerCollection not be \Magento\Indexer\Model\Indexer\Collection?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
30
     */
31
    public function inject(\Magento\Indexer\Model\Indexer\Collection $indexerCollection)
32
    {
33
        $this->indexerCollection = $indexerCollection;
0 ignored issues
show
Documentation Bug introduced by
It seems like $indexerCollection of type object<Magento\Indexer\Model\Indexer\Collection> is incompatible with the declared type object<Magento\Indexer\Model\Config> of property $indexerCollection.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
    }
35
36
    /**
37
     * @param \Symfony\Component\Console\Input\InputInterface $input
38
     * @param \Symfony\Component\Console\Output\OutputInterface $output
39
     * @return int|void
40
     */
41
    protected function execute(InputInterface $input, OutputInterface $output)
42
    {
43
        $this->detectMagento($output, true);
44
45
        if (!$this->initMagento()) {
46
            return;
47
        }
48
49
        foreach ($this->getIndexerCollection() as $indexer) {
50
            /** @var $indexer \Magento\Framework\Indexer\IndexerInterface */
51
            if ($indexer->isScheduled()) {
52
                $indexer->getView()->unsubscribe();
53
                $indexer->getView()->subscribe();
54
                $output->writeln(
55
                    sprintf('Re-created triggers of indexer <info>%s</info>', $indexer->getTitle())
56
                );
57
            } else {
58
                $output->writeln(
59
                    sprintf('Skipped indexer <info>%s</info>. Mode must be "schedule".', $indexer->getTitle())
60
                );
61
            }
62
        }
63
    }
64
}
65