[BUGFIX] prevent exception on command line caused by undefined HTTP Host #2136
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Setting TYPO3_PATH_ROOT does not resolve the problem for me, it is also already set correctly by TYPO3.
The cause of the problem is missing HTTP_HOST in $_SERVER on the command line.
If you look at \TYPO3\CMS\Core\Http\NormalizedParams::determineSiteUrl, the parameter $requestDir is not a server directory, but the request host with the script path appended.
On the command line (and also in the backend context) the server params are not passed to the newly created ServerRequest instance in \FluidTYPO3\Flux\Builder\RequestBuilder::getServerRequest, so the HTTP host is always empty.
In TYPO3 >= 11.x a cast to string was added in \TYPO3\CMS\Core\Http\NormalizedParams::determineSiteUrl
so the exception cannot occur there any more.
My suggested solution for this would be to add fallback handling in case the HTTP host is empty:
first check if any site contains a full host name as the base
if no host name is found, set a dummy host as a last resort for TYPO3 10.4 only.
Since this is only used for the temporary Request object in \FluidTYPO3\Flux\Integration\Configuration\SpooledConfigurationApplicator::spoolQueuedContentTypeRegistrations, this should have no effect on anything outside of EXT:flux.