Actions
Bug #105616
closedExtbase repository call from command leads to: ConfigurationManager has not been initialized properly
Status:
Closed
Priority:
Should have
Assignee:
-
Category:
CLI
Target version:
-
Start date:
2024-11-17
Due date:
% Done:
0%
Estimated time:
TYPO3 Version:
13
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:
Description
An issue in TYPO3 13. When calling an extbase repository from a command, this error happens:
No request given. ConfigurationManager has not been initialized properly.
Example command:
public function execute(InputInterface $input, OutputInterface $output): int { $dlR = GeneralUtility::makeInstance(DownloadRepository::class); $dlR->findAll(); }
The DownloadRepository is a completely default extbase repository and can be empty.
Updated by Garvin Hicking 4 days ago
- Is duplicate of Bug #105554: Enable Extbase to be used in console commands added
Updated by Garvin Hicking 4 days ago
- Category set to CLI
- Status changed from New to Closed
Extbase is bound to frontend requests, specifically it needs TypoScript to setup persistence atrributes.
The linked issue is a request to make bootstrapping a custom frontend request easier to set up.
For now you can use something along these lines (from Christoph Erdmann via slack typo3-cms):
private function initCliEnvironment(): void { if (PHP_SAPI === 'cli') { $this->classesConfigurationFactory->createClassesConfiguration(); Bootstrap::initializeBackendAuthentication(); /** @var SiteFinder $siteFinder */ $siteFinder = GeneralUtility::makeInstance(SiteFinder::class); $site = $siteFinder->getSiteByIdentifier('your-site'); $language = $site->getLanguageById(0); $GLOBALS['BE_USER']->user['lang'] = $language->getLocale()->getLanguageCode(); $serverRequest = new ServerRequest(); $serverRequest = $serverRequest->withAttribute('extbase', []); $serverRequest = $serverRequest->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE); $serverRequest = $serverRequest->withAttribute('language', $language); $this->configurationManager->setRequest($serverRequest); } }
Or the code of the linked issue as an example.
Another possibility is to maybe utilize the QueryBuilder to access data you need
In CLI context (for reading) or DataHandler (for writing)
Hope that helps, I'm closing this in favor of the other open issue.
Actions