Reset::execute()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 31
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.439
c 0
b 0
f 0
cc 6
eloc 16
nc 8
nop 2
1
<?php
2
3
namespace LimeSoda\Environment;
4
5
use N98\Magento\Command\AbstractMagentoCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\StringInput;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class Reset extends AbstractMagentoCommand
12
{
13
    protected $_operation = "reset";
14
    protected $_data = array('customers','reports','sales');
15
16
    protected function configure()
17
    {
18
      $this
19
          ->setName('ls:env:'.$this->_operation)
20
          ->addArgument('environment', InputArgument::REQUIRED, 'Identifier of the environment')
21
          ->addArgument('data', InputArgument::OPTIONAL, 'Data to remove: customers, reports, sales')
22
          ->setDescription('Reset (empty) customer, sales, reporting and logging tables in database');
23
    }
24
25
   /**
26
    * @param \Symfony\Component\Console\Input\InputInterface $input
27
    * @param \Symfony\Component\Console\Output\OutputInterface $output
28
    * @return int|void
29
    */
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        $this->detectMagento($output, true);
33
        if ($this->initMagento()) {
34
          
35
          $environment = $input->getArgument('environment');
36
          $toReset = $input->getArgument('data');
37
38
          if (isset($toReset)) {
39
              if (array_search($toReset, $this->_data)===false) {
40
                throw new \Exception("No data to reset '" . $toReset ."' provided.");
41
              }
42
            $this->_data = array($toReset);
43
          }
44
45
          $helper = \Mage::helper('limesoda_environmentconfiguration');
46
          
47
          // Deactivating auto-exiting after command execution
48
          $this->getApplication()->setAutoExit(false);
49
50
          foreach ($this->_data as $data) {
51
              foreach ($helper->getOperations($environment, $this->_operation, $data) as $operation) {
52
                  $input = new StringInput($operation);
53
                  $this->getApplication()->run($input, $output);
54
              }
55
          }
56
          
57
          // Reactivating auto-exiting after command execution
58
          $this->getApplication()->setAutoExit(true);
59
        }
60
    }
61
62
}
63