protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var \Symfony\Component\Console\Output\ConsoleOutput $output */
$magento = new Magento($input->getOption('magento-root'));
$config_adapter = new ConfigurationAdapter($magento);
$yaml = new Parser();
if ($input->getArgument('config-yaml-file')) {
$config_yaml_file = $input->getArgument('config-yaml-file');
if (!file_exists($config_yaml_file)) {
throw new \Exception("File ({$config_yaml_file}) does not exist");
}
if (!is_readable($config_yaml_file)) {
throw new \Exception("File ({$config_yaml_file}) is not readable");
}
$config_file_contents = $yaml->parse(file_get_contents($config_yaml_file));
$config_file_yaml = new ConfigYaml($config_file_contents, $input->getOption('env'));
foreach ($config_file_yaml->getData() as $scope_key => $scope_data) {
foreach ($scope_data as $path => $value) {
$scope_data = ConfigYaml::extractFromScopeKey($scope_key);
if ($value !== null) {
$affected_rows = $config_adapter->setValue($path, $value, $scope_data['scope'], $scope_data['scope_id']);
} else {
$affected_rows = $config_adapter->deleteValue($path, $scope_data['scope'], $scope_data['scope_id']);
}
if ($affected_rows > 0) {
$line = sprintf("[%s] %s -> %s", $scope_key, $path, $value ?: 'null');
if (method_exists($output, 'getErrorOutput')) {
$output->getErrorOutput()->writeln($line);
} else {
$output->writeln($line);
}
}
}
}
}
return 0;
}