diff --git a/typo3/sysext/core/Classes/Cache/CacheManager.php b/typo3/sysext/core/Classes/Cache/CacheManager.php index 62ed306d186ff2e06b614156142250a3486cfd00..0272037848deacbec774a5105002e022e3f51a05 100644 --- a/typo3/sysext/core/Classes/Cache/CacheManager.php +++ b/typo3/sysext/core/Classes/Cache/CacheManager.php @@ -93,6 +93,8 @@ class CacheManager implements SingletonInterface */ 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); @@ -101,9 +103,12 @@ class CacheManager implements SingletonInterface 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); } /** diff --git a/typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php b/typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php index 6806e52e96dcad67c2e00950354ec6740ccdafea..e2ae47958f84b3b8b830a2691edea3353423174a 100644 --- a/typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php +++ b/typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php @@ -496,4 +496,45 @@ class CacheManagerTest extends UnitTestCase $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')); + } }