Skip to content

Commit 8375483

Browse files
MAGETWO-66656: Fix retrieval of old value in config import
1 parent 729a208 commit 8375483

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

app/code/Magento/Config/Model/Config/BackendFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectman
2626
* Create backend model by name
2727
*
2828
* @param string $modelName
29+
* @param array $arguments The object arguments
2930
* @return \Magento\Framework\App\Config\ValueInterface
3031
* @throws \InvalidArgumentException
3132
*/
32-
public function create($modelName)
33+
public function create($modelName, array $arguments = [])
3334
{
34-
$model = $this->_objectManager->create($modelName);
35+
$model = $this->_objectManager->create($modelName, $arguments);
3536
if (!$model instanceof \Magento\Framework\App\Config\ValueInterface) {
3637
throw new \InvalidArgumentException('Invalid config field backend model: ' . $modelName);
3738
}

app/code/Magento/Config/Model/PreparedValueFactory.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
*/
66
namespace Magento\Config\Model;
77

8+
use Magento\Config\Model\Config\BackendFactory;
89
use Magento\Config\Model\Config\Structure;
910
use Magento\Config\Model\Config\StructureFactory;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
1012
use Magento\Framework\App\Config\ValueInterface;
1113
use Magento\Framework\App\DeploymentConfig;
1214
use Magento\Framework\App\Config\Value;
13-
use Magento\Framework\App\Config\ValueFactory;
1415

1516
/**
1617
* Creates a prepared instance of Value.
@@ -37,23 +38,33 @@ class PreparedValueFactory
3738
* The factory for configuration value objects.
3839
*
3940
* @see ValueInterface
40-
* @var ValueFactory
41+
* @var BackendFactory
4142
*/
4243
private $valueFactory;
4344

45+
/**
46+
* The scope configuration.
47+
*
48+
* @var ScopeConfigInterface
49+
*/
50+
private $config;
51+
4452
/**
4553
* @param DeploymentConfig $deploymentConfig The deployment configuration reader
4654
* @param StructureFactory $structureFactory The manager for system configuration structure
47-
* @param ValueFactory $valueFactory The factory for configuration value objects
55+
* @param BackendFactory $valueFactory The factory for configuration value objects
56+
* @param ScopeConfigInterface $config The scope configuration
4857
*/
4958
public function __construct(
5059
DeploymentConfig $deploymentConfig,
5160
StructureFactory $structureFactory,
52-
ValueFactory $valueFactory
61+
BackendFactory $valueFactory,
62+
ScopeConfigInterface $config
5363
) {
5464
$this->deploymentConfig = $deploymentConfig;
5565
$this->structureFactory = $structureFactory;
5666
$this->valueFactory = $valueFactory;
67+
$this->config = $config;
5768
}
5869

5970
/**
@@ -75,10 +86,15 @@ public function create($path, $value, $scope, $scopeCode)
7586
$field = $this->deploymentConfig->isAvailable()
7687
? $structure->getElement($path)
7788
: null;
89+
/** @var string $backendModelName */
90+
$backendModelName = $field instanceof Structure\Element\Field && $field->hasBackendModel()
91+
? $field->getData()['backend_model']
92+
: ValueInterface::class;
7893
/** @var ValueInterface $backendModel */
79-
$backendModel = $field instanceof Structure\Element\Field && $field->hasBackendModel()
80-
? $field->getBackendModel()
81-
: $this->valueFactory->create();
94+
$backendModel = $this->valueFactory->create(
95+
$backendModelName,
96+
['config' => $this->config]
97+
);
8298

8399
if ($backendModel instanceof Value) {
84100
$backendModel->setPath($path);

app/code/Magento/Config/Test/Unit/Model/PreparedValueFactoryTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
*/
66
namespace Magento\Config\Test\Unit\Model;
77

8+
use Magento\Config\Model\Config\BackendFactory;
89
use Magento\Config\Model\PreparedValueFactory;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
911
use Magento\Framework\App\DeploymentConfig;
10-
use Magento\Framework\App\Config\ValueFactory;
1112
use Magento\Config\Model\Config\StructureFactory;
1213
use Magento\Framework\App\Config\Value;
1314
use Magento\Config\Model\Config\Structure;
@@ -29,7 +30,7 @@ class PreparedValueFactoryTest extends \PHPUnit_Framework_TestCase
2930
private $structureFactoryMock;
3031

3132
/**
32-
* @var ValueFactory|\PHPUnit_Framework_MockObject_MockObject
33+
* @var BackendFactory|\PHPUnit_Framework_MockObject_MockObject
3334
*/
3435
private $valueFactoryMock;
3536

@@ -48,6 +49,11 @@ class PreparedValueFactoryTest extends \PHPUnit_Framework_TestCase
4849
*/
4950
private $fieldMock;
5051

52+
/**
53+
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
54+
*/
55+
private $configMock;
56+
5157
/**
5258
* @var PreparedValueFactory
5359
*/
@@ -65,7 +71,7 @@ protected function setUp()
6571
->disableOriginalConstructor()
6672
->setMethods(['create'])
6773
->getMock();
68-
$this->valueFactoryMock = $this->getMockBuilder(ValueFactory::class)
74+
$this->valueFactoryMock = $this->getMockBuilder(BackendFactory::class)
6975
->disableOriginalConstructor()
7076
->setMethods(['create'])
7177
->getMock();
@@ -79,11 +85,14 @@ protected function setUp()
7985
->disableOriginalConstructor()
8086
->setMethods(['setPath', 'setScope', 'setScopeId', 'setValue'])
8187
->getMock();
88+
$this->configMock = $this->getMockBuilder(ScopeConfigInterface::class)
89+
->getMockForAbstractClass();
8290

8391
$this->valueBuilder = new PreparedValueFactory(
8492
$this->deploymentConfigMock,
8593
$this->structureFactoryMock,
86-
$this->valueFactoryMock
94+
$this->valueFactoryMock,
95+
$this->configMock
8796
);
8897
}
8998

app/code/Magento/Config/etc/di.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@
9999
</argument>
100100
</arguments>
101101
</virtualType>
102+
<virtualType name="snapshotValueFactory" type="Magento\Config\Model\PreparedValueFactory">
103+
<arguments>
104+
<argument name="config" xsi:type="object">configSnapshot</argument>
105+
</arguments>
106+
</virtualType>
107+
<type name="Magento\Config\Model\Config\Importer">
108+
<arguments>
109+
<argument name="valueBuilder" xsi:type="object">snapshotValueFactory</argument>
110+
</arguments>
111+
</type>
102112
<virtualType name="modulesDataProviderProxy" type="Magento\Framework\App\Config\InitialConfigSource\Proxy">
103113
<arguments>
104114
<argument name="instanceName" xsi:type="string">modulesDataProvider</argument>

0 commit comments

Comments
 (0)