TYPO3_REQUEST in scheduler command is null

47 views Asked by At

To use the global variable in TYPO3_REQUEST is in a TYPO3 v12 Symfony command not possible. It works if I start the command manually in the scheduler task module. But when the task is executed as cron tab $GLOABLS['TYPO3_REQUEST'] is null.

Is there an other workaround to use the TYPO3 request object in symfony commands? I only found in vendor/typo3/cms-backend/Classes/Command/ResetPasswordCommand.php a workaround with a fake request. Is this the recommended way?

In the docs I couldn't find a hint https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/RequestLifeCycle/Typo3Request.html

2

There are 2 answers

1
Garvin Hicking On

Usually a backend task is not bound to a request, so yes you can only "fake" it.

However; what is your specific use case, what would you need from the request, maybe you can handle it differently?

0
mhirdes On

In this case for to change the language in a standalone view, this helps:

$emailView = GeneralUtility::makeInstance(StandaloneView::class); 
$request = self::getTypo3Request()->withAttribute('language', $siteLanguage); $emailView->setRequest($request); 
public static function getTypo3Request(): ServerRequestInterface
    {
        if(!empty($GLOBALS['TYPO3_REQUEST'])) {
            return $GLOBALS['TYPO3_REQUEST'];
        }

        return (new ServerRequest())->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE);
    }