Deprecation: #111298 - DataHandler->clear_cacheCmd() 

See forge#111298

Description 

The method \TYPO3\CMS\Core\DataHandling\DataHandler->clear_cacheCmd() has been deprecated. Cache commands such as "pages", "all", a page id or "cacheTag:<tag>" are flushed by \TYPO3\CMS\Core\Cache\Flush\CacheFlusher , which needs no DataHandler instance, see Feature: #111263 - Flush caches without DataHandler.

Impact 

Calling the method triggers a PHP E_USER_DEPRECATED error. The extension scanner reports usages.

Affected installations 

Installations with extensions calling DataHandler->clear_cacheCmd() , usually to flush caches without processing any data map or command map.

Migration 

Flush the cache command with CacheFlusher . Pass a CacheFlushingContext created from the backend user to keep checking the permissions of User TSconfig options.clearCache . Without it, the command is flushed unrestricted, which fits scheduler tasks or console commands.

Before:

use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility;

$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->start([], []);
$dataHandler->clear_cacheCmd('pages');
Copied!

After:

use TYPO3\CMS\Core\Cache\Flush\CacheFlushDemand;
use TYPO3\CMS\Core\Cache\Flush\CacheFlusher;
use TYPO3\CMS\Core\Cache\Flush\CacheFlushingContext;

public function __construct(
    private readonly CacheFlusher $cacheFlusher,
) {}

public function flushPageCaches(): void
{
    $this->cacheFlusher->flush(
        CacheFlushDemand::forCommand('pages'),
        CacheFlushingContext::fromBackendUser($GLOBALS['BE_USER'])
    );
}
Copied!