Bug #90991

BackendUser authentication fails for DataHandler in symfony command on command line

Added by Jürgen Venne almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
CLI
Start date:
2020-04-09
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
7.4
Tags:
Complexity:
Is Regression:
Sprint Focus:

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.

#1

Updated by Jürgen Venne almost 2 years ago

  • Subject changed from BackendUser authentication fails in symfony command on command line to BackendUser authentication fails for DataHandler in symfony command on command line
#2

Updated by Benni Mack almost 2 years ago

  • Status changed from New to Needs Feedback

Hey Jürgen.

I wonder why this has ever worked. When instantiating DataHandler you always need to call start() before doing anything. This is mainly related since DataHandler-> clear_cacheCmd() now needs a valid BackendUser to validate PageTS (done the proper way), so I recommend you add this line of code in your v9 code already to be easily forward compatible.

#3

Updated by Benni Mack almost 2 years ago

  • Target version changed from 10 LTS to Candidate for patchlevel
#4

Updated by Jürgen Venne almost 2 years ago

It works now as you described.
Thank you Benni.

#5

Updated by Benni Mack almost 2 years ago

  • Status changed from Needs Feedback to Closed

Also available in: Atom PDF