Skip to content
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

[FEATURE] Add option to conditional skip individual setup arguments #906

Merged
merged 2 commits into from May 3, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions .travis.yml
Expand Up @@ -62,22 +62,22 @@ jobs:
include:
- stage: test
php: 7.4
env: TYPO3_VERSION="^10.4"
env: TYPO3_VERSION="^10.4.1"
- stage: test
php: 7.3
env: TYPO3_VERSION="^10.4"
env: TYPO3_VERSION="^10.4.1"
- stage: test
php: 7.2
env: TYPO3_VERSION="^10.4"
env: TYPO3_VERSION="^10.4.1"
- stage: test
php: 7.2
env: TYPO3_VERSION="^10.4" PREFER_LOWEST="--prefer-lowest"
env: TYPO3_VERSION="^10.4.1" PREFER_LOWEST="--prefer-lowest"
- stage: test
php: 7.2
env: TYPO3_VERSION="dev-master"
- stage: test
php: 7.4
env: TYPO3_VERSION="^10.4"
env: TYPO3_VERSION="^10.4.1"
script:
- composer self-update --snapshot --2
- git clean -dffx
Expand Down
17 changes: 15 additions & 2 deletions Classes/Console/Install/Action/InteractiveActionArguments.php
Expand Up @@ -16,6 +16,7 @@

use Helhum\Typo3Console\Mvc\Cli\ConsoleOutput;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

class InteractiveActionArguments
{
Expand Down Expand Up @@ -47,15 +48,27 @@ public function populate(array $argumentDefinitions, array $options = []): array
$actionArguments = [];
foreach ($argumentDefinitions as $argumentName => $argumentDefinition) {
$argumentValue = $this->extractArgumentValueFromDefinitionOrGivenArguments($argumentName, $argumentDefinition);
while ($argumentValue === null) {
$argumentValue = $this->fetchArgumentValue($argumentDefinition);
if ($this->shouldExtractValue($argumentDefinition, $actionArguments)) {
while ($argumentValue === null) {
$argumentValue = $this->fetchArgumentValue($argumentDefinition);
}
}
$actionArguments[$argumentName] = $argumentValue;
}

return $actionArguments;
}

private function shouldExtractValue(array $argumentDefinition, array $actionArguments): bool
{
if (!$condition = ($argumentDefinition['condition'] ?? '')) {
return true;
}
$expressionLanguage = new ExpressionLanguage();

return (bool)$expressionLanguage->evaluate($condition, $actionArguments);
}

private function extractArgumentValueFromDefinitionOrGivenArguments(string $argumentName, array $argumentDefinition)
{
$argumentValue = null;
Expand Down
18 changes: 4 additions & 14 deletions Classes/Console/Install/Action/Typo3InstallAction.php
Expand Up @@ -18,6 +18,7 @@
use Helhum\Typo3Console\Install\InstallStepResponse;
use Helhum\Typo3Console\Mvc\Cli\CommandDispatcher;
use Helhum\Typo3Console\Mvc\Cli\ConsoleOutput;
use Helhum\Typo3Console\Mvc\Cli\FailedSubProcessCommandException;

class Typo3InstallAction implements InstallActionInterface
{
Expand Down Expand Up @@ -62,12 +63,6 @@ public function execute(array $actionDefinition, array $options = []): bool
);
$response = $this->executeActionWithArguments($actionName, $arguments);

if ($this->executeActionWithArguments('actionNeedsExecution', [$actionName])->actionNeedsExecution()) {
// @deprecated Can be removed once TYPO3 8.7 support is removed. Then it will be safe to call the action only once
// and just assume it completed
$response = $this->executeActionWithArguments($actionName, $arguments);
}

$messages = $response->getMessages();
$messageRenderer = new CliMessageRenderer($this->output);
$messageRenderer->render($messages);
Expand Down Expand Up @@ -99,21 +94,16 @@ private function translateActionArgumentsToCommandArguments(array $actionArgumen
* @param string $actionName Name of the install step
* @param array $arguments Arguments for the install step
* @param array $options Options for the install step
* @throws FailedSubProcessCommandException
* @return InstallStepResponse
*/
private function executeActionWithArguments($actionName, array $arguments = [], array $options = [])
private function executeActionWithArguments($actionName, array $arguments = [], array $options = []): InstallStepResponse
{
$actionName = strtolower($actionName);
// Arguments must come first then options, to avoid argument values to be passed to boolean flags
$arguments = array_merge($arguments, $options);
$actionResult = $this->commandDispatcher->executeCommand('install:' . $actionName, $arguments);
$response = @unserialize($actionResult);
if ($response === false && $actionName === 'defaultconfiguration') {
// This action terminates with exit, (trying to initiate a HTTP redirect)
// Therefore we gracefully create a valid response here
$response = new InstallStepResponse(false, []);
}

return $response;
return @unserialize($actionResult);
}
}
6 changes: 6 additions & 0 deletions Configuration/Install/InstallSteps.yaml
Expand Up @@ -23,34 +23,39 @@ databaseConnect:
default: 'mysqli'

databaseUserName:
condition: 'databaseDriver != "pdo_sqlite"'
description: 'User name for database server'
option: '--database-user-name'
type: string
value: '%env(TYPO3_INSTALL_DB_USER)%'
default: ''

databaseUserPassword:
condition: 'databaseDriver != "pdo_sqlite"'
description: 'User password for database server'
option: '--database-user-password'
type: hidden
value: '%env(TYPO3_INSTALL_DB_PASSWORD)%'
default: ''

databaseHostName:
condition: 'databaseDriver != "pdo_sqlite"'
description: 'Host name of database server'
option: '--database-host-name'
type: string
value: '%env(TYPO3_INSTALL_DB_HOST)%'
default: '127.0.0.1'

databasePort:
condition: 'databaseDriver != "pdo_sqlite"'
description: 'TCP Port of database server'
option: '--database-port'
type: int
value: '%env(TYPO3_INSTALL_DB_PORT)%'
default: 3306

databaseSocket:
condition: 'databaseDriver != "pdo_sqlite"'
description: 'Unix Socket to connect to'
option: '--database-socket'
type: string
Expand Down Expand Up @@ -111,6 +116,7 @@ defaultConfiguration:
value: '%env(TYPO3_INSTALL_SITE_SETUP_TYPE)%'
default: 'no'
siteUrl:
condition: 'siteSetupType == "site"'
description: 'Specify the site base url'
option: '--site-base-url'
type: string
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/ExtensionArtifacts/composer.json
Expand Up @@ -53,7 +53,7 @@
},
"require": {
"helhum/typo3-console": "@dev",
"typo3/cms-core": "^10.4.0"
"typo3/cms-core": "^10.4.1"
},
"replace": {
"helhum/typo3-console-plugin": "*",
Expand Down
19 changes: 10 additions & 9 deletions composer.json
Expand Up @@ -31,24 +31,25 @@
"php": "^7.2",
"helhum/typo3-console-plugin": "^2.0.2",

"typo3/cms-backend": "^10.4.0",
"typo3/cms-core": "^10.4.0",
"typo3/cms-extbase": "^10.4.0",
"typo3/cms-extensionmanager": "^10.4.0",
"typo3/cms-fluid": "^10.4.0",
"typo3/cms-frontend": "^10.4.0",
"typo3/cms-install": "^10.4.0",
"typo3/cms-backend": "^10.4.1",
"typo3/cms-core": "^10.4.1",
"typo3/cms-extbase": "^10.4.1",
"typo3/cms-extensionmanager": "^10.4.1",
"typo3/cms-fluid": "^10.4.1",
"typo3/cms-frontend": "^10.4.1",
"typo3/cms-install": "^10.4.1",

"doctrine/annotations": "^1.4",
"symfony/console": "^4.4 || ^5.0",
"symfony/process": "^4.4 || ^5.0",
"helhum/config-loader": ">=0.9 <0.13"
},
"require-dev": {
"typo3/cms-reports": "^10.4.0 || dev-master",
"typo3/cms-filemetadata": "^10.4.0 || dev-master",
"typo3/cms-reports": "^10.4.1 || dev-master",
"typo3/cms-filemetadata": "^10.4.1 || dev-master",
"typo3-console/create-reference-command": "@dev",
"typo3-console/php-server-command": "^0.2",
"symfony/expression-language": "^4.4 || ^5.0",
"symfony/filesystem": "^4.4 || ^5.0",
"nimut/testing-framework": "5.x-dev",
"php-parallel-lint/php-parallel-lint": "^1.2"
Expand Down