Skip to content

Commit

Permalink
Merge pull request #1087 from magento-falcons/MAGETWO-68764
Browse files Browse the repository at this point in the history
[Falcons]: Delivery of Bugfixes for Deployment
  • Loading branch information
Alexander Akimov authored May 11, 2017
2 parents bd3d976 + 283490a commit f14f886
Show file tree
Hide file tree
Showing 10 changed files with 336 additions and 205 deletions.

This file was deleted.

43 changes: 27 additions & 16 deletions app/code/Magento/Config/Console/Command/ConfigSetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
namespace Magento\Config\Console\Command;

use Magento\Config\App\Config\Type\System;
use Magento\Config\Console\Command\ConfigSet\EmulatedProcessorFacade;
use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
use Magento\Deploy\Model\DeploymentConfig\Hash;
use Magento\Deploy\Model\DeploymentConfig\Validator;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Command\Command;
Expand All @@ -34,11 +33,11 @@ class ConfigSetCommand extends Command
/**#@-*/

/**
* The emulated processor facade.
* Emulator adminhtml area for CLI command.
*
* @var EmulatedProcessorFacade
* @var EmulatedAdminhtmlAreaProcessor
*/
private $emulatedProcessorFacade;
private $emulatedAreaProcessor;

/**
* The config change detector.
Expand All @@ -55,18 +54,28 @@ class ConfigSetCommand extends Command
private $hash;

/**
* @param EmulatedProcessorFacade $emulatedProcessorFacade The emulated processor facade
* The factory for processor facade.
*
* @var ProcessorFacadeFactory
*/
private $processorFacadeFactory;

/**
* @param EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor Emulator adminhtml area for CLI command
* @param ChangeDetector $changeDetector The config change detector
* @param Hash $hash The hash manager
* @param ProcessorFacadeFactory $processorFacadeFactory The factory for processor facade
*/
public function __construct(
EmulatedProcessorFacade $emulatedProcessorFacade,
EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor,
ChangeDetector $changeDetector,
Hash $hash
Hash $hash,
ProcessorFacadeFactory $processorFacadeFactory
) {
$this->emulatedProcessorFacade = $emulatedProcessorFacade;
$this->emulatedAreaProcessor = $emulatedAreaProcessor;
$this->changeDetector = $changeDetector;
$this->hash = $hash;
$this->processorFacadeFactory = $processorFacadeFactory;

parent::__construct();
}
Expand Down Expand Up @@ -128,13 +137,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

try {
$message = $this->emulatedProcessorFacade->process(
$input->getArgument(static::ARG_PATH),
$input->getArgument(static::ARG_VALUE),
$input->getOption(static::OPTION_SCOPE),
$input->getOption(static::OPTION_SCOPE_CODE),
$input->getOption(static::OPTION_LOCK)
);
$message = $this->emulatedAreaProcessor->process(function () use ($input) {
return $this->processorFacadeFactory->create()->process(
$input->getArgument(static::ARG_PATH),
$input->getArgument(static::ARG_VALUE),
$input->getOption(static::OPTION_SCOPE),
$input->getOption(static::OPTION_SCOPE_CODE),
$input->getOption(static::OPTION_LOCK)
);
});

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Config\Console\Command;

use Magento\Framework\App\Area;
use Magento\Framework\App\State;
use Magento\Framework\Config\ScopeInterface;

/**
* Emulates callback inside adminhtml area code and adminhtml scope.
* It is used for CLI commands which should work with data available only in adminhtml scope.
*/
class EmulatedAdminhtmlAreaProcessor
{
/**
* The application scope manager.
*
* @var ScopeInterface
*/
private $scope;

/**
* The application state manager.
*
* @var State
*/
private $state;

/**
* @param ScopeInterface $scope The application scope manager
* @param State $state The application state manager
*/
public function __construct(ScopeInterface $scope, State $state)
{
$this->scope = $scope;
$this->state = $state;
}

/**
* Emulates callback inside adminhtml area code and adminhtml scope.
*
* Returns the return value of the callback.
*
* @param callable $callback The callable to be called
* @param array $params The parameters to be passed to the callback, as an indexed array
* @return bool|int|float|string|array|null - as the result of this method is the result of callback,
* you can use callback only with specified in this method return types
* @throws \Exception The exception is thrown if the parameter $callback throws an exception
*/
public function process(callable $callback, array $params = [])
{
$currentScope = $this->scope->getCurrentScope();
try {
return $this->state->emulateAreaCode(Area::AREA_ADMINHTML, function () use ($callback, $params) {
$this->scope->setCurrentScope(Area::AREA_ADMINHTML);
return call_user_func_array($callback, $params);
});
} catch (\Exception $exception) {
throw $exception;
} finally {
$this->scope->setCurrentScope($currentScope);
}
}
}

This file was deleted.

Loading

0 comments on commit f14f886

Please sign in to comment.