Issue Bug Closed

#90991BackendUser authentication fails for DataHandler in symfony command on command line

Jürgen Venne 04/09/20, 16:36 updated 04/14/20, 09:49

Description

I use this in my symfony command as described on https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Typo3CoreEngine/UsingDataHandler/Index.html

TYPO3 dev-master 10.4 typo3/cms-core commit b4192d6

    public function execute(InputInterface $input, OutputInterface $output)
    {
        // authenticate CommandLineUserAuthentication user for DataHandler usage
        Bootstrap::initializeBackendAuthentication(); // is marked @internal, so use GLOBALS directly
        // $GLOBALS['BE_USER']->backendCheckLogin();
        // TYPO3 9 < 9.5.14 commands do not support method injection
        $this->dataHandler = GeneralUtility::makeInstance(DataHandler::class);
        // here*
        $this->dataHandler->clear_cacheCmd('pages');

This works in TYPO3 9.5.14
TYPO3 10.4-dev shows if the command is called from command line:

Uncaught TYPO3 Exception Call to a member function getTSConfig() on null
thrown in file /var/www/html/web/typo3/sysext/core/Classes/DataHandling/DataHandler.php
in line 8130

This is caused by $this->dataHandler->BE_USER is null.
As workaround I insert this to //here*:

        if ($this->dataHandler->BE_USER === null) {
            // Bug workaround: DataHandler BE_USER is not correct initialized on command line in TYPO3 10.4-dev
            $this->dataHandler->BE_USER = $GLOBALS['BE_USER'];
        }

It looks like the authentication fails for DataHandler.

Reviews 0

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