Skip to content

Add an option for setup:config:set to define the document root #29176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
66 changes: 25 additions & 41 deletions app/code/Magento/Config/Setup/ConfigOptionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
namespace Magento\Config\Setup;

use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Config\Data\ConfigData;
use Magento\Framework\Config\Data\ConfigDataFactory;
use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Setup\ConfigOptionsListInterface;
use Magento\Framework\Setup\Option\SelectConfigOption;
use Magento\Framework\Setup\Option\BooleanConfigOption;

/**
* Deployment configuration options required for the Config module.
Expand All @@ -23,17 +22,14 @@ class ConfigOptionsList implements ConfigOptionsListInterface
* Input key for the debug_logging option.
*/
const INPUT_KEY_DEBUG_LOGGING = 'enable-debug-logging';

/**
* Path to the debug_logging value in the deployment config.
*/
const CONFIG_PATH_DEBUG_LOGGING = 'dev/debug/debug_logging';

/**
* Input key for the syslog_logging option.
*/
const INPUT_KEY_SYSLOG_LOGGING = 'enable-syslog-logging';

/**
* Path to the syslog_logging value in the deployment config.
*/
Expand All @@ -58,17 +54,14 @@ public function __construct(ConfigDataFactory $configDataFactory)
public function getOptions()
{
return [
new SelectConfigOption(
new BooleanConfigOption(
self::INPUT_KEY_DEBUG_LOGGING,
SelectConfigOption::FRONTEND_WIZARD_RADIO,
[true, false, 1, 0],
self::CONFIG_PATH_DEBUG_LOGGING,
'Enable debug logging'
'Enable debug logging',
null
),
new SelectConfigOption(
new BooleanConfigOption(
self::INPUT_KEY_SYSLOG_LOGGING,
SelectConfigOption::FRONTEND_WIZARD_RADIO,
[true, false, 1, 0],
self::CONFIG_PATH_SYSLOG_LOGGING,
'Enable syslog logging'
),
Expand All @@ -87,49 +80,40 @@ public function createConfig(array $options, DeploymentConfig $deploymentConfig)

$config = [];
foreach ($deploymentOption as $inputKey => $configPath) {
$configValue = $this->processBooleanConfigValue(
$inputKey,
$configData = $this->configDataFactory->create(ConfigFilePool::APP_ENV);
$config[] = $configData;
if (!isset($options[$inputKey])) {
continue;
}
$configData->set(
$configPath,
$options
$this->boolVal($options[$inputKey])
);
if ($configValue) {
$config[] = $configValue;
}
}

return $config;
}

/**
* Provide config value from input.
*
* @param string $inputKey
* @param string $configPath
* @param array $options
* @return ConfigData|null
* @inheritdoc
*/
private function processBooleanConfigValue(string $inputKey, string $configPath, array &$options): ?ConfigData
public function validate(array $options, DeploymentConfig $deploymentConfig)
{
$configData = null;
if (isset($options[$inputKey])) {
$configData = $this->configDataFactory->create(ConfigFilePool::APP_ENV);
if ($options[$inputKey] === 'true'
|| $options[$inputKey] === '1') {
$value = 1;
} else {
$value = 0;
}
$configData->set($configPath, $value);
}

return $configData;
return [];
}

/**
* @inheritdoc
* Convert any valid input option to a boolean
*
* @param mixed $option
*
* @return int|null
*/
public function validate(array $options, DeploymentConfig $deploymentConfig)
private function boolVal($option): ?int
{
return [];
if ($option === '') {
return null;
}
return (int)in_array(strtolower((string)$option), BooleanConfigOption::OPTIONS_POSITIVE);
}
}
3 changes: 1 addition & 2 deletions app/code/Magento/Developer/Model/Logger/Handler/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
namespace Magento\Developer\Model\Logger\Handler;

use Magento\Config\Setup\ConfigOptionsList;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\State;
use Magento\Framework\Filesystem\DriverInterface;
use Magento\Framework\App\DeploymentConfig;

/**
* Enable/disable debug logging based on the store config setting
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/Developer/Model/Logger/Handler/Syslog.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Magento\Developer\Model\Logger\Handler;

use Magento\Config\Setup\ConfigOptionsList;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\DeploymentConfig;

/**
Expand Down
70 changes: 28 additions & 42 deletions app/code/Magento/MessageQueue/Setup/ConfigOptionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

namespace Magento\MessageQueue\Setup;

use Magento\Framework\Setup\ConfigOptionsListInterface;
use Magento\Framework\Setup\Option\SelectConfigOption;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Config\Data\ConfigData;
use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Setup\ConfigOptionsListInterface;
use Magento\Framework\Setup\Option\BooleanConfigOption;

/**
* Deployment configuration consumers options needed for Setup application
Expand All @@ -21,37 +21,26 @@ class ConfigOptionsList implements ConfigOptionsListInterface
/**
* Input key for the option
*/
const INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES ='consumers-wait-for-messages';

const INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES = 'consumers-wait-for-messages';
/**
* Path to the value in the deployment config
*/
const CONFIG_PATH_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES = 'queue/consumers_wait_for_messages';

/**
* Default value
*/
const DEFAULT_CONSUMERS_WAIT_FOR_MESSAGES = 1;

/**
* The available configuration values
*
* @var array
*/
private $selectOptions = [0, 1];

/**
* @inheritdoc
*/
public function getOptions()
public function getOptions(): array
{
return [
new SelectConfigOption(
new BooleanConfigOption(
self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES,
SelectConfigOption::FRONTEND_WIZARD_SELECT,
$this->selectOptions,
self::CONFIG_PATH_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES,
'Should consumers wait for a message from the queue? 1 - Yes, 0 - No',
'Should consumers wait for a message from the queue?',
self::DEFAULT_CONSUMERS_WAIT_FOR_MESSAGES
),
];
Expand All @@ -61,48 +50,45 @@ public function getOptions()
* @inheritdoc
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function createConfig(array $data, DeploymentConfig $deploymentConfig)
public function createConfig(array $data, DeploymentConfig $deploymentConfig): array
{
$configData = new ConfigData(ConfigFilePool::APP_ENV);
$deploymentOption = [
self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES => self::CONFIG_PATH_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES,
];

if (!$this->isDataEmpty($data, self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES)) {
$config = [];
foreach ($deploymentOption as $inputKey => $configPath) {
$configData = new ConfigData(ConfigFilePool::APP_ENV);
$config[] = $configData;
if (!isset($data[$inputKey])) {
continue;
}
$configData->set(
self::CONFIG_PATH_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES,
(int)$data[self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES]
$configPath,
$this->boolVal($data[$inputKey])
);
}

return [$configData];
return $config;
}

/**
* @inheritdoc
*/
public function validate(array $options, DeploymentConfig $deploymentConfig)
public function validate(array $options, DeploymentConfig $deploymentConfig): array
{
$errors = [];

if (!$this->isDataEmpty($options, self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES)
&& !in_array($options[self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES], $this->selectOptions)) {
$errors[] = 'You can use only 1 or 0 for ' . self::INPUT_KEY_QUEUE_CONSUMERS_WAIT_FOR_MESSAGES . ' option';
}

return $errors;
return [];
}

/**
* Check if data ($data) with key ($key) is empty
* Convert any valid input option to a boolean
*
* @param mixed $option
*
* @param array $data
* @param string $key
* @return bool
* @return int|null
*/
private function isDataEmpty(array $data, $key)
private function boolVal($option): ?int
{
if (isset($data[$key]) && $data[$key] !== '') {
return false;
}

return true;
return (int)in_array(strtolower((string)$option), BooleanConfigOption::OPTIONS_POSITIVE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function testDebugInProductionMode()

$this->removeDebugLog();
$this->logger->debug($message);
$this->assertFileNotExists($this->getDebuggerLogPath());
$this->assertFileDoesNotExist($this->getDebuggerLogPath());
$this->assertNull($this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DEBUG_LOGGING));

$this->checkCommonFlow($message);
Expand Down Expand Up @@ -235,6 +235,6 @@ private function checkCommonFlow(string $message)
$this->enableDebugging(false);
$this->removeDebugLog();
$this->logger->debug($message);
$this->assertFileNotExists($this->getDebuggerLogPath());
$this->assertFileDoesNotExist($this->getDebuggerLogPath());
}
}
4 changes: 2 additions & 2 deletions lib/internal/Magento/Framework/Filesystem/Driver/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function readDirectory($path)
$flags = \FilesystemIterator::SKIP_DOTS |
\FilesystemIterator::UNIX_PATHS |
\RecursiveDirectoryIterator::FOLLOW_SYMLINKS;

$iterator = new \FilesystemIterator($path, $flags);
$result = [];
/** @var \FilesystemIterator $file */
Expand Down Expand Up @@ -952,7 +952,7 @@ public function readDirectoryRecursively($path = null)
$flags = \FilesystemIterator::SKIP_DOTS |
\FilesystemIterator::UNIX_PATHS |
\RecursiveDirectoryIterator::FOLLOW_SYMLINKS;

try {
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path, $flags),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\Setup\Option;

/**
* Select option in deployment config tool
*/
class BooleanConfigOption extends AbstractConfigOption
{
/**#@+
* Frontend input types
*/
const FRONTEND_WIZARD_RADIO = 'radio';
const SELECT_OPTIONS = ['no', 'yes'];
const INPUT_OPTIONS = ['0', '1', 'no', 'yes', 'false', 'true', ''];
const OPTIONS_POSITIVE = ['1', 'yes', 'true'];
/**#@- */

/**
* BooleanConfigOption constructor.
*
* @param string $name
* @param string $configPath
* @param string $description
* @param string|array|null $defaultValue
* @param string|array|null $shortCut
*/
public function __construct(
$name,
$configPath,
$description = '',
$defaultValue = '0',
$shortCut = null
) {
parent::__construct(
$name,
self::FRONTEND_WIZARD_RADIO,
self::VALUE_REQUIRED,
$configPath,
$description,
$defaultValue,
$shortCut
);
}

/**
* Get available options
*
* @return array
*/
public function getSelectOptions(): array
{
return self::SELECT_OPTIONS;
}

/**
* Validates input data
*
* @param mixed $data
*
* @return void
* @throws \InvalidArgumentException
*/
public function validate($data): void
{
if (!in_array(strtolower((string)$data), self::INPUT_OPTIONS)) {
throw new \InvalidArgumentException("Value specified for '{$this->getName()}' is not supported: '{$data}'");
}
parent::validate($data);
}
}
2 changes: 1 addition & 1 deletion setup/src/Magento/Setup/Model/ConfigGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function createSessionConfig(array $data)
* Creates definitions config data
*
* @param array $data
* @return ConfigData
* @return ConfigData|null
* @deprecated 2.2.0
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
Expand Down
Loading