Project

General

Profile

Actions

Bug #99307

closed

Extbase repository method call from command leads to "Undefined global variable $TYPO3_REQUEST"

Added by Alex Kellner almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2022-12-07
Due date:
% Done:

100%

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

Description

Scenaria: Registered symfony command where an extbase repository is created via GeneralUtility::makeInstance(). Using something like $repository->findByUid(1) leads to this error:

PHP Warning: Undefined global variable $TYPO3_REQUEST in .../vendor/typo3/cms-extbase/Classes/Configuration/BackendConfigurationManager.php line 159

Exception trace:
  at /var/www/html/luxletter.localhost.de/vendor/typo3/cms-core/Classes/Error/ErrorHandler.php:138
 TYPO3\CMS\Core\Error\ErrorHandler->handleError() at /var/www/html/luxletter.localhost.de/vendor/typo3/cms-extbase/Classes/Configuration/BackendConfigurationManager.php:159
 TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager->getConfiguration() at /var/www/html/luxletter.localhost.de/vendor/typo3/cms-extbase/Classes/Configuration/ConfigurationManager.php:100
 TYPO3\CMS\Extbase\Configuration\ConfigurationManager->getConfiguration() at /var/www/html/luxletter.localhost.de/vendor/typo3/cms-extbase/Classes/Persistence/Generic/QueryFactory.php:62
 TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory->create() at /var/www/html/luxletter.localhost.de/vendor/typo3/cms-extbase/Classes/Persistence/Generic/PersistenceManager.php:177
 TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager->createQueryForType() at /var/www/html/luxletter.localhost.de/vendor/typo3/cms-extbase/Classes/Persistence/Generic/Backend.php:200
 TYPO3\CMS\Extbase\Persistence\Generic\Backend->getObjectByIdentifier() at /var/www/html/luxletter.localhost.de/vendor/typo3/cms-extbase/Classes/Persistence/Generic/PersistenceManager.php:145
 TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager->getObjectByIdentifier() at /var/www/html/luxletter.localhost.de/vendor/typo3/cms-extbase/Classes/Persistence/Repository.php:158
 TYPO3\CMS\Extbase\Persistence\Repository->findByIdentifier() at /var/www/html/luxletter.localhost.de/vendor/typo3/cms-extbase/Classes/Persistence/Repository.php:147
 TYPO3\CMS\Extbase\Persistence\Repository->findByUid() at /var/www/PhpstormProjects/luxletter/Classes/Command/QueueCommand.php:69
 In2code\Luxletter\Command\QueueCommand->execute() at /var/www/html/luxletter.localhost.de/vendor/symfony/console/Command/Command.php:312
 Symfony\Component\Console\Command\Command->run() at /var/www/html/luxletter.localhost.de/vendor/symfony/console/Application.php:1038
 Symfony\Component\Console\Application->doRunCommand() at /var/www/html/luxletter.localhost.de/vendor/symfony/console/Application.php:312
 Symfony\Component\Console\Application->doRun() at /var/www/html/luxletter.localhost.de/vendor/symfony/console/Application.php:168
 Symfony\Component\Console\Application->run() at /var/www/html/luxletter.localhost.de/vendor/typo3/cms-core/Classes/Console/CommandApplication.php:117
 TYPO3\CMS\Core\Console\CommandApplication->run() at /var/www/html/luxletter.localhost.de/vendor/typo3/cms-cli/typo3:23
 {closure}() at /var/www/html/luxletter.localhost.de/vendor/typo3/cms-cli/typo3:24
 include() at /var/www/html/luxletter.localhost.de/vendor/bin/typo3:120

Any breaking change here? TYPO3 12.1.0

Actions #1

Updated by Alex Kellner almost 2 years ago

Same happens when using an injection method for the extbase repository instead of using makeInstance()

Actions #2

Updated by Alex Kellner almost 2 years ago

Thx to Georg on slack there is a workarround for this:

if (!isset($GLOBALS['TYPO3_REQUEST'])) {
            // @todo: FormPersistenceManager is sometimes triggered via CLI without request. In this
            //        case we fake a request so extbase ConfigurationManager still works.
            $request = (new ServerRequest())->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE);
            $GLOBALS['TYPO3_REQUEST'] = $request;
            $fakeRequest = true;
        }

This seems to work. Final question: Is this a permanent or temporarily workarround?

Actions #3

Updated by Gerrit Code Review almost 2 years ago

  • Status changed from New to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77028

Actions #4

Updated by Oliver Bartsch almost 2 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #5

Updated by Gerrit Code Review almost 2 years ago

  • Status changed from Resolved to Under Review

Patch set 1 for branch 12.1 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77134

Actions #6

Updated by Gerrit Code Review almost 2 years ago

Patch set 2 for branch 12.1 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77134

Actions #7

Updated by Oliver Bartsch almost 2 years ago

  • Status changed from Under Review to Resolved
Actions #8

Updated by Benni Mack almost 2 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF