Skip to content

Commit

Permalink
[BUGFIX] Fix cache clear task
Browse files Browse the repository at this point in the history
The task to clear caches related to files results in abnormal
termination of the program. This is caused because the DataMapper used
to clear caches expects the BE_USER to either be null or fully
authenticated.

This fix copies over the existing logic to authenticate from the other
cache clear task. It also adds a condition ensuring the authentication
logic runs only once, as a second authentication is redundant if both
tasks get executed.
  • Loading branch information
dreistromlandMf authored and dhoffmann1979 committed Sep 26, 2024
1 parent 923365f commit f8bdf0b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ protected function getDataHandler(): DataHandler
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
/** @var CommandLineUserAuthentication $user */
$user = $GLOBALS['BE_USER'];
$user->authenticate();

if (!$user->user) {
$user->authenticate();
}

$dataHandler->BE_USER = $user;

/** @psalm-suppress InternalProperty */
$dataHandler->admin = true;
return $dataHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

use Doctrine\DBAL\Result;
use In2code\In2publishCore\CommonInjection\LocalDatabaseInjection;
use TYPO3\CMS\Core\Authentication\CommandLineUserAuthentication;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand Down Expand Up @@ -142,11 +143,29 @@ protected function resolveRecordsToPages(RecordCollection $recordCollection): vo

protected function clearCachesForPages(RecordCollection $recordCollection): void
{
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler = $this->getDataHandler();
$dataHandler->start([], []);
$pages = $recordCollection->getPages();
foreach ($pages as $page) {
$dataHandler->clear_cacheCmd($page);
}
}

protected function getDataHandler(): DataHandler
{
/** @var DataHandler $dataHandler */
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
/** @var CommandLineUserAuthentication $user */
$user = $GLOBALS['BE_USER'];

if (!$user->user) {
$user->authenticate();
}

$dataHandler->BE_USER = $user;

/** @psalm-suppress InternalProperty */
$dataHandler->admin = true;
return $dataHandler;
}
}

0 comments on commit f8bdf0b

Please sign in to comment.