Skip to content

Commit 5b868df

Browse files
MAGETWO-69430: Magento allows to save not valid data using config:set command
1 parent 07f4e70 commit 5b868df

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

app/code/Magento/Config/Console/Command/ConfigSet/LockProcessor.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Config\App\Config\Type\System;
99
use Magento\Config\Model\PreparedValueFactory;
1010
use Magento\Framework\App\Config\ConfigPathResolver;
11+
use Magento\Framework\App\Config\Value;
1112
use Magento\Framework\App\DeploymentConfig;
1213
use Magento\Framework\Config\File\ConfigFilePool;
1314
use Magento\Framework\Exception\CouldNotSaveException;
@@ -79,19 +80,27 @@ public function process($path, $value, $scope, $scopeCode)
7980
$configPath = $this->configPathResolver->resolve($path, $scope, $scopeCode, System::CONFIG_TYPE);
8081
$backendModel = $this->preparedValueFactory->create($path, $value, $scope, $scopeCode);
8182

82-
/**
83-
* Temporary solution until Magento introduce unified interface
84-
* for storing system configuration into database and configuration files.
85-
*/
86-
$backendModel->validateBeforeSave();
87-
$backendModel->beforeSave();
83+
if ($backendModel instanceof Value) {
84+
/**
85+
* Temporary solution until Magento introduce unified interface
86+
* for storing system configuration into database and configuration files.
87+
*/
88+
$backendModel->validateBeforeSave();
89+
$backendModel->beforeSave();
8890

89-
$this->deploymentConfigWriter->saveConfig(
90-
[ConfigFilePool::APP_ENV => $this->arrayManager->set($configPath, [], $backendModel->getValue())],
91-
false
92-
);
91+
$value = $backendModel->getValue();
9392

94-
$backendModel->afterSave();
93+
$backendModel->afterSave();
94+
95+
/**
96+
* Because FS does not support transactions,
97+
* we'll write value just after all validations are triggered.
98+
*/
99+
$this->deploymentConfigWriter->saveConfig(
100+
[ConfigFilePool::APP_ENV => $this->arrayManager->set($configPath, [], $value)],
101+
false
102+
);
103+
}
95104
} catch (\Exception $exception) {
96105
throw new CouldNotSaveException(__('%1', $exception->getMessage()), $exception);
97106
}

app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/LockProcessorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ public function testCustomException()
206206
->willReturn($this->valueMock);
207207
$this->arrayManagerMock->expects($this->never())
208208
->method('set');
209-
$this->valueMock->expects($this->never())
209+
$this->valueMock->expects($this->once())
210210
->method('getValue');
211211
$this->valueMock->expects($this->once())
212-
->method('validateBeforeSave')
212+
->method('afterSave')
213213
->willThrowException(new \Exception('Invalid values'));
214214
$this->deploymentConfigWriterMock->expects($this->never())
215215
->method('saveConfig');

0 commit comments

Comments
 (0)