Bug #99307
closedExtbase repository method call from command leads to "Undefined global variable $TYPO3_REQUEST"
100%
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
Updated by Alex Kellner almost 2 years ago
Same happens when using an injection method for the extbase repository instead of using makeInstance()
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?
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
Updated by Oliver Bartsch almost 2 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset c28d52476e57da6c52456913621114130b64f4a8.
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
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
Updated by Oliver Bartsch almost 2 years ago
- Status changed from Under Review to Resolved
Applied in changeset 363ac2ee69d0a9e22b641317692a937d409c9790.