Skip to content

Commit c5705c6

Browse files
Merge branches 'MAGETWO-66656' and 'MAGETWO-67152' of https://github.com/magento-falcons/magento2ce into MAGETWO-67152
2 parents c278011 + 8bb17ea commit c5705c6

File tree

13 files changed

+822
-521
lines changed

13 files changed

+822
-521
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Console\Command\ConfigSet;
7+
8+
use Magento\Framework\App\Area;
9+
use Magento\Framework\App\State;
10+
use Magento\Framework\Config\ScopeInterface;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\Exception\RuntimeException;
13+
14+
/**
15+
* Processor facade for config:set command with emulated adminhtml area.
16+
*/
17+
class EmulatedProcessorFacade
18+
{
19+
/**
20+
* The factory for processor facade.
21+
*
22+
* @var ProcessorFacadeFactory
23+
*/
24+
private $processorFacadeFactory;
25+
26+
/**
27+
* The application scope manager.
28+
*
29+
* @var ScopeInterface
30+
*/
31+
private $scope;
32+
33+
/**
34+
* The application state manager.
35+
*
36+
* @var State
37+
*/
38+
private $state;
39+
40+
/**
41+
* @param ScopeInterface $scope The application scope manager
42+
* @param State $state The application state manager
43+
* @param ProcessorFacadeFactory $processorFacadeFactory The factory for processor facade
44+
*/
45+
public function __construct(
46+
ScopeInterface $scope,
47+
State $state,
48+
ProcessorFacadeFactory $processorFacadeFactory
49+
) {
50+
$this->scope = $scope;
51+
$this->state = $state;
52+
$this->processorFacadeFactory = $processorFacadeFactory;
53+
}
54+
55+
/**
56+
* Processes config:set command.
57+
*
58+
* @param string $path The configuration path in format group/section/field_name
59+
* @param string $value The configuration value
60+
* @param string $scope The configuration scope (default, website, or store)
61+
* @param string $scopeCode The scope code
62+
* @param boolean $lock The lock flag
63+
* @return string Processor response message
64+
* @throws RuntimeException If exception was catch
65+
*/
66+
public function process($path, $value, $scope, $scopeCode, $lock)
67+
{
68+
$currentScope = $this->scope->getCurrentScope();
69+
70+
try {
71+
// Emulating adminhtml scope to be able to read configs.
72+
return $this->state->emulateAreaCode(Area::AREA_ADMINHTML, function () use (
73+
$path,
74+
$value,
75+
$scope,
76+
$scopeCode,
77+
$lock
78+
) {
79+
$this->scope->setCurrentScope(Area::AREA_ADMINHTML);
80+
81+
return $this->processorFacadeFactory->create()->process(
82+
$path,
83+
$value,
84+
$scope,
85+
$scopeCode,
86+
$lock
87+
);
88+
});
89+
} catch (LocalizedException $exception) {
90+
throw new RuntimeException(__('%1', $exception->getMessage()), $exception);
91+
} finally {
92+
$this->scope->setCurrentScope($currentScope);
93+
}
94+
}
95+
}

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

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
namespace Magento\Config\Console\Command\ConfigSet;
77

88
use Magento\Config\App\Config\Type\System;
9-
use Magento\Config\Model\Config\Structure;
9+
use Magento\Config\Model\PreparedValueFactory;
1010
use Magento\Framework\App\Config\ConfigPathResolver;
11-
use Magento\Framework\App\Config\Value;
12-
use Magento\Framework\App\Config\ValueFactory;
1311
use Magento\Framework\App\DeploymentConfig;
1412
use Magento\Framework\Config\File\ConfigFilePool;
1513
use Magento\Framework\Exception\CouldNotSaveException;
@@ -24,11 +22,11 @@
2422
class LockProcessor implements ConfigSetProcessorInterface
2523
{
2624
/**
27-
* The deployment configuration reader.
25+
* The factory for prepared value.
2826
*
29-
* @var DeploymentConfig
27+
* @var PreparedValueFactory
3028
*/
31-
private $deploymentConfig;
29+
private $preparedValueFactory;
3230

3331
/**
3432
* The deployment configuration writer.
@@ -52,42 +50,21 @@ class LockProcessor implements ConfigSetProcessorInterface
5250
private $configPathResolver;
5351

5452
/**
55-
* The manager for system configuration structure.
56-
*
57-
* @var Structure
58-
*/
59-
private $configStructure;
60-
61-
/**
62-
* The factory for configuration value objects.
63-
*
64-
* @see Value
65-
* @var ValueFactory
66-
*/
67-
private $configValueFactory;
68-
69-
/**
70-
* @param DeploymentConfig $deploymentConfig The deployment configuration reader
53+
* @param PreparedValueFactory $preparedValueFactory The factory for prepared value
7154
* @param DeploymentConfig\Writer $writer The deployment configuration writer
7255
* @param ArrayManager $arrayManager An array manager for different manipulations with arrays
7356
* @param ConfigPathResolver $configPathResolver The resolver for configuration paths according to source type
74-
* @param Structure $configStructure The manager for system configuration structure
75-
* @param ValueFactory $configValueFactory The factory for configuration value objects
7657
*/
7758
public function __construct(
78-
DeploymentConfig $deploymentConfig,
59+
PreparedValueFactory $preparedValueFactory,
7960
DeploymentConfig\Writer $writer,
8061
ArrayManager $arrayManager,
81-
ConfigPathResolver $configPathResolver,
82-
Structure $configStructure,
83-
ValueFactory $configValueFactory
62+
ConfigPathResolver $configPathResolver
8463
) {
85-
$this->deploymentConfig = $deploymentConfig;
64+
$this->preparedValueFactory = $preparedValueFactory;
8665
$this->deploymentConfigWriter = $writer;
8766
$this->arrayManager = $arrayManager;
8867
$this->configPathResolver = $configPathResolver;
89-
$this->configStructure = $configStructure;
90-
$this->configValueFactory = $configValueFactory;
9168
}
9269

9370
/**
@@ -100,19 +77,7 @@ public function process($path, $value, $scope, $scopeCode)
10077
{
10178
try {
10279
$configPath = $this->configPathResolver->resolve($path, $scope, $scopeCode, System::CONFIG_TYPE);
103-
/** @var Structure\Element\Field $field */
104-
$field = $this->deploymentConfig->isAvailable()
105-
? $this->configStructure->getElement($path)
106-
: null;
107-
/** @var Value $backendModel */
108-
$backendModel = $field && $field->hasBackendModel()
109-
? $field->getBackendModel()
110-
: $this->configValueFactory->create();
111-
112-
$backendModel->setPath($path);
113-
$backendModel->setScope($scope);
114-
$backendModel->setScopeId($scopeCode);
115-
$backendModel->setValue($value);
80+
$backendModel = $this->preparedValueFactory->create($path, $value, $scope, $scopeCode);
11681

11782
/**
11883
* Temporary solution until Magento introduce unified interface

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

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

8-
use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
9-
use Magento\Framework\App\Area;
8+
use Magento\Config\App\Config\Type\System;
9+
use Magento\Config\Console\Command\ConfigSet\EmulatedProcessorFacade;
10+
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
11+
use Magento\Deploy\Model\DeploymentConfig\Hash;
12+
use Magento\Deploy\Model\DeploymentConfig\Validator;
1013
use Magento\Framework\App\Config\ScopeConfigInterface;
11-
use Magento\Framework\App\State;
12-
use Magento\Framework\Config\ScopeInterface;
1314
use Magento\Framework\Console\Cli;
1415
use Symfony\Component\Console\Command\Command;
1516
use Symfony\Component\Console\Input\InputArgument;
@@ -33,39 +34,39 @@ class ConfigSetCommand extends Command
3334
/**#@-*/
3435

3536
/**
36-
* Scope manager.
37+
* The emulated processor facade.
3738
*
38-
* @var ScopeInterface
39+
* @var EmulatedProcessorFacade
3940
*/
40-
private $scope;
41+
private $emulatedProcessorFacade;
4142

4243
/**
43-
* Application state.
44+
* The config change detector.
4445
*
45-
* @var State
46+
* @var ChangeDetector
4647
*/
47-
private $state;
48+
private $changeDetector;
4849

4950
/**
50-
* The processor facade factory
51+
* The hash manager.
5152
*
52-
* @var ProcessorFacadeFactory
53+
* @var Hash
5354
*/
54-
private $processorFacadeFactory;
55+
private $hash;
5556

5657
/**
57-
* @param ScopeInterface $scope Scope manager
58-
* @param State $state Application state
59-
* @param ProcessorFacadeFactory $processorFacadeFactory The processor facade factory
58+
* @param EmulatedProcessorFacade $emulatedProcessorFacade The emulated processor facade
59+
* @param ChangeDetector $changeDetector The config change detector
60+
* @param Hash $hash The hash manager
6061
*/
6162
public function __construct(
62-
ScopeInterface $scope,
63-
State $state,
64-
ProcessorFacadeFactory $processorFacadeFactory
63+
EmulatedProcessorFacade $emulatedProcessorFacade,
64+
ChangeDetector $changeDetector,
65+
Hash $hash
6566
) {
66-
$this->scope = $scope;
67-
$this->state = $state;
68-
$this->processorFacadeFactory = $processorFacadeFactory;
67+
$this->emulatedProcessorFacade = $emulatedProcessorFacade;
68+
$this->changeDetector = $changeDetector;
69+
$this->hash = $hash;
6970

7071
parent::__construct();
7172
}
@@ -115,24 +116,29 @@ protected function configure()
115116
*/
116117
protected function execute(InputInterface $input, OutputInterface $output)
117118
{
119+
if ($this->changeDetector->hasChanges(System::CONFIG_TYPE)) {
120+
$output->writeln(
121+
'<error>'
122+
. 'This command is unavailable right now. '
123+
. 'To continue working with it please run app:config:import or setup:upgrade command before.'
124+
. '</error>'
125+
);
126+
127+
return Cli::RETURN_FAILURE;
128+
}
129+
118130
try {
119-
$areaScope = $this->scope->getCurrentScope();
120-
// Emulating adminhtml scope to be able to read configs.
121-
$this->state->emulateAreaCode(Area::AREA_ADMINHTML, function () use ($input, $output) {
122-
$this->scope->setCurrentScope(Area::AREA_ADMINHTML);
123-
124-
$message = $this->processorFacadeFactory->create()->process(
125-
$input->getArgument(static::ARG_PATH),
126-
$input->getArgument(static::ARG_VALUE),
127-
$input->getOption(static::OPTION_SCOPE),
128-
$input->getOption(static::OPTION_SCOPE_CODE),
129-
$input->getOption(static::OPTION_LOCK)
130-
);
131-
132-
$output->writeln('<info>' . $message . '</info>');
133-
});
134-
135-
$this->scope->setCurrentScope($areaScope);
131+
$message = $this->emulatedProcessorFacade->process(
132+
$input->getArgument(static::ARG_PATH),
133+
$input->getArgument(static::ARG_VALUE),
134+
$input->getOption(static::OPTION_SCOPE),
135+
$input->getOption(static::OPTION_SCOPE_CODE),
136+
$input->getOption(static::OPTION_LOCK)
137+
);
138+
139+
$this->hash->regenerate(System::CONFIG_TYPE);
140+
141+
$output->writeln('<info>' . $message . '</info>');
136142

137143
return Cli::RETURN_SUCCESS;
138144
} catch (\Exception $exception) {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Test\Unit\Console\Command\ConfigSet;
7+
8+
use Magento\Config\Console\Command\ConfigSet\EmulatedProcessorFacade;
9+
use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\State;
12+
use Magento\Framework\Config\ScopeInterface;
13+
use PHPUnit_Framework_MockObject_MockObject as Mock;
14+
15+
class EmulatedProcessorFacadeTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var EmulatedProcessorFacade
19+
*/
20+
private $model;
21+
22+
/**
23+
* @var ScopeInterface|Mock
24+
*/
25+
private $scopeMock;
26+
27+
/**
28+
* @var State|Mock
29+
*/
30+
private $stateMock;
31+
32+
/**
33+
* @var ProcessorFacadeFactory|Mock
34+
*/
35+
private $processorFacadeFactory;
36+
37+
protected function setUp()
38+
{
39+
$this->scopeMock = $this->getMockBuilder(ScopeInterface::class)
40+
->getMockForAbstractClass();
41+
$this->stateMock = $this->getMockBuilder(State::class)
42+
->disableOriginalConstructor()
43+
->getMock();
44+
$this->processorFacadeFactory = $this->getMockBuilder(ProcessorFacadeFactory::class)
45+
->disableOriginalConstructor()
46+
->getMock();
47+
48+
$this->model = new EmulatedProcessorFacade(
49+
$this->scopeMock,
50+
$this->stateMock,
51+
$this->processorFacadeFactory
52+
);
53+
}
54+
55+
public function testProcess()
56+
{
57+
$this->scopeMock->expects($this->once())
58+
->method('getCurrentScope')
59+
->willReturn('currentScope');
60+
$this->scopeMock->expects($this->once())
61+
->method('setCurrentScope')
62+
->with('currentScope');
63+
$this->stateMock->expects($this->once())
64+
->method('emulateAreaCode');
65+
66+
$this->model->process(
67+
'test/test/test',
68+
'value',
69+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
70+
null,
71+
false
72+
);
73+
}
74+
}

0 commit comments

Comments
 (0)