Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ class ConfigSetProcessorFactory
* lock - save and lock configuration
*/
const TYPE_DEFAULT = 'default';

/**
* @deprecated
* @see TYPE_LOCK_ENV or TYPE_LOCK_CONFIG
*/
const TYPE_LOCK = 'lock';
const TYPE_LOCK_ENV = 'lock-env';
const TYPE_LOCK_CONFIG = 'lock-config';
/**#@-*/

/**#@-*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function process($path, $value, $scope, $scopeCode)
throw new CouldNotSaveException(
__(
'The value you set has already been locked. To change the value, use the --%1 option.',
ConfigSetCommand::OPTION_LOCK
ConfigSetCommand::OPTION_LOCK_ENV
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

/**
* Processes file lock flow of config:set command.
* This processor saves the value of configuration and lock it for editing in Admin interface.
* This processor saves the value of configuration into app/etc/env.php
* and locks it for editing in Admin interface.
*
* {@inheritdoc}
*/
Expand Down Expand Up @@ -49,23 +50,30 @@ class LockProcessor implements ConfigSetProcessorInterface
* @var ConfigPathResolver
*/
private $configPathResolver;
/**
* @var string
*/
private $target;

/**
* @param PreparedValueFactory $preparedValueFactory The factory for prepared value
* @param DeploymentConfig\Writer $writer The deployment configuration writer
* @param ArrayManager $arrayManager An array manager for different manipulations with arrays
* @param ConfigPathResolver $configPathResolver The resolver for configuration paths according to source type
* @param string $target
*/
public function __construct(
PreparedValueFactory $preparedValueFactory,
DeploymentConfig\Writer $writer,
ArrayManager $arrayManager,
ConfigPathResolver $configPathResolver
ConfigPathResolver $configPathResolver,
$target = ConfigFilePool::APP_ENV
) {
$this->preparedValueFactory = $preparedValueFactory;
$this->deploymentConfigWriter = $writer;
$this->arrayManager = $arrayManager;
$this->configPathResolver = $configPathResolver;
$this->target = $target;
}

/**
Expand Down Expand Up @@ -97,7 +105,7 @@ public function process($path, $value, $scope, $scopeCode)
* we'll write value just after all validations are triggered.
*/
$this->deploymentConfigWriter->saveConfig(
[ConfigFilePool::APP_ENV => $this->arrayManager->set($configPath, [], $value)],
[$this->target => $this->arrayManager->set($configPath, [], $value)],
false
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Scope\ValidatorInterface;
use Magento\Config\Model\Config\PathValidator;
use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\ConfigurationMismatchException;
use Magento\Framework\Exception\CouldNotSaveException;
Expand Down Expand Up @@ -98,27 +99,60 @@ public function __construct(
* @param boolean $lock The lock flag
* @return string Processor response message
* @throws ValidatorException If some validation is wrong
* @throws CouldNotSaveException If cannot save config value
* @throws ConfigurationMismatchException If processor can not be instantiated
* @since 100.2.0
* @deprecated
* @see processWithLockTarget()
*/
public function process($path, $value, $scope, $scopeCode, $lock)
{
return $this->processWithLockTarget($path, $value, $scope, $scopeCode, $lock);
}

/**
* Processes config:set command with the option to set a target file.
*
* @param string $path The configuration path in format section/group/field_name
* @param string $value The configuration value
* @param string $scope The configuration scope (default, website, or store)
* @param string $scopeCode The scope code
* @param boolean $lock The lock flag
* @param string $lockTarget
* @return string Processor response message
* @throws ValidatorException If some validation is wrong
*/
public function processWithLockTarget(
$path,
$value,
$scope,
$scopeCode,
$lock,
$lockTarget = ConfigFilePool::APP_ENV
) {
try {
$this->scopeValidator->isValid($scope, $scopeCode);
$this->pathValidator->validate($path);
} catch (LocalizedException $exception) {
throw new ValidatorException(__($exception->getMessage()), $exception);
}

$processor = $lock
? $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_LOCK)
: $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_DEFAULT);
$message = $lock
? 'Value was saved and locked.'
: 'Value was saved.';
$processor =
$lock
? ( $lockTarget == ConfigFilePool::APP_ENV
? $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_LOCK_ENV)
: $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_LOCK_CONFIG)
)
: $this->configSetProcessorFactory->create(ConfigSetProcessorFactory::TYPE_DEFAULT)
;

$message =
$lock
? ( $lockTarget == ConfigFilePool::APP_ENV
? 'Value was saved in app/etc/env.php and locked.'
: 'Value was saved in app/etc/config.php and locked.'
)
: 'Value was saved.';

// The processing flow depends on --lock option.
// The processing flow depends on --lock and --share options.
$processor->process($path, $value, $scope, $scopeCode);

$this->hash->regenerate(System::CONFIG_TYPE);
Expand Down
34 changes: 31 additions & 3 deletions app/code/Magento/Config/Console/Command/ConfigSetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Config\Console\Command;

use Magento\Config\App\Config\Type\System;
use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -34,6 +36,8 @@ class ConfigSetCommand extends Command
const OPTION_SCOPE = 'scope';
const OPTION_SCOPE_CODE = 'scope-code';
const OPTION_LOCK = 'lock';
const OPTION_LOCK_ENV = 'lock-env';
const OPTION_LOCK_CONFIG = 'lock-config';
/**#@-*/

/**#@-*/
Expand Down Expand Up @@ -108,11 +112,24 @@ protected function configure()
InputArgument::OPTIONAL,
'Scope code (required only if scope is not \'default\')'
),
new InputOption(
static::OPTION_LOCK_ENV,
'le',
InputOption::VALUE_NONE,
'Lock value which prevents modification in the Admin (will be saved in app/etc/env.php)'
),
new InputOption(
static::OPTION_LOCK_CONFIG,
'lc',
InputOption::VALUE_NONE,
'Lock and share value with other installations, prevents modification in the Admin '
. '(will be saved in app/etc/config.php)'
),
new InputOption(
static::OPTION_LOCK,
'l',
InputOption::VALUE_NONE,
'Lock value which prevents modification in the Admin'
'Deprecated, use the --' . static::OPTION_LOCK_ENV . ' option instead.'
),
]);

Expand Down Expand Up @@ -146,12 +163,23 @@ protected function execute(InputInterface $input, OutputInterface $output)

try {
$message = $this->emulatedAreaProcessor->process(function () use ($input) {
return $this->processorFacadeFactory->create()->process(

$lock = $input->getOption(static::OPTION_LOCK_ENV)
|| $input->getOption(static::OPTION_LOCK_CONFIG)
|| $input->getOption(static::OPTION_LOCK);

$lockTargetPath = ConfigFilePool::APP_ENV;
if ($input->getOption(static::OPTION_LOCK_CONFIG)) {
$lockTargetPath = ConfigFilePool::APP_CONFIG;
}

return $this->processorFacadeFactory->create()->processWithLockTarget(
$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)
$lock,
$lockTargetPath
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function setUp()
$this->model = new ConfigSetProcessorFactory(
$this->objectManagerMock,
[
ConfigSetProcessorFactory::TYPE_LOCK => LockProcessor::class,
ConfigSetProcessorFactory::TYPE_LOCK_ENV => LockProcessor::class,
ConfigSetProcessorFactory::TYPE_DEFAULT => DefaultProcessor::class,
'wrongType' => \stdClass::class,
]
Expand All @@ -59,7 +59,7 @@ public function testCreate()

$this->assertInstanceOf(
ConfigSetProcessorInterface::class,
$this->model->create(ConfigSetProcessorFactory::TYPE_LOCK)
$this->model->create(ConfigSetProcessorFactory::TYPE_LOCK_ENV)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ private function configMockForProcessTest($path, $scope, $scopeCode)

/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage The value you set has already been locked. To change the value, use the --lock option.
* @codingStandardsIgnoreStart
* @expectedExceptionMessage The value you set has already been locked. To change the value, use the --lock-env option.
* @codingStandardsIgnoreEnd
*/
public function testProcessLockedValue()
{
Expand Down
Loading