Skip to content

Commit f14f886

Browse files
author
Alexander Akimov
authored
Merge pull request #1087 from magento-falcons/MAGETWO-68764
[Falcons]: Delivery of Bugfixes for Deployment
2 parents bd3d976 + 283490a commit f14f886

File tree

10 files changed

+336
-205
lines changed

10 files changed

+336
-205
lines changed

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

-95
This file was deleted.

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

+27-16
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
namespace Magento\Config\Console\Command;
77

88
use Magento\Config\App\Config\Type\System;
9-
use Magento\Config\Console\Command\ConfigSet\EmulatedProcessorFacade;
9+
use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
1010
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
1111
use Magento\Deploy\Model\DeploymentConfig\Hash;
12-
use Magento\Deploy\Model\DeploymentConfig\Validator;
1312
use Magento\Framework\App\Config\ScopeConfigInterface;
1413
use Magento\Framework\Console\Cli;
1514
use Symfony\Component\Console\Command\Command;
@@ -34,11 +33,11 @@ class ConfigSetCommand extends Command
3433
/**#@-*/
3534

3635
/**
37-
* The emulated processor facade.
36+
* Emulator adminhtml area for CLI command.
3837
*
39-
* @var EmulatedProcessorFacade
38+
* @var EmulatedAdminhtmlAreaProcessor
4039
*/
41-
private $emulatedProcessorFacade;
40+
private $emulatedAreaProcessor;
4241

4342
/**
4443
* The config change detector.
@@ -55,18 +54,28 @@ class ConfigSetCommand extends Command
5554
private $hash;
5655

5756
/**
58-
* @param EmulatedProcessorFacade $emulatedProcessorFacade The emulated processor facade
57+
* The factory for processor facade.
58+
*
59+
* @var ProcessorFacadeFactory
60+
*/
61+
private $processorFacadeFactory;
62+
63+
/**
64+
* @param EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor Emulator adminhtml area for CLI command
5965
* @param ChangeDetector $changeDetector The config change detector
6066
* @param Hash $hash The hash manager
67+
* @param ProcessorFacadeFactory $processorFacadeFactory The factory for processor facade
6168
*/
6269
public function __construct(
63-
EmulatedProcessorFacade $emulatedProcessorFacade,
70+
EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor,
6471
ChangeDetector $changeDetector,
65-
Hash $hash
72+
Hash $hash,
73+
ProcessorFacadeFactory $processorFacadeFactory
6674
) {
67-
$this->emulatedProcessorFacade = $emulatedProcessorFacade;
75+
$this->emulatedAreaProcessor = $emulatedAreaProcessor;
6876
$this->changeDetector = $changeDetector;
6977
$this->hash = $hash;
78+
$this->processorFacadeFactory = $processorFacadeFactory;
7079

7180
parent::__construct();
7281
}
@@ -128,13 +137,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
128137
}
129138

130139
try {
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-
);
140+
$message = $this->emulatedAreaProcessor->process(function () use ($input) {
141+
return $this->processorFacadeFactory->create()->process(
142+
$input->getArgument(static::ARG_PATH),
143+
$input->getArgument(static::ARG_VALUE),
144+
$input->getOption(static::OPTION_SCOPE),
145+
$input->getOption(static::OPTION_SCOPE_CODE),
146+
$input->getOption(static::OPTION_LOCK)
147+
);
148+
});
138149

139150
$this->hash->regenerate(System::CONFIG_TYPE);
140151

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Console\Command;
7+
8+
use Magento\Framework\App\Area;
9+
use Magento\Framework\App\State;
10+
use Magento\Framework\Config\ScopeInterface;
11+
12+
/**
13+
* Emulates callback inside adminhtml area code and adminhtml scope.
14+
* It is used for CLI commands which should work with data available only in adminhtml scope.
15+
*/
16+
class EmulatedAdminhtmlAreaProcessor
17+
{
18+
/**
19+
* The application scope manager.
20+
*
21+
* @var ScopeInterface
22+
*/
23+
private $scope;
24+
25+
/**
26+
* The application state manager.
27+
*
28+
* @var State
29+
*/
30+
private $state;
31+
32+
/**
33+
* @param ScopeInterface $scope The application scope manager
34+
* @param State $state The application state manager
35+
*/
36+
public function __construct(ScopeInterface $scope, State $state)
37+
{
38+
$this->scope = $scope;
39+
$this->state = $state;
40+
}
41+
42+
/**
43+
* Emulates callback inside adminhtml area code and adminhtml scope.
44+
*
45+
* Returns the return value of the callback.
46+
*
47+
* @param callable $callback The callable to be called
48+
* @param array $params The parameters to be passed to the callback, as an indexed array
49+
* @return bool|int|float|string|array|null - as the result of this method is the result of callback,
50+
* you can use callback only with specified in this method return types
51+
* @throws \Exception The exception is thrown if the parameter $callback throws an exception
52+
*/
53+
public function process(callable $callback, array $params = [])
54+
{
55+
$currentScope = $this->scope->getCurrentScope();
56+
try {
57+
return $this->state->emulateAreaCode(Area::AREA_ADMINHTML, function () use ($callback, $params) {
58+
$this->scope->setCurrentScope(Area::AREA_ADMINHTML);
59+
return call_user_func_array($callback, $params);
60+
});
61+
} catch (\Exception $exception) {
62+
throw $exception;
63+
} finally {
64+
$this->scope->setCurrentScope($currentScope);
65+
}
66+
}
67+
}

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

-74
This file was deleted.

0 commit comments

Comments
 (0)