From 581ac89489128c3a0bcc4f8558413fbe8a4a43f8 Mon Sep 17 00:00:00 2001 From: "rostyslav.hymon" Date: Thu, 30 Jan 2020 12:52:47 +0200 Subject: [PATCH] MC-23940: Removing websites or stores together with their configuration from config.php fails --- .../Model/Config/Importer/SaveProcessor.php | 11 ++++--- .../Config/Importer/SaveProcessorTest.php | 33 +++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Config/Model/Config/Importer/SaveProcessor.php b/app/code/Magento/Config/Model/Config/Importer/SaveProcessor.php index 2ea9df52c0a03..225729f69a74e 100644 --- a/app/code/Magento/Config/Model/Config/Importer/SaveProcessor.php +++ b/app/code/Magento/Config/Model/Config/Importer/SaveProcessor.php @@ -91,6 +91,7 @@ public function process(array $data) * @param string $scope The configuration scope (default, website, or store) * @param string $scopeCode The scope code * @return void + * @throws \Magento\Framework\Exception\RuntimeException */ private function invokeSave(array $scopeData, $scope, $scopeCode = null) { @@ -98,11 +99,13 @@ private function invokeSave(array $scopeData, $scope, $scopeCode = null) foreach ($scopeData as $path) { $value = $this->scopeConfig->getValue($path, $scope, $scopeCode); - $backendModel = $this->valueFactory->create($path, $value, $scope, $scopeCode); + if ($value !== null) { + $backendModel = $this->valueFactory->create($path, $value, $scope, $scopeCode); - if ($backendModel instanceof Value) { - $backendModel->beforeSave(); - $backendModel->afterSave(); + if ($backendModel instanceof Value) { + $backendModel->beforeSave(); + $backendModel->afterSave(); + } } } } diff --git a/app/code/Magento/Config/Test/Unit/Model/Config/Importer/SaveProcessorTest.php b/app/code/Magento/Config/Test/Unit/Model/Config/Importer/SaveProcessorTest.php index aec3a6f64fec0..39a0e14f3e91c 100644 --- a/app/code/Magento/Config/Test/Unit/Model/Config/Importer/SaveProcessorTest.php +++ b/app/code/Magento/Config/Test/Unit/Model/Config/Importer/SaveProcessorTest.php @@ -136,4 +136,37 @@ public function testProcess() $this->assertSame(null, $this->model->process($data)); } + + public function testProcessWithNullValues() + { + $data = [ + 'default' => [ + 'advanced' => ['modules_disable_output' => ['Test_Module' => '1']] + ], + 'websites' => ['test_website' => ['general' => ['locale' => ['timezone' => 'America/Rio_Branco']]]], + ]; + $this->arrayUtilsMock->expects($this->exactly(2)) + ->method('flatten') + ->willReturnMap([ + [ + [ + 'advanced' => ['modules_disable_output' => ['Test_Module' => '1']] + ], + '', + '/', + ['advanced/modules_disable_output/Test_Module' => '1'] + ], + [ + ['general' => ['locale' => ['timezone' => 'America/Rio_Branco']]], + '', + '/', + ['general/locale/timezone' => 'America/Rio_Branco'] + ] + ]); + $this->scopeConfigMock->expects($this->exactly(2)) + ->method('getValue') + ->willReturn(null); + + $this->assertSame(null, $this->model->process($data)); + } }