emulatedAreaProcessor = $emulatedAreaProcessor;
$this->changeDetector = $changeDetector;
$this->processorFacadeFactory = $processorFacadeFactory;
$this->deploymentConfig = $deploymentConfig;
parent::__construct();
}
/**
* @inheritdoc
* @since 101.0.0
*/
protected function configure()
{
$this->setName('config:set')
->setDescription('Change system configuration')
->setDefinition([
new InputArgument(
static::ARG_PATH,
InputArgument::REQUIRED,
'Configuration path in format section/group/field_name'
),
new InputArgument(static::ARG_VALUE, InputArgument::REQUIRED, 'Configuration value'),
new InputOption(
static::OPTION_SCOPE,
null,
InputArgument::OPTIONAL,
'Configuration scope (default, website, or store)',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
),
new InputOption(
static::OPTION_SCOPE_CODE,
null,
InputArgument::OPTIONAL,
'Scope code (required only if scope is not \'default\')'
),
new InputOption(
static::OPTION_LOCK_ENV,
'le',
InputOption::VALUE_NONE,
'Lock value which prevents modification in the Admin (will be saved in app/etc/env.php)'
),
new InputOption(
static::OPTION_LOCK_CONFIG,
'lc',
InputOption::VALUE_NONE,
'Lock and share value with other installations, prevents modification in the Admin '
. '(will be saved in app/etc/config.php)'
),
new InputOption(
static::OPTION_LOCK,
'l',
InputOption::VALUE_NONE,
'Deprecated, use the --' . static::OPTION_LOCK_ENV . ' option instead.'
),
]);
parent::configure();
}
/**
* Creates and run appropriate processor, depending on input options.
*
* {@inheritdoc}
* @since 101.0.0
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$this->deploymentConfig->isAvailable()) {
$output->writeln(
'You cannot run this command because the Magento application is not installed.'
);
return Cli::RETURN_FAILURE;
}
if ($this->changeDetector->hasChanges(System::CONFIG_TYPE)) {
$output->writeln(
''
. 'This command is unavailable right now. '
. 'To continue working with it please run app:config:import or setup:upgrade command before.'
. ''
);
return Cli::RETURN_FAILURE;
}
try {
$message = $this->emulatedAreaProcessor->process(function () use ($input) {
$lock = $input->getOption(static::OPTION_LOCK_ENV)
|| $input->getOption(static::OPTION_LOCK_CONFIG)
|| $input->getOption(static::OPTION_LOCK);
$lockTargetPath = ConfigFilePool::APP_ENV;
if ($input->getOption(static::OPTION_LOCK_CONFIG)) {
$lockTargetPath = ConfigFilePool::APP_CONFIG;
}
return $this->processorFacadeFactory->create()->processWithLockTarget(
$input->getArgument(static::ARG_PATH),
$input->getArgument(static::ARG_VALUE),
$input->getOption(static::OPTION_SCOPE),
$input->getOption(static::OPTION_SCOPE_CODE),
$lock,
$lockTargetPath
);
});
$output->writeln('' . $message . '');
return Cli::RETURN_SUCCESS;
} catch (\Exception $exception) {
$output->writeln('' . $exception->getMessage() . '');
return Cli::RETURN_FAILURE;
}
}
}