diff --git a/README.md b/README.md index b9ff453..900652d 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,14 @@ For example: dev/debug/template_hints: 1 stores-1: currency/options/base: GBP + dev/restrict/allow_ips: null -The above will disable template hints on product, enable template hints on the development environment and set the currency to Pounds Sterling in the store scope for the store with ID #1. +The above will: + +* disable template hints on product; +* enable template hints on the development environment; +* set the currency to Pounds Sterling in the store scope for the store with ID #1; +* ensure the allowed development ip's are inherited from the website for store #1. Valid scope keys are: diff --git a/src/MageConfigSync/Application.php b/src/MageConfigSync/Application.php index 10d69c6..79d69e7 100644 --- a/src/MageConfigSync/Application.php +++ b/src/MageConfigSync/Application.php @@ -10,7 +10,7 @@ class Application extends \Symfony\Component\Console\Application { public function __construct() { - parent::__construct("mageconfigsync", "0.3.1"); + parent::__construct("mageconfigsync", "0.4.0"); $this->add(new DumpCommand()); $this->add(new DiffCommand()); diff --git a/src/MageConfigSync/Command/DiffCommand.php b/src/MageConfigSync/Command/DiffCommand.php index c1438a2..a673b8d 100644 --- a/src/MageConfigSync/Command/DiffCommand.php +++ b/src/MageConfigSync/Command/DiffCommand.php @@ -75,11 +75,11 @@ protected function execute(InputInterface $input, OutputInterface $output) foreach ($scope_data as $key => $value) { $diff_count++; $diff_message = sprintf( - "%s/%s is different (File: '%s', DB: '%s')", + "%s/%s is different (File: %s, DB: %s)", $scope, $key, - $file_data[$scope][$key], - $db_data[$scope][$key] + $this->decorateValue($file_data[$scope][$key]), + $this->decorateValue($db_data[$scope][$key]) ); $output->writeln($diff_message); } @@ -91,4 +91,13 @@ protected function execute(InputInterface $input, OutputInterface $output) } } } + + protected function decorateValue($value) + { + if (is_null($value)) { + return 'null'; + } else { + return "'{$value}'"; + } + } } diff --git a/src/MageConfigSync/Command/LoadCommand.php b/src/MageConfigSync/Command/LoadCommand.php index 8e0cf5d..2475e6e 100644 --- a/src/MageConfigSync/Command/LoadCommand.php +++ b/src/MageConfigSync/Command/LoadCommand.php @@ -67,14 +67,18 @@ protected function execute(InputInterface $input, OutputInterface $output) foreach ($scope_data as $path => $value) { $scope_data = ConfigYaml::extractFromScopeKey($scope_key); - $affected_rows = $config_adapter->setValue($path, $value, $scope_data['scope'], $scope_data['scope_id']); + 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 + $value ?: 'null' ); if (method_exists($output, 'getErrorOutput')) { diff --git a/src/MageConfigSync/Magento/ConfigurationAdapter.php b/src/MageConfigSync/Magento/ConfigurationAdapter.php index 01072bb..0ca1430 100644 --- a/src/MageConfigSync/Magento/ConfigurationAdapter.php +++ b/src/MageConfigSync/Magento/ConfigurationAdapter.php @@ -43,6 +43,26 @@ public function setValue($path, $value, $scope, $scope_id) ); } + /** + * @param $path + * @param $scope + * @param $scope_id + * + * @return int Number of affected rows + */ + public function deleteValue($path, $scope, $scope_id) + { + $write = $this->_magento->getDatabaseWriteConnection(); + return $write->delete( + $this->_table_name, + array( + 'scope = ?' => $scope, + 'scope_id = ?' => $scope_id, + 'path = ?' => $path + ) + ); + } + /** * @param $path * @return array diff --git a/src/MageConfigSync/Tests/MagentoTest/a/b/app/Mage.php b/src/MageConfigSync/Tests/MagentoTest/a/b/app/Mage.php index bafdcb6..bee8a1a 100644 --- a/src/MageConfigSync/Tests/MagentoTest/a/b/app/Mage.php +++ b/src/MageConfigSync/Tests/MagentoTest/a/b/app/Mage.php @@ -1 +1 @@ -