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] Ensure compatibility with TYPO3 9.1 and above #674

Merged
merged 1 commit into from
Feb 17, 2018
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
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ script:
jobs:
fast_finish: true
allow_failures:
- env: TYPO3_VERSION="dev-master as 9.0.0"
- env: TYPO3_VERSION="dev-master as 9.1.0"
include:
- &lint
stage: test
Expand Down Expand Up @@ -85,10 +85,10 @@ jobs:
env: TYPO3_VERSION=^8.7 PREFER_LOWEST="--prefer-lowest"
- stage: test
php: 7.2
env: TYPO3_VERSION="~9.0.0"
env: TYPO3_VERSION="~9.1.0"
- stage: test
php: 7.2
env: TYPO3_VERSION="dev-master as 9.0.0"
env: TYPO3_VERSION="dev-master as 9.1.0"

- stage: test
php: 7.1
Expand Down
6 changes: 1 addition & 5 deletions Classes/Core/Booting/CompatibilityScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
*
*/

use Helhum\Typo3Console\Extension\ExtensionConfiguration;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration as CoreExtensionConfiguration;

class CompatibilityScripts
{
public static function initializeConfigurationManagement()
Expand All @@ -33,7 +30,6 @@ public static function initializeDatabaseConnection()

public static function initializeExtensionConfiguration()
{
// Replace core functionality with something that is working for us
class_alias(ExtensionConfiguration::class, CoreExtensionConfiguration::class);
// noop for TYPO3 9
}
}
152 changes: 17 additions & 135 deletions Classes/Extension/ExtensionConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,153 +14,35 @@
*
*/

/*
* This file is part of the TYPO3 CMS 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 the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Configuration\ConfigurationManager;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Install\Service\ExtensionConfigurationService;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extensionmanager\Utility\InstallUtility;

/**
* With the current limited concept of extension configuration,
* essential TYPO3 Console functionality would be impossible,
* such as extension setup from active extensions, or flushing low level caches.
*
* Therefore we replace the original class with a more graceful alternative.
*/
class ExtensionConfiguration
{
private static $isInFallbackMode = false;

public function get(string $extension, string $path = '')
{
try {
return $this->getConfiguration($extension, $path);
} catch (\Throwable $e) {
if (self::$isInFallbackMode) {
throw $e;
}
self::$isInFallbackMode = true;
$this->saveDefaultConfiguration($extension, true);
self::$isInFallbackMode = false;
try {
return ArrayUtility::getValueByPath($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][$extension], $path);
} catch (\Throwable $e) {
return $this->getConfiguration($extension, $path);
}
}
}
/**
* @var InstallUtility
*/
private $extensionInstaller;

public function set(string $extension, string $path = '', $value = null)
public function __construct(InstallUtility $extensionInstaller = null)
{
if (self::$isInFallbackMode) {
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][$extension] = $value;
} else {
$this->setConfiguration($extension, $path, $value);
}
$this->extensionInstaller = $extensionInstaller ?: GeneralUtility::makeInstance(ObjectManager::class)->get(InstallUtility::class);
}

public function saveDefaultConfiguration(string $extension, $force = false)
{
if (!$force
&& isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extension], $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][$extension])
if ((!$force
&& isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extension]))
|| !@is_file(ExtensionManagementUtility::extPath($extension, 'ext_conf_template.txt'))
) {
return;
}
$extensionConfigurationService = new ExtensionConfigurationService();
$extensionConfigurationService->synchronizeExtConfTemplateWithLocalConfiguration($extension);
}

// Unmodified TYPO3 code below

/**
* API to get() and set() instance specific extension configuration options.
*
* Extension authors are encouraged to use this API - it is currently a simple
* wrapper to access TYPO3_CONF_VARS['EXTENSIONS'] but could later become something
* different in case core decides to store extension configuration elsewhere.
*
* Extension authors must not access TYPO3_CONF_VARS['EXTENSIONS'] on their own.
*
* Extension configurations are often 'feature flags' currently defined by
* ext_conf_template.txt files. The core (more specifically the install tool)
* takes care default values and overridden values are properly prepared upon
* loading or updating an extension.
*/
private function getConfiguration(string $extension, string $path = '')
{
if (!isset($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][$extension]) || !is_array($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][$extension])) {
throw new ExtensionConfigurationExtensionNotConfiguredException(
'No extension configuration for extension ' . $extension . ' found. Either this extension'
. ' has no extension configuration or the configuration is not up to date. Execute the'
. ' install tool to update configuration.',
1509654728
);
}
if (empty($path)) {
return $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][$extension];
}
if (!ArrayUtility::isValidPath($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'], $extension . '/' . $path)) {
throw new ExtensionConfigurationPathDoesNotExistException(
'Path ' . $path . ' does not exist in extension configuration',
1509977699
);
}
return ArrayUtility::getValueByPath($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'], $extension . '/' . $path);
}

private function setConfiguration(string $extension, string $path = '', $value = null)
{
if (empty($extension)) {
throw new \RuntimeException('extension name must not be empty', 1509715852);
}
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
if ($path === '' && $value === null) {
// Remove whole extension config
$configurationManager->removeLocalConfigurationKeysByPath([ 'EXTENSIONS/' . $extension ]);
} elseif ($path !== '' && $value === null) {
// Remove a single value or sub path
$configurationManager->removeLocalConfigurationKeysByPath([ 'EXTENSIONS/' . $extension . '/' . $path]);
} elseif ($path === '' && $value !== null) {
// Set full extension config
$configurationManager->setLocalConfigurationValueByPath('EXTENSIONS/' . $extension, $value);
} else {
// Set single path
$configurationManager->setLocalConfigurationValueByPath('EXTENSIONS/' . $extension . '/' . $path, $value);
}

// After TYPO3_CONF_VARS['EXTENSIONS'] has been written, update legacy layer TYPO3_CONF_VARS['EXTENSIONS']['extConf']
// @deprecated since TYPO3 v9, will be removed in v10 with removal of old serialized 'extConf' layer
$extensionsConfigs = $configurationManager->getConfigurationValueByPath('EXTENSIONS');
foreach ($extensionsConfigs as $extensionName => $extensionConfig) {
$extensionConfig = $this->addDotsToArrayKeysRecursiveForLegacyExtConf($extensionConfig);
$configurationManager->setLocalConfigurationValueByPath('EXT/extConf/' . $extensionName, serialize($extensionConfig));
}
}

private function addDotsToArrayKeysRecursiveForLegacyExtConf(array $extensionConfig)
{
$newArray = [];
foreach ($extensionConfig as $key => $value) {
if (is_array($value)) {
$newArray[$key . '.'] = $this->addDotsToArrayKeysRecursiveForLegacyExtConf($value);
} else {
$newArray[$key] = $value;
}
}
return $newArray;
$method = 'saveDefaultConfiguration';
$installer = $this->extensionInstaller;
\Closure::bind(function () use ($installer, $method, $extension) {
return $installer->$method($extension);
}, null, $installer)();
}
}
4 changes: 2 additions & 2 deletions Classes/Install/Upgrade/SilentConfigurationUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

use Symfony\Component\Console\Exception\RuntimeException;
use TYPO3\CMS\Core\Configuration\ConfigurationManager;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Install\Service\Exception\ConfigurationChangedException;
use TYPO3\CMS\Install\Service\ExtensionConfigurationService;
use TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService;

/**
Expand Down Expand Up @@ -49,7 +49,7 @@ public function executeSilentConfigurationUpgradesIfNeeded()
}
// We need to write the extension configuration for all active extensions ourselves
// as the core does not take care doing so (yet)
$extensionConfigurationService = new ExtensionConfigurationService();
$extensionConfigurationService = new ExtensionConfiguration();
$extensionConfigurationService->synchronizeExtConfTemplateWithLocalConfigurationOfAllExtensions();

$upgradeService = new SilentConfigurationUpgradeService($this->configurationManager);
Expand Down
55 changes: 0 additions & 55 deletions Compatibility/TYPO3v87/Extension/ExtensionConfiguration.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ public function extensionSetupActiveWorksWhenExtensionChecksConfigInExtLocalConf
$config = @\json_decode(trim($this->executeConsoleCommand('configuration:showlocal', ['EXT/extConf', '--json'])), true);
$this->assertArrayHasKey('ext_config', $config);
} finally {
$this->removeFixtureExtensionCode('ext_config');
$this->executeConsoleCommand('install:generatepackagestates', ['--activate-default']);
$this->executeConsoleCommand('configuration:remove', ['EXTENSIONS/ext_config', '--force']);
$this->executeConsoleCommand('configuration:remove', ['EXT/extConf/ext_config', '--force']);
$this->removeFixtureExtensionCode('ext_config');
}
}

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ environment:
TYPO3_INSTALL_DB_DBNAME: 'appveyor_console_test'

matrix:
- TYPO3_VERSION: '~9.0.0'
- TYPO3_VERSION: '~9.1.0'
PHP_VERSION: '7.2.1-Win32-VC15'
- TYPO3_VERSION: '~8.7'
PHP_VERSION: '7.1.13-Win32-VC14'
Expand Down
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@
"php": ">=7.0.0 <7.3",
"helhum/typo3-console-plugin": "^2.0.2",

"typo3/cms-backend": "^8.7.10 || ~9.0.0",
"typo3/cms-core": "^8.7.10 || ~9.0.0",
"typo3/cms-extbase": "^8.7.10 || ~9.0.0",
"typo3/cms-extensionmanager": "^8.7.10 || ~9.0.0",
"typo3/cms-fluid": "^8.7.10 || ~9.0.0",
"typo3/cms-install": "^8.7.10 || ~9.0.0",
"typo3/cms-scheduler": "^8.7.10 || ~9.0.0",
"typo3/cms-saltedpasswords": "^8.7.10 || ~9.0.0",
"typo3/cms-backend": "^8.7.10 || ~9.1.0",
"typo3/cms-core": "^8.7.10 || ~9.1.0",
"typo3/cms-extbase": "^8.7.10 || ~9.1.0",
"typo3/cms-extensionmanager": "^8.7.10 || ~9.1.0",
"typo3/cms-fluid": "^8.7.10 || ~9.1.0",
"typo3/cms-install": "^8.7.10 || ~9.1.0",
"typo3/cms-scheduler": "^8.7.10 || ~9.1.0",
"typo3/cms-saltedpasswords": "^8.7.10 || ~9.1.0",

"doctrine/annotations": "^1.4",
"symfony/console": "^3.3.6 || ^4.0",
"symfony/process": "^3.3.6 || ^4.0"
},
"require-dev": {
"typo3/cms-reports": "^8.7.10 || ~9.0.0 || 9.1.*@dev",
"typo3/cms-filemetadata": "^8.7.10 || ~9.0.0 || 9.1.*@dev",
"typo3/cms-reports": "^8.7.10 || ~9.1.0 || 9.2.*@dev",
"typo3/cms-filemetadata": "^8.7.10 || ~9.1.0 || 9.2.*@dev",

"typo3-console/php-server-command": "^0.1.1",
"typo3-console/create-reference-command": "^2.2",
Expand Down