|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Config\Store; |
|
4
|
|
|
|
|
5
|
|
|
use N98\Magento\Command\Config\AbstractConfigCommand; |
|
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\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
class SetCommand extends AbstractConfigCommand |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var array |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $_scopes = array( |
|
17
|
|
|
'default', |
|
18
|
|
|
'websites', |
|
19
|
|
|
'stores', |
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
protected function configure() |
|
23
|
|
|
{ |
|
24
|
|
|
$this |
|
25
|
|
|
->setName('config:store:set') |
|
26
|
|
|
->setDescription('Set a store config item') |
|
27
|
|
|
->addArgument('path', InputArgument::REQUIRED, 'The store config path like "general/local/code"') |
|
28
|
|
|
->addArgument('value', InputArgument::REQUIRED, 'The config value') |
|
29
|
|
|
->addOption( |
|
30
|
|
|
'scope', |
|
31
|
|
|
null, |
|
32
|
|
|
InputOption::VALUE_OPTIONAL, |
|
33
|
|
|
'The config value\'s scope (default, websites, stores)', |
|
34
|
|
|
'default' |
|
35
|
|
|
) |
|
36
|
|
|
->addOption('scope-id', null, InputOption::VALUE_OPTIONAL, 'The config value\'s scope ID', '0') |
|
37
|
|
|
->addOption( |
|
38
|
|
|
'encrypt', |
|
39
|
|
|
null, |
|
40
|
|
|
InputOption::VALUE_NONE, |
|
41
|
|
|
'The config value should be encrypted using env.php\'s crypt key' |
|
42
|
|
|
) |
|
43
|
|
|
->addOption( |
|
44
|
|
|
"no-null", |
|
45
|
|
|
null, |
|
46
|
|
|
InputOption::VALUE_NONE, |
|
47
|
|
|
"Do not treat value NULL as " . self::DISPLAY_NULL_UNKOWN_VALUE . " value" |
|
48
|
|
|
) |
|
49
|
|
|
; |
|
50
|
|
|
|
|
51
|
|
|
$help = <<<HELP |
|
52
|
|
|
Set a store config value by path. |
|
53
|
|
|
To set a value of a specify store view you must set the "scope" and "scope-id" option. |
|
54
|
|
|
|
|
55
|
|
|
HELP; |
|
56
|
|
|
$this->setHelp($help); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
|
61
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
62
|
|
|
* @return int|void |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->detectMagento($output, true); |
|
67
|
|
|
if (!$this->initMagento()) { |
|
68
|
|
|
return; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$scope = $input->getOption('scope'); |
|
72
|
|
|
$this->_validateScopeParam($scope); |
|
73
|
|
|
$scopeId = $this->_convertScopeIdParam($scope, $input->getOption('scope-id')); |
|
74
|
|
|
|
|
75
|
|
|
$valueDisplay = $value = $input->getArgument('value'); |
|
76
|
|
|
|
|
77
|
|
|
if ($value === "NULL" && !$input->getOption('no-null')) { |
|
78
|
|
|
if ($input->getOption('encrypt')) { |
|
79
|
|
|
throw new \InvalidArgumentException("Encryption is not possbile for NULL values"); |
|
80
|
|
|
} |
|
81
|
|
|
$value = null; |
|
82
|
|
|
$valueDisplay = self::DISPLAY_NULL_UNKOWN_VALUE; |
|
83
|
|
|
} else { |
|
84
|
|
|
$value = str_replace(array('\n', '\r'), array("\n", "\r"), $value); |
|
85
|
|
|
$value = $this->_formatValue($value, ($input->getOption('encrypt') ? 'encrypt' : '')); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$this->getConfigWriter()->save( |
|
89
|
|
|
$input->getArgument('path'), |
|
90
|
|
|
$value, |
|
91
|
|
|
$scope, |
|
92
|
|
|
$scopeId |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
|
|
$output->writeln( |
|
96
|
|
|
'<comment>' . $input->getArgument('path') . "</comment> => <comment>" . $valueDisplay . |
|
97
|
|
|
'</comment>' |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|