Issue Bug New Orphaned

#90962Cache and Dependency Injection in Upgrade module

Chris Müller 04/06/20, 16:05 updated 06/10/20, 10:54

Description

In my schema extension I injected a frontend cache with DI into a class.

The cache is defined in the ext_localconf.php:

    $coreCacheIdentifier = 'tx_' . $extensionKey . '_core';
    if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$coreCacheIdentifier])) {
        $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$coreCacheIdentifier] = [];
    }
    if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$coreCacheIdentifier]['frontend'])) {
        $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$coreCacheIdentifier]['frontend'] = \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class;
    }
    if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$coreCacheIdentifier]['backend'])) {
        $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$coreCacheIdentifier]['backend'] = \TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend::class;
    }
    if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$coreCacheIdentifier]['options'])) {
        $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$coreCacheIdentifier]['options']['defaultLifetime'] = 0;
    }

and listed correctly in the Configuration module.

Definition in Services.yaml:

services:
  cache.tx_schema_core:
    class: TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
    factory: ['@TYPO3\CMS\Core\Cache\CacheManager', 'getCache']
    arguments: ['tx_schema_core']

  Brotkrueml\Schema\Registry\TypeRegistry:
    arguments:
      $cache: '@cache.tx_schema_core'
      $packageManager: '@TYPO3\CMS\Core\Package\PackageManager'

In the TypeRegistry class itself, the the constructor looks like:

public function __construct(FrontendInterface $cache = null, PackageManager $packageManager = null)

The injection works for most cases in frontend and backend. However, executing two routines in the Upgrade module fail:

- Check TCA in ext_tables.php
- Check TCA Migrations

upgrade_check_tca.png

But: When I define the cache in the AdditionalConfiguration.php instead of localconf.php it works. Also when deactivating DI in Services.yaml

The behaviour can be reproduced with the schema extension (commit af18687d from April 5th):
https://github.com/brotkrueml/schema

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

Fix this issue

Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch

Commit message
[BUGFIX] Cache and Dependency Injection in Upgrade module Resolves: #90962 Releases: main