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

[TASK] Abstract access to system config file #1119

Merged
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
33 changes: 33 additions & 0 deletions Classes/Compatibility/Typo3CompatibilityBridge.php
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Helhum\Typo3Console;

/*
* This file is part of the TYPO3 Console project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read
* LICENSE file that was distributed with this source code.
*
*/

use TYPO3\CMS\Core\Configuration\ConfigurationManager;
use TYPO3\CMS\Core\Information\Typo3Version;

/**
* Compatibility code to support TYPO3 11 and 12
*/
class Typo3CompatibilityBridge
{
public static function getSystemConfigurationFileLocation(): string
{
if ((new Typo3Version())->getMajorVersion() > 11) {
return (new ConfigurationManager())->getSystemConfigurationFileLocation();
}

return (new ConfigurationManager())->getLocalConfigurationFileLocation();
}
}
Expand Up @@ -43,7 +43,7 @@ protected function configure()
Removes a system configuration option by path.

For this command to succeed, the configuration option(s) must be in
LocalConfiguration.php and not be overridden elsewhere.
system configuration file and not be overridden elsewhere.

<b>Example:</b>

Expand Down
Expand Up @@ -29,7 +29,7 @@ protected function configure()
$this->setHelp(
<<<'EOH'
Shows system configuration value by path.
If the currently active configuration differs from the value in LocalConfiguration.php
If the currently active configuration differs from the value in system configuration file
the difference between these values is shown.

<b>Example:</b>
Expand Down
Expand Up @@ -48,7 +48,7 @@ protected function configure()
$this->setHelp(
<<<'EOH'
Shows local configuration option value by path.
Shows the value which is stored in LocalConfiguration.php.
Shows the value which is stored in system configuration file.
Note that this value could be overridden. Use <code>typo3 configuration:show <path></code> to see if this is the case.

<b>Example:</b>
Expand Down
4 changes: 2 additions & 2 deletions Classes/Console/Command/Install/InstallSetupCommand.php
Expand Up @@ -57,13 +57,13 @@ protected function configure()
'force',
'f',
InputOption::VALUE_NONE,
'Force installation of TYPO3, even if `LocalConfiguration.php` file already exists.'
'Force installation of TYPO3, even if system configuration file already exists.'
),
new InputOption(
'skip-integrity-check',
null,
InputOption::VALUE_NONE,
'Skip the checking for clean state before executing setup. This allows a pre-defined `LocalConfiguration.php` to be present. Handle with care. It might lead to unexpected or broken installation results.'
'Skip the checking for clean state before executing setup. This allows a pre-defined system configuration file to be present. Handle with care. It might lead to unexpected or broken installation results.'
),
new InputOption(
'skip-extension-setup',
Expand Down
9 changes: 5 additions & 4 deletions Classes/Console/Install/Action/PrepareInstallAction.php
Expand Up @@ -16,6 +16,7 @@

use Helhum\Typo3Console\Mvc\Cli\CommandDispatcher;
use Helhum\Typo3Console\Mvc\Cli\ConsoleOutput;
use Helhum\Typo3Console\Typo3CompatibilityBridge;
use TYPO3\CMS\Core\Core\Environment;

class PrepareInstallAction implements InstallActionInterface
Expand Down Expand Up @@ -54,7 +55,7 @@ public function execute(array $actionDefinition, array $options = []): bool
}

/**
* Handles the case when LocalConfiguration.php file already exists
* Handles the case when system configuration file already exists
*
* @param array $options
* @throws InstallationFailedException
Expand All @@ -69,15 +70,15 @@ private function ensureInstallationIsPossible(array $options)
$isInteractive = $options['interactive'] ?? $this->output->getSymfonyConsoleInput()->isInteractive();
$forceInstall = $options['forceInstall'] ?? false;

$localConfFile = Environment::getLegacyConfigPath() . '/LocalConfiguration.php';
$localConfFile = Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
if (!$forceInstall && file_exists($localConfFile)) {
$this->output->outputLine();
$this->output->outputLine('<error>TYPO3 seems to be already set up!</error>');
$proceed = $isInteractive;
if ($isInteractive) {
$this->output->outputLine();
$this->output->outputLine('<info>If you continue, your <code>typo3conf/LocalConfiguration.php</code></info>');
$this->output->outputLine('<info>file will be deleted!</info>');
$this->output->outputLine('<info>If you continue, your system configuration file</info>');
$this->output->outputLine('<warning>will be deleted!</warning>');
$this->output->outputLine();
$proceed = $this->output->askConfirmation('<info>Do you really want to proceed?</info> (<comment>no</comment>) ', false);
}
Expand Down
Expand Up @@ -14,6 +14,7 @@
*
*/

use Helhum\Typo3Console\Typo3CompatibilityBridge;
use Symfony\Component\Console\Exception\RuntimeException;
use TYPO3\CMS\Core\Configuration\ConfigurationManager;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
Expand All @@ -22,7 +23,7 @@
use TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService;

/**
* Used to migrate deprecated LocalConfiguration.php values to new values
* Used to migrate deprecated system configuration values to new values
* It is a wrapper around the TYPO3 class to properly handle redirect exceptions
*/
class SilentConfigurationUpgrade
Expand All @@ -45,7 +46,7 @@ public function __construct(ConfigurationManager $configurationManager = null)
*/
public function executeSilentConfigurationUpgradesIfNeeded()
{
if (!file_exists($this->configurationManager->getLocalConfigurationFileLocation())) {
if (!file_exists(Typo3CompatibilityBridge::getSystemConfigurationFileLocation())) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/Console/Mvc/Cli/Symfony/Application.php
Expand Up @@ -148,7 +148,7 @@ public function renderThrowable(\Throwable $exception, OutputInterface $output):
sprintf(
'Command "%s" cannot be run, because it needs a fully set up TYPO3 system.'
. PHP_EOL
. 'Your system currently lacks an essential configuration file (LocalConfiguration.php).',
. 'Your system currently lacks a system configuration file.',
$exception->getCommandName()
),
'Try setting up your system using the "install:setup" command.',
Expand Down
Expand Up @@ -19,15 +19,12 @@
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Class ConfigurationService
*/
class ConfigurationService implements SingletonInterface
{
const EXCEPTION_CODE_ARRAY_KEY_NOT_FOUND = 1341397869;

/**
* @var \TYPO3\CMS\Core\Configuration\ConfigurationManager
* @var ConfigurationManager
*/
protected $configurationManager;

Expand Down Expand Up @@ -155,7 +152,7 @@ public function removeLocal($path)
}

/**
* Sets a value in LocalConfiguration.php
* Sets a value in system configuration file
*
* But only if types are compatible and local config is active
*
Expand All @@ -176,7 +173,7 @@ public function setLocal($path, $value, $targetType = '')
}

/**
* Returns true if the value is stored in the LocalConfiguration.php file and
* Returns true if the value is stored in the system configuration file and
* is NOT overridden later (e.g. in AdditionalConfiguration.php)
*
* @param string $path
Expand Down
Expand Up @@ -38,8 +38,8 @@ public function renderDiff($localConfig, $activeConfig)
{
$diff = new Diff(new Paragraph(), new DiffConsoleRenderer());

$result = '<del>-- LocalConfiguration.php</del>' . PHP_EOL;
$result .= '<ins>++ AdditionalConfiguration.php</ins>' . PHP_EOL;
$result = '<del>-- system configuration</del>' . PHP_EOL;
$result .= '<ins>++ overridden configuration</ins>' . PHP_EOL;

$result .= $diff->render($this->getConfigurationAsString($localConfig), $this->getConfigurationAsString($activeConfig));

Expand Down
2 changes: 1 addition & 1 deletion Documentation/CommandReference/ConfigurationRemove.rst
Expand Up @@ -16,7 +16,7 @@ configuration:remove
Removes a system configuration option by path.

For this command to succeed, the configuration option(s) must be in
LocalConfiguration.php and not be overridden elsewhere.
system configuration file and not be overridden elsewhere.

**Example:**

Expand Down
2 changes: 1 addition & 1 deletion Documentation/CommandReference/ConfigurationShow.rst
Expand Up @@ -14,7 +14,7 @@ configuration:show
**Show configuration value**

Shows system configuration value by path.
If the currently active configuration differs from the value in LocalConfiguration.php
If the currently active configuration differs from the value in system configuration file
the difference between these values is shown.

**Example:**
Expand Down
2 changes: 1 addition & 1 deletion Documentation/CommandReference/ConfigurationShowlocal.rst
Expand Up @@ -14,7 +14,7 @@ configuration:showlocal
**Show local configuration value**

Shows local configuration option value by path.
Shows the value which is stored in LocalConfiguration.php.
Shows the value which is stored in system configuration file.
Note that this value could be overridden. Use `typo3 configuration:show <path>` to see if this is the case.

**Example:**
Expand Down
4 changes: 2 additions & 2 deletions Documentation/CommandReference/InstallSetup.rst
Expand Up @@ -40,15 +40,15 @@ Options
=======

`--force|-f`
Force installation of TYPO3, even if `LocalConfiguration.php` file already exists.
Force installation of TYPO3, even if system configuration file already exists.

- Accept value: no
- Is value required: no
- Is multiple: no
- Default: false

`--skip-integrity-check`
Skip the checking for clean state before executing setup. This allows a pre-defined `LocalConfiguration.php` to be present. Handle with care. It might lead to unexpected or broken installation results.
Skip the checking for clean state before executing setup. This allows a pre-defined system configuration file to be present. Handle with care. It might lead to unexpected or broken installation results.

- Accept value: no
- Is value required: no
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/

use Helhum\Typo3Console\Mvc\Cli\FailedSubProcessCommandException;
use Helhum\Typo3Console\Typo3CompatibilityBridge;

class ConfigurationCommandControllerTest extends AbstractCommandTest
{
Expand All @@ -24,7 +25,7 @@ class ConfigurationCommandControllerTest extends AbstractCommandTest
public function configurationCanBeShown()
{
$output = $this->executeConsoleCommand('configuration:show', ['BE/installToolPassword']);
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$this->assertStringContainsString($config['BE']['installToolPassword'], $output);
}

Expand All @@ -33,9 +34,9 @@ public function configurationCanBeShown()
*/
public function configurationShowsDiff()
{
$output = $this->executeConsoleCommand('configuration:show', ['SC_OPTIONS/"ext/install"']);
$this->assertStringContainsString('update', $output);
$this->assertStringContainsString('++ AdditionalConfiguration.php', $output);
$output = $this->executeConsoleCommand('configuration:show', ['SC_OPTIONS/"t3lib/class.t3lib_tcemain.php"']);
$this->assertStringContainsString('processDatamapClass', $output);
$this->assertStringContainsString('++ overridden configuration', $output);
}

/**
Expand All @@ -44,7 +45,7 @@ public function configurationShowsDiff()
public function localConfigurationCanBeShown()
{
$output = $this->executeConsoleCommand('configuration:showlocal', ['BE/installToolPassword']);
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$this->assertStringContainsString($config['BE']['installToolPassword'], $output);
}

Expand All @@ -54,7 +55,7 @@ public function localConfigurationCanBeShown()
public function localConfigurationCanBeShownAsJson()
{
$output = $this->executeConsoleCommand('configuration:showlocal', ['BE/installToolPassword', '--json']);
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$this->assertSame($config['BE']['installToolPassword'], \json_decode($output));
}

Expand All @@ -64,7 +65,7 @@ public function localConfigurationCanBeShownAsJson()
public function activeConfigurationCanBeShown()
{
$output = $this->executeConsoleCommand('configuration:showactive', ['BE/installToolPassword']);
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$this->assertStringContainsString($config['BE']['installToolPassword'], $output);
}

Expand All @@ -74,7 +75,7 @@ public function activeConfigurationCanBeShown()
public function activeConfigurationCanBeShownAsJson()
{
$output = $this->executeConsoleCommand('configuration:showactive', ['BE/installToolPassword', '--json']);
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$this->assertSame($config['BE']['installToolPassword'], \json_decode($output));
}

Expand All @@ -83,13 +84,13 @@ public function activeConfigurationCanBeShownAsJson()
*/
public function configurationCanBeSet()
{
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$oldPassword = $config['BE']['installToolPassword'];
$this->executeConsoleCommand('configuration:set', ['BE/installToolPassword', 'foobar']);
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$this->assertSame('foobar', $config['BE']['installToolPassword']);
$this->executeConsoleCommand('configuration:set', ['BE/installToolPassword', $oldPassword]);
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$this->assertSame($oldPassword, $config['BE']['installToolPassword']);
}

Expand All @@ -98,13 +99,13 @@ public function configurationCanBeSet()
*/
public function configurationCanBeRemovedAndSetAgainWithoutKeyPresent()
{
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$oldPassword = $config['BE']['installToolPassword'];
$this->executeConsoleCommand('configuration:remove', ['BE/installToolPassword', '--force']);
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$this->assertArrayNotHasKey('installToolPassword', $config['BE']);
$this->executeConsoleCommand('configuration:set', ['BE/installToolPassword', $oldPassword]);
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$this->assertSame($oldPassword, $config['BE']['installToolPassword']);
}

Expand All @@ -114,7 +115,7 @@ public function configurationCanBeRemovedAndSetAgainWithoutKeyPresent()
public function numericalIndexedArraysCanBeSet()
{
$this->executeConsoleCommand('configuration:set', ['EXTCONF/lang/availableLanguages/0', 'fr_FR']);
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$this->assertSame('fr_FR', $config['EXTCONF']['lang']['availableLanguages'][0]);
}

Expand All @@ -124,7 +125,7 @@ public function numericalIndexedArraysCanBeSet()
public function associativeArraysCanBeSet()
{
$this->executeConsoleCommand('configuration:set', ['EXTCONF/foo/bar', 'baz']);
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$this->assertSame('baz', $config['EXTCONF']['foo']['bar']);
}

Expand All @@ -134,7 +135,7 @@ public function associativeArraysCanBeSet()
public function arraysCanBeSetAsJson()
{
$this->executeConsoleCommand('configuration:set', ['EXTCONF/foo/baz', '["baz"]', '--json']);
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$this->assertSame(['baz'], $config['EXTCONF']['foo']['baz']);
}

Expand All @@ -144,7 +145,7 @@ public function arraysCanBeSetAsJson()
public function booleanCanBeSetAsJson()
{
$this->executeConsoleCommand('configuration:set', ['EXTCONF/foo/bool', 'true', '--json']);
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$this->assertTrue($config['EXTCONF']['foo']['bool']);
}

Expand All @@ -154,7 +155,7 @@ public function booleanCanBeSetAsJson()
public function nullCanBeSetAsJson()
{
$this->executeConsoleCommand('configuration:set', ['EXTCONF/foo/null', 'null', '--json']);
$config = require getenv('TYPO3_PATH_ROOT') . '/typo3conf/LocalConfiguration.php';
$config = require Typo3CompatibilityBridge::getSystemConfigurationFileLocation();
$this->assertNull($config['EXTCONF']['foo']['null']);
}

Expand Down