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\InputOption; |
9
|
|
|
use Symfony\Component\Console\Input\StringInput; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
|
12
|
|
|
class Configure extends AbstractMagentoCommand |
13
|
|
|
{ |
14
|
|
|
protected function configure() |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
$this |
17
|
|
|
->setName('ls:env:configure') |
18
|
|
|
->addArgument('environment', InputArgument::REQUIRED, 'Identifier of the environment') |
19
|
|
|
->addOption('override', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'pair of variable name and value overriding the values in the configuration, e.g. --variable="arg1=value1"') |
20
|
|
|
->setDescription('Update settings and data for environment'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
25
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
26
|
|
|
* @return int|void |
27
|
|
|
*/ |
28
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
29
|
|
|
{ |
30
|
|
|
$this->detectMagento($output, true); |
31
|
|
|
if ($this->initMagento()) { |
32
|
|
|
|
33
|
|
|
$environment = $input->getArgument('environment'); |
34
|
|
|
$helper = \Mage::helper('limesoda_environmentconfiguration'); |
35
|
|
|
|
36
|
|
|
// Deactivating auto-exiting after command execution |
37
|
|
|
$this->getApplication()->setAutoExit(false); |
38
|
|
|
|
39
|
|
|
foreach ($helper->getParsedCommands($environment, $this->getVariableOverrides($input)) as $command) { |
40
|
|
|
$input = new StringInput($command); |
41
|
|
|
$this->getApplication()->run($input, $output); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// Reactivating auto-exiting after command execution |
45
|
|
|
$this->getApplication()->setAutoExit(true); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
|
|
protected function getVariableOverrides(InputInterface $input) |
54
|
|
|
{ |
55
|
|
|
$result = array(); |
56
|
|
|
|
57
|
|
|
foreach ($input->getOption('override') as $keyValueString) { |
58
|
|
|
$keyValuePair = explode('=', $keyValueString); |
59
|
|
|
if (count($keyValuePair) === 2) { |
60
|
|
|
$result[$keyValuePair[0]] = $keyValuePair[1]; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $result; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|