1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Config; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
class SetCommand extends AbstractConfigCommand |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
protected $_scopes = array( |
16
|
|
|
'default', |
17
|
|
|
'websites', |
18
|
|
|
'stores', |
19
|
|
|
); |
20
|
|
|
|
21
|
|
View Code Duplication |
protected function configure() |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
$this |
24
|
|
|
->setName('config:set') |
25
|
|
|
->setDescription('Set a core config item') |
26
|
|
|
->addArgument('path', InputArgument::REQUIRED, 'The config path') |
27
|
|
|
->addArgument('value', InputArgument::REQUIRED, 'The config value') |
28
|
|
|
->addOption('scope', null, InputOption::VALUE_OPTIONAL, 'The config value\'s scope (default, websites, stores)', 'default') |
|
|
|
|
29
|
|
|
->addOption('scope-id', null, InputOption::VALUE_OPTIONAL, 'The config value\'s scope ID', '0') |
30
|
|
|
->addOption('encrypt', null, InputOption::VALUE_NONE, 'The config value should be encrypted using local.xml\'s crypt key') |
|
|
|
|
31
|
|
|
; |
32
|
|
|
|
33
|
|
|
$help = <<<HELP |
34
|
|
|
Set a store config value by path. |
35
|
|
|
To set a value of a specify store view you must set the "scope" and "scope-id" option. |
36
|
|
|
|
37
|
|
|
HELP; |
38
|
|
|
$this->setHelp($help); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param InputInterface $input |
43
|
|
|
* @param OutputInterface $output |
44
|
|
|
* |
45
|
|
|
* @return int|void |
46
|
|
|
*/ |
47
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
48
|
|
|
{ |
49
|
|
|
$this->detectMagento($output, true); |
50
|
|
|
if (!$this->initMagento()) { |
51
|
|
|
return; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$config = $this->_getConfigModel(); |
55
|
|
|
if (!$config->getResourceModel()) { |
56
|
|
|
// without a resource model, a config option can't be saved. |
57
|
|
|
return; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->_validateScopeParam($input->getOption('scope')); |
61
|
|
|
$scopeId = $this->_convertScopeIdParam($input->getOption('scope'), $input->getOption('scope-id')); |
62
|
|
|
|
63
|
|
|
$value = str_replace(array('\n', '\r'), array("\n", "\r"), $input->getArgument('value')); |
64
|
|
|
$value = $this->_formatValue($value, ($input->getOption('encrypt') ? 'encrypt' : false)); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$config->saveConfig( |
67
|
|
|
$input->getArgument('path'), |
68
|
|
|
$value, |
69
|
|
|
$input->getOption('scope'), |
70
|
|
|
$scopeId |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$output->writeln('<comment>' . $input->getArgument('path') . "</comment> => <comment>" . $input->getArgument('value') . '</comment>'); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.