Skip to content

Commit 22e1ecc

Browse files
committed
Merge remote-tracking branch 'falcons/falcons-pr-bugfixes' into PRS
2 parents d5644db + f35cd0a commit 22e1ecc

File tree

20 files changed

+337
-82
lines changed

20 files changed

+337
-82
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface ConfigSetProcessorInterface
2020
/**
2121
* Processes config:set command.
2222
*
23-
* @param string $path The configuration path in format group/section/field_name
23+
* @param string $path The configuration path in format section/group/field_name
2424
* @param string $value The configuration value
2525
* @param string $scope The configuration scope (default, website, or store)
2626
* @param string $scopeCode The scope code

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Magento\Framework\Exception\ConfigurationMismatchException;
1313
use Magento\Framework\Exception\CouldNotSaveException;
1414
use Magento\Framework\Exception\ValidatorException;
15+
use Magento\Deploy\Model\DeploymentConfig\Hash;
16+
use Magento\Config\App\Config\Type\System;
1517

1618
/**
1719
* Processor facade for config:set command.
@@ -48,25 +50,35 @@ class ProcessorFacade
4850
*/
4951
private $configSetProcessorFactory;
5052

53+
/**
54+
* The hash manager.
55+
*
56+
* @var Hash
57+
*/
58+
private $hash;
59+
5160
/**
5261
* @param ValidatorInterface $scopeValidator The scope validator
5362
* @param PathValidator $pathValidator The path validator
5463
* @param ConfigSetProcessorFactory $configSetProcessorFactory The factory for config:set processors
64+
* @param Hash $hash The hash manager
5565
*/
5666
public function __construct(
5767
ValidatorInterface $scopeValidator,
5868
PathValidator $pathValidator,
59-
ConfigSetProcessorFactory $configSetProcessorFactory
69+
ConfigSetProcessorFactory $configSetProcessorFactory,
70+
Hash $hash
6071
) {
6172
$this->scopeValidator = $scopeValidator;
6273
$this->pathValidator = $pathValidator;
6374
$this->configSetProcessorFactory = $configSetProcessorFactory;
75+
$this->hash = $hash;
6476
}
6577

6678
/**
6779
* Processes config:set command.
6880
*
69-
* @param string $path The configuration path in format group/section/field_name
81+
* @param string $path The configuration path in format section/group/field_name
7082
* @param string $value The configuration value
7183
* @param string $scope The configuration scope (default, website, or store)
7284
* @param string $scopeCode The scope code
@@ -95,6 +107,8 @@ public function process($path, $value, $scope, $scopeCode, $lock)
95107
// The processing flow depends on --lock option.
96108
$processor->process($path, $value, $scope, $scopeCode);
97109

110+
$this->hash->regenerate(System::CONFIG_TYPE);
111+
98112
return $message;
99113
}
100114
}

app/code/Magento/Config/Console/Command/ConfigSetCommand.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Magento\Config\App\Config\Type\System;
99
use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
1010
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
11-
use Magento\Deploy\Model\DeploymentConfig\Hash;
1211
use Magento\Framework\App\Config\ScopeConfigInterface;
1312
use Magento\Framework\Console\Cli;
1413
use Symfony\Component\Console\Command\Command;
@@ -49,13 +48,6 @@ class ConfigSetCommand extends Command
4948
*/
5049
private $changeDetector;
5150

52-
/**
53-
* The hash manager.
54-
*
55-
* @var Hash
56-
*/
57-
private $hash;
58-
5951
/**
6052
* The factory for processor facade.
6153
*
@@ -66,18 +58,15 @@ class ConfigSetCommand extends Command
6658
/**
6759
* @param EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor Emulator adminhtml area for CLI command
6860
* @param ChangeDetector $changeDetector The config change detector
69-
* @param Hash $hash The hash manager
7061
* @param ProcessorFacadeFactory $processorFacadeFactory The factory for processor facade
7162
*/
7263
public function __construct(
7364
EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor,
7465
ChangeDetector $changeDetector,
75-
Hash $hash,
7666
ProcessorFacadeFactory $processorFacadeFactory
7767
) {
7868
$this->emulatedAreaProcessor = $emulatedAreaProcessor;
7969
$this->changeDetector = $changeDetector;
80-
$this->hash = $hash;
8170
$this->processorFacadeFactory = $processorFacadeFactory;
8271

8372
parent::__construct();
@@ -94,7 +83,7 @@ protected function configure()
9483
new InputArgument(
9584
static::ARG_PATH,
9685
InputArgument::REQUIRED,
97-
'Configuration path in format group/section/field_name'
86+
'Configuration path in format section/group/field_name'
9887
),
9988
new InputArgument(static::ARG_VALUE, InputArgument::REQUIRED, 'Configuration value'),
10089
new InputOption(
@@ -150,8 +139,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
150139
);
151140
});
152141

153-
$this->hash->regenerate(System::CONFIG_TYPE);
154-
155142
$output->writeln('<info>' . $message . '</info>');
156143

157144
return Cli::RETURN_SUCCESS;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,13 @@ public function import(array $data)
122122
$this->scopeConfig->clean();
123123
}
124124

125-
$this->state->emulateAreaCode(Area::AREA_ADMINHTML, function () use ($changedData) {
125+
$this->state->emulateAreaCode(Area::AREA_ADMINHTML, function () use ($changedData, $data) {
126126
$this->scope->setCurrentScope(Area::AREA_ADMINHTML);
127127

128128
// Invoke saving of new values.
129129
$this->saveProcessor->process($changedData);
130+
$this->flagManager->saveFlag(static::FLAG_CODE, $data);
130131
});
131-
132-
$this->flagManager->saveFlag(static::FLAG_CODE, $data);
133132
} catch (\Exception $e) {
134133
throw new InvalidTransitionException(__('%1', $e->getMessage()), $e);
135134
} finally {

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

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Framework\App\Config\ValueInterface;
1313
use Magento\Framework\App\Config\Value;
1414
use Magento\Framework\App\ScopeInterface;
15-
use Magento\Store\Model\ScopeInterface as StoreScopeInterface;
15+
use Magento\Store\Model\ScopeTypeNormalizer;
1616
use Magento\Framework\App\ScopeResolverPool;
1717
use Magento\Framework\Exception\RuntimeException;
1818

@@ -53,28 +53,38 @@ class PreparedValueFactory
5353
*/
5454
private $config;
5555

56+
/**
57+
* The scope type normalizer.
58+
*
59+
* @var ScopeTypeNormalizer
60+
*/
61+
private $scopeTypeNormalizer;
62+
5663
/**
5764
* @param ScopeResolverPool $scopeResolverPool The scope resolver pool
5865
* @param StructureFactory $structureFactory The manager for system configuration structure
5966
* @param BackendFactory $valueFactory The factory for configuration value objects
6067
* @param ScopeConfigInterface $config The scope configuration
68+
* @param ScopeTypeNormalizer $scopeTypeNormalizer The scope type normalizer
6169
*/
6270
public function __construct(
6371
ScopeResolverPool $scopeResolverPool,
6472
StructureFactory $structureFactory,
6573
BackendFactory $valueFactory,
66-
ScopeConfigInterface $config
74+
ScopeConfigInterface $config,
75+
ScopeTypeNormalizer $scopeTypeNormalizer
6776
) {
6877
$this->scopeResolverPool = $scopeResolverPool;
6978
$this->structureFactory = $structureFactory;
7079
$this->valueFactory = $valueFactory;
7180
$this->config = $config;
81+
$this->scopeTypeNormalizer = $scopeTypeNormalizer;
7282
}
7383

7484
/**
7585
* Returns instance of Value with defined properties.
7686
*
77-
* @param string $path The configuration path in format group/section/field_name
87+
* @param string $path The configuration path in format section/group/field_name
7888
* @param string $value The configuration value
7989
* @param string $scope The configuration scope (default, website, or store)
8090
* @param string|int|null $scopeCode The scope code
@@ -106,20 +116,26 @@ public function create($path, $value, $scope, $scopeCode = null)
106116
if ($backendModel instanceof Value) {
107117
$scopeId = 0;
108118

109-
if (in_array($scope, [StoreScopeInterface::SCOPE_WEBSITE, StoreScopeInterface::SCOPE_WEBSITES])) {
110-
$scope = StoreScopeInterface::SCOPE_WEBSITES;
111-
} elseif (in_array($scope, [StoreScopeInterface::SCOPE_STORE, StoreScopeInterface::SCOPE_STORES])) {
112-
$scope = StoreScopeInterface::SCOPE_STORES;
113-
}
119+
$scope = $this->scopeTypeNormalizer->normalize($scope);
114120

115121
if ($scope !== ScopeInterface::SCOPE_DEFAULT) {
116-
$scopeResolver = $this->scopeResolverPool->get($scope);
117-
$scopeId = $scopeResolver->getScope($scopeCode)->getId();
122+
$scopeId = $this->scopeResolverPool->get($scope)
123+
->getScope($scopeCode)
124+
->getId();
125+
}
126+
127+
if ($field instanceof Structure\Element\Field) {
128+
$groupPath = $field->getGroupPath();
129+
$group = $structure->getElement($groupPath);
130+
$backendModel->setField($field->getId());
131+
$backendModel->setGroupId($group->getId());
132+
$backendModel->setFieldConfig($field->getData());
118133
}
119134

120135
$backendModel->setPath($configPath);
121136
$backendModel->setScope($scope);
122137
$backendModel->setScopeId($scopeId);
138+
$backendModel->setScopeCode($scopeCode);
123139
$backendModel->setValue($value);
124140
}
125141

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Magento\Framework\Exception\ValidatorException;
1616
use Magento\Framework\Exception\CouldNotSaveException;
1717
use Magento\Framework\Exception\ConfigurationMismatchException;
18+
use Magento\Deploy\Model\DeploymentConfig\Hash;
19+
use Magento\Config\App\Config\Type\System;
1820
use PHPUnit_Framework_MockObject_MockObject as Mock;
1921

2022
/**
@@ -49,6 +51,11 @@ class ProcessorFacadeTest extends \PHPUnit_Framework_TestCase
4951
*/
5052
private $processorMock;
5153

54+
/**
55+
* @var Hash|Mock
56+
*/
57+
private $hashMock;
58+
5259
/**
5360
* @inheritdoc
5461
*/
@@ -69,10 +76,15 @@ protected function setUp()
6976
->method('create')
7077
->willReturn($this->processorMock);
7178

79+
$this->hashMock = $this->getMockBuilder(Hash::class)
80+
->disableOriginalConstructor()
81+
->getMock();
82+
7283
$this->model = new ProcessorFacade(
7384
$this->scopeValidatorMock,
7485
$this->pathValidatorMock,
75-
$this->configSetProcessorFactoryMock
86+
$this->configSetProcessorFactoryMock,
87+
$this->hashMock
7688
);
7789
}
7890

@@ -91,6 +103,9 @@ public function testProcess()
91103
$this->processorMock->expects($this->once())
92104
->method('process')
93105
->with('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
106+
$this->hashMock->expects($this->once())
107+
->method('regenerate')
108+
->with(System::CONFIG_TYPE);
94109

95110
$this->assertSame(
96111
'Value was saved.',

app/code/Magento/Config/Test/Unit/Console/Command/ConfigSetCommandTest.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
*/
66
namespace Magento\Config\Test\Unit\Console\Command;
77

8-
use Magento\Config\App\Config\Type\System;
98
use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
9+
use Magento\Config\Console\Command\ConfigSet\ProcessorFacade;
1010
use Magento\Config\Console\Command\ConfigSetCommand;
1111
use Magento\Config\Console\Command\EmulatedAdminhtmlAreaProcessor;
1212
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
13-
use Magento\Deploy\Model\DeploymentConfig\Hash;
1413
use Magento\Framework\Console\Cli;
1514
use Magento\Framework\Exception\ValidatorException;
1615
use PHPUnit_Framework_MockObject_MockObject as Mock;
@@ -39,14 +38,14 @@ class ConfigSetCommandTest extends \PHPUnit_Framework_TestCase
3938
private $changeDetectorMock;
4039

4140
/**
42-
* @var Hash|Mock
41+
* @var ProcessorFacadeFactory|Mock
4342
*/
44-
private $hashMock;
43+
private $processorFacadeFactoryMock;
4544

4645
/**
47-
* @var ProcessorFacadeFactory|Mock
46+
* @var ProcessorFacade|Mock
4847
*/
49-
private $processorFacadeFactoryMock;
48+
private $processorFacadeMock;
5049

5150
/**
5251
* @inheritdoc
@@ -59,17 +58,16 @@ protected function setUp()
5958
$this->changeDetectorMock = $this->getMockBuilder(ChangeDetector::class)
6059
->disableOriginalConstructor()
6160
->getMock();
62-
$this->hashMock = $this->getMockBuilder(Hash::class)
61+
$this->processorFacadeFactoryMock = $this->getMockBuilder(ProcessorFacadeFactory::class)
6362
->disableOriginalConstructor()
6463
->getMock();
65-
$this->processorFacadeFactoryMock = $this->getMockBuilder(ProcessorFacadeFactory::class)
64+
$this->processorFacadeMock = $this->getMockBuilder(ProcessorFacade::class)
6665
->disableOriginalConstructor()
6766
->getMock();
6867

6968
$this->command = new ConfigSetCommand(
7069
$this->emulatedAreProcessorMock,
7170
$this->changeDetectorMock,
72-
$this->hashMock,
7371
$this->processorFacadeFactoryMock
7472
);
7573
}
@@ -79,12 +77,17 @@ public function testExecute()
7977
$this->changeDetectorMock->expects($this->once())
8078
->method('hasChanges')
8179
->willReturn(false);
82-
$this->emulatedAreProcessorMock->expects($this->once())
80+
$this->processorFacadeFactoryMock->expects($this->once())
81+
->method('create')
82+
->willReturn($this->processorFacadeMock);
83+
$this->processorFacadeMock->expects($this->once())
8384
->method('process')
8485
->willReturn('Some message');
85-
$this->hashMock->expects($this->once())
86-
->method('regenerate')
87-
->with(System::CONFIG_TYPE);
86+
$this->emulatedAreProcessorMock->expects($this->once())
87+
->method('process')
88+
->willReturnCallback(function ($function) {
89+
return $function();
90+
});
8891

8992
$tester = new CommandTester($this->command);
9093
$tester->execute([

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ protected function setUp()
125125
);
126126
}
127127

128-
/**
129-
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
130-
*/
131128
public function testImport()
132129
{
133130
$data = [];
@@ -150,6 +147,7 @@ public function testImport()
150147
->method('emulateAreaCode')
151148
->with(Area::AREA_ADMINHTML, $this->anything())
152149
->willReturnCallback(function ($area, $function) {
150+
$this->assertEquals(Area::AREA_ADMINHTML, $area);
153151
return $function();
154152
});
155153
$this->saveProcessorMock->expects($this->once())

0 commit comments

Comments
 (0)