Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SensitiveConfigSetCommand.php
Go to the documentation of this file.
1 <?php
7 
15 use Symfony\Component\Console\Command\Command;
16 use Symfony\Component\Console\Input\InputArgument;
17 use Symfony\Component\Console\Input\InputInterface;
18 use Symfony\Component\Console\Input\InputOption;
19 use Symfony\Component\Console\Output\OutputInterface;
20 
24 class SensitiveConfigSetCommand extends Command
25 {
29  const INPUT_OPTION_INTERACTIVE = 'interactive';
30 
34  const INPUT_OPTION_SCOPE = 'scope';
35 
39  const INPUT_OPTION_SCOPE_CODE = 'scope-code';
40 
44  const INPUT_ARGUMENT_PATH = 'path';
45 
49  const INPUT_ARGUMENT_VALUE = 'value';
50 
56  private $changeDetector;
57 
63  private $hash;
64 
70  private $facade;
71 
77  private $emulatedAreaProcessor;
78 
85  public function __construct(
87  ChangeDetector $changeDetector,
88  Hash $hash,
89  EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor
90  ) {
91  $this->facade = $facade;
92  $this->changeDetector = $changeDetector;
93  $this->hash = $hash;
94  $this->emulatedAreaProcessor = $emulatedAreaProcessor;
95 
96  parent::__construct();
97  }
98 
102  protected function configure()
103  {
104  $this->addArgument(
105  self::INPUT_ARGUMENT_PATH,
106  InputArgument::OPTIONAL,
107  'Configuration path for example group/section/field_name'
108  );
109  $this->addArgument(
110  self::INPUT_ARGUMENT_VALUE,
111  InputArgument::OPTIONAL,
112  'Configuration value'
113  );
114  $this->addOption(
115  self::INPUT_OPTION_INTERACTIVE,
116  'i',
117  InputOption::VALUE_NONE,
118  'Enable interactive mode to set all sensitive variables'
119  );
120  $this->addOption(
121  self::INPUT_OPTION_SCOPE,
122  null,
123  InputOption::VALUE_OPTIONAL,
124  'Scope for configuration, if not set use \'default\'',
126  );
127  $this->addOption(
128  self::INPUT_OPTION_SCOPE_CODE,
129  null,
130  InputOption::VALUE_OPTIONAL,
131  'Scope code for configuration, empty string by default',
132  ''
133  );
134  $this->setName('config:sensitive:set')
135  ->setDescription('Set sensitive configuration values');
136  parent::configure();
137  }
138 
142  protected function execute(InputInterface $input, OutputInterface $output)
143  {
144  if ($this->changeDetector->hasChanges(System::CONFIG_TYPE)) {
145  $output->writeln(
146  '<error>'
147  . 'This command is unavailable right now. '
148  . 'To continue working with it please run app:config:import or setup:upgrade command before.'
149  . '</error>'
150  );
151 
152  return Cli::RETURN_FAILURE;
153  }
154 
155  try {
156  $this->emulatedAreaProcessor->process(function () use ($input, $output) {
157  $this->facade->process($input, $output);
158  });
159  $this->hash->regenerate(System::CONFIG_TYPE);
160 
161  return Cli::RETURN_SUCCESS;
162  } catch (\Exception $e) {
163  $output->writeln(
164  sprintf('<error>%s</error>', $e->getMessage())
165  );
166 
167  return Cli::RETURN_FAILURE;
168  }
169  }
170 }
__construct(SensitiveConfigSetFacade $facade, ChangeDetector $changeDetector, Hash $hash, EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor)