Skip to content

Commit

Permalink
[BUGFIX] Fix handling of deprecated cache configuration
Browse files Browse the repository at this point in the history
When initializing the configuration for a cache any existing
configuration under its old name (cache_ prefixed) is applied
as an additive override now. This ensures that basic configuration
like groups are preserved and not removed with the formerly correct
way to adjust cache-config.

Resolves: #91306
Releases: master
Change-Id: Ic862f80263f410688d2dffb7c13948c1c40488a3
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64407
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Johannes Kasberger <johannes.kasberger@reelworx.at>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Benjamin Franzke <bfr@qbus.de>
Reviewed-by: Johannes Kasberger <johannes.kasberger@reelworx.at>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Benjamin Franzke <bfr@qbus.de>
  • Loading branch information
liayn authored and bnf committed May 20, 2020
1 parent c96bf68 commit 534e7cf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
7 changes: 6 additions & 1 deletion typo3/sysext/core/Classes/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public function __construct(bool $disableCaching = false)
*/
public function setCacheConfigurations(array $cacheConfigurations)
{
$newConfiguration = [];
$migratedConfiguration = [];
foreach ($cacheConfigurations as $identifier => $configuration) {
if (!is_array($configuration)) {
throw new \InvalidArgumentException('The cache configuration for cache "' . $identifier . '" was not an array as expected.', 1231259656);
Expand All @@ -101,9 +103,12 @@ public function setCacheConfigurations(array $cacheConfigurations)
if (strpos($identifier, 'cache_') === 0) {
trigger_error('Accessing a cache with the "cache_" prefix as in "' . $identifier . '" is not necessary anymore, and should be called without the cache prefix.', E_USER_DEPRECATED);
$identifier = substr($identifier, 6);
$migratedConfiguration[$identifier] = $configuration;
} else {
$newConfiguration[$identifier] = $configuration;
}
$this->cacheConfigurations[$identifier] = $configuration;
}
$this->cacheConfigurations = array_replace_recursive($newConfiguration, $migratedConfiguration);
}

/**
Expand Down
41 changes: 41 additions & 0 deletions typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,45 @@ public function flushCachesInGroupByTagsDeletesByTag()
$manager->setCacheConfigurations($configuration);
$manager->flushCachesInGroupByTags('group2', $tags);
}

/**
* @test
*/
public function setCacheConfigurationsMergesLegacyConfigCorrectly()
{
$rawConfiguration = [
'pages' => [
'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class,
'options' => [
'compression' => true,
],
'groups' => ['pages'],
],
'cache_pages' => [
'backend' => \TYPO3\CMS\Core\Cache\Backend\RedisBackend::class,
'options' => [
'hostname' => 'redis',
],
'groups' => ['pages'],
],
];
$expectedConfiguration = [
'pages' => [
'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
'backend' => \TYPO3\CMS\Core\Cache\Backend\RedisBackend::class,
'options' => [
'compression' => true,
'hostname' => 'redis',
],
'groups' => ['pages']
],
];
$this->expectDeprecation();

/** @var \PHPUnit\Framework\MockObject\MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface|CacheManager $manager */
$manager = $this->getAccessibleMock(CacheManager::class, ['dummy']);
$manager->setCacheConfigurations($rawConfiguration);
self::assertEquals($expectedConfiguration, $manager->_get('cacheConfigurations'));
}
}

0 comments on commit 534e7cf

Please sign in to comment.