/** * @param ConfigurationAdapter $config_adapter * @param bool $environment * @return ConfigYaml */ public static function build(ConfigurationAdapter $config_adapter, $environment = false) { $data_structure = array(); foreach ($config_adapter->getAllValues() as $row) { $scope = $row['scope']; $scope_id = $row['scope_id']; $path = $row['path']; $value = $row['value']; $scope_key = self::buildScopeKey($scope, $scope_id); if (!isset($data_structure[$scope_key])) { $data_structure[$scope_key] = array(); } $data_structure[$scope_key][$path] = $value; } return new ConfigYaml($data_structure, $environment); }
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; }