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