From cd9cc4fb303288132ae52fdadd9f6a719365a309 Mon Sep 17 00:00:00 2001 From: Konrad Michalik Date: Wed, 1 Jul 2026 12:19:10 +0200 Subject: [PATCH 1/2] fix: skip ServerRequestFactory::fromGlobals() on CLI to avoid InvalidRequestUrlOnCliException --- Classes/Service/SiteService.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Classes/Service/SiteService.php b/Classes/Service/SiteService.php index 3ea4975..10c7298 100644 --- a/Classes/Service/SiteService.php +++ b/Classes/Service/SiteService.php @@ -5,6 +5,7 @@ namespace SourceBroker\T3api\Service; use SourceBroker\T3api\Routing\Enhancer\ResourceEnhancer; +use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Exception\SiteNotFoundException; use TYPO3\CMS\Core\Http\ServerRequestFactory; use TYPO3\CMS\Core\Routing\SiteMatcher; @@ -69,7 +70,11 @@ public static function getByIdentifier(string $identifier): Site protected static function getResolvedByTypo3(): ?SiteInterface { - if (!class_exists(SiteMatcher::class)) { + // On CLI there is no valid request URL, so ServerRequestFactory::fromGlobals() + // throws InvalidRequestUrlOnCliException. That breaks any consumer which triggers + // route-enhancer matching inside a CLI sub-request (e.g. EXT:solr v14 indexing). + // Returning null lets the URL / wildcard fallbacks below resolve the site instead. + if (!class_exists(SiteMatcher::class) || Environment::isCli()) { return null; } From 107b9def292a17e012ffe3c12cadda65d4da0592 Mon Sep 17 00:00:00 2001 From: Konrad Michalik Date: Wed, 1 Jul 2026 13:41:17 +0200 Subject: [PATCH 2/2] fix: skip T3api route enhancer when the current site cannot be resolved (CLI sub-requests / EXT:solr v14 indexing) --- Classes/Routing/Enhancer/ResourceEnhancer.php | 15 +++++++++++++-- Classes/Service/SiteService.php | 7 +------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Classes/Routing/Enhancer/ResourceEnhancer.php b/Classes/Routing/Enhancer/ResourceEnhancer.php index b1ef7c6..9816d92 100644 --- a/Classes/Routing/Enhancer/ResourceEnhancer.php +++ b/Classes/Routing/Enhancer/ResourceEnhancer.php @@ -31,11 +31,22 @@ public function __construct(array $configuration) */ public function enhanceForMatching(RouteCollection $collection): void { + try { + $basePath = $this->getBasePath(); + } catch (\Throwable) { + // The T3api base path cannot be resolved when the current site is not + // determinable, e.g. in CLI sub-requests such as EXT:solr v14 page indexing + // where ServerRequestFactory::fromGlobals() has no valid request URL. The + // API routes are irrelevant for such requests, so skip enhancement instead + // of breaking route matching for the whole request. + return; + } + /** @var Route $variant */ $variant = clone $collection->get('default'); - $variant->setPath($this->getBasePath() . sprintf('/{%s?}', self::PARAMETER_NAME)); + $variant->setPath($basePath . sprintf('/{%s?}', self::PARAMETER_NAME)); $variant->setRequirement(self::PARAMETER_NAME, '.*'); - $collection->add('enhancer_' . $this->getBasePath() . spl_object_hash($variant), $variant); + $collection->add('enhancer_' . $basePath . spl_object_hash($variant), $variant); } /** diff --git a/Classes/Service/SiteService.php b/Classes/Service/SiteService.php index 10c7298..3ea4975 100644 --- a/Classes/Service/SiteService.php +++ b/Classes/Service/SiteService.php @@ -5,7 +5,6 @@ namespace SourceBroker\T3api\Service; use SourceBroker\T3api\Routing\Enhancer\ResourceEnhancer; -use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Exception\SiteNotFoundException; use TYPO3\CMS\Core\Http\ServerRequestFactory; use TYPO3\CMS\Core\Routing\SiteMatcher; @@ -70,11 +69,7 @@ public static function getByIdentifier(string $identifier): Site protected static function getResolvedByTypo3(): ?SiteInterface { - // On CLI there is no valid request URL, so ServerRequestFactory::fromGlobals() - // throws InvalidRequestUrlOnCliException. That breaks any consumer which triggers - // route-enhancer matching inside a CLI sub-request (e.g. EXT:solr v14 indexing). - // Returning null lets the URL / wildcard fallbacks below resolve the site instead. - if (!class_exists(SiteMatcher::class) || Environment::isCli()) { + if (!class_exists(SiteMatcher::class)) { return null; }