protected function execute(InputInterface $input, OutputInterface $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_db_yaml = ConfigYaml::build($config_adapter);
         $config_file_contents = $yaml->parse(file_get_contents($config_yaml_file));
         $config_file_yaml = new ConfigYaml($config_file_contents, $input->getOption('env'));
         $diff = ConfigYaml::compare($config_file_yaml, $config_db_yaml);
         if (count($diff) > 0) {
             $db_data = $config_db_yaml->getData();
             $file_data = $config_file_yaml->getData();
             $diff_count = 0;
             foreach ($diff as $scope => $scope_data) {
                 foreach ($scope_data as $key => $value) {
                     $diff_count++;
                     $diff_message = sprintf("%s/%s is different (File: %s, DB: %s)", $scope, $key, $this->decorateValue($file_data[$scope][$key]), $this->decorateValue($db_data[$scope][$key]));
                     $output->writeln($diff_message);
                 }
             }
             return $diff_count;
         } else {
             return 0;
         }
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $magento = new Magento($input->getOption('magento-root'));
     $config_adapter = new ConfigurationAdapter($magento);
     $config_yaml = ConfigYaml::build($config_adapter);
     $output->write($config_yaml->toYaml($input->getOption('env')));
     return 0;
 }
 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;
 }
 /**
  * @param ConfigYaml $a
  * @param ConfigYaml $b
  * @return array
  */
 public static function compare(ConfigYaml $a, ConfigYaml $b)
 {
     $a_data = $a->getData();
     $b_data = $b->getData();
     return ArrayUtil::diffAssocRecursive($a_data, $b_data);
 }