diff --git a/Neos.Neos/Classes/FrontendRouting/SiteDetection/SiteDetectionMiddleware.php b/Neos.Neos/Classes/FrontendRouting/SiteDetection/SiteDetectionMiddleware.php index 7460502d0f4..9f1003588d6 100644 --- a/Neos.Neos/Classes/FrontendRouting/SiteDetection/SiteDetectionMiddleware.php +++ b/Neos.Neos/Classes/FrontendRouting/SiteDetection/SiteDetectionMiddleware.php @@ -5,6 +5,7 @@ namespace Neos\Neos\FrontendRouting\SiteDetection; use Neos\Flow\Annotations as Flow; +use Neos\Flow\Persistence\Doctrine\Exception\DatabaseException; use Neos\Neos\Domain\Model\Site; use Neos\Neos\Domain\Repository\DomainRepository; use Neos\Neos\Domain\Repository\SiteRepository; @@ -42,19 +43,25 @@ final class SiteDetectionMiddleware implements MiddlewareInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - $requestUriHost = $request->getUri()->getHost(); $site = null; - if (!empty($requestUriHost)) { - $activeDomain = $this->domainRepository->findOneByHost($requestUriHost, true); - if ($activeDomain !== null) { - $site = $activeDomain->getSite(); + $requestUriHost = $request->getUri()->getHost(); + try { + if (!empty($requestUriHost)) { + // try to get site by domain + $activeDomain = $this->domainRepository->findOneByHost($requestUriHost, true); + $site = $activeDomain?->getSite(); } - } - if ($site === null) { - $site = $this->siteRepository->findFirstOnline(); + if ($site === null) { + // try to get any site + $site = $this->siteRepository->findFirstOnline(); + } + } catch (DatabaseException) { + // doctrine might have not been migrated yet or no database is connected. } if (!$site instanceof Site) { + // no site has been created yet, + // but we allow other middlewares / routes to work return $handler->handle($request); } diff --git a/Neos.Neos/Classes/FrontendRouting/SiteDetection/SiteDetectionResult.php b/Neos.Neos/Classes/FrontendRouting/SiteDetection/SiteDetectionResult.php index d4ef6060165..9fa9eddc4cd 100644 --- a/Neos.Neos/Classes/FrontendRouting/SiteDetection/SiteDetectionResult.php +++ b/Neos.Neos/Classes/FrontendRouting/SiteDetection/SiteDetectionResult.php @@ -60,7 +60,7 @@ public static function fromRouteParameters(RouteParameters $routeParameters): se if ($siteNodeName === null || $contentRepositoryId === null) { throw new \RuntimeException( 'Current site and content repository could not be extracted from the Request.' - . ' SiteDetectionMiddleware must run before calling this method!' + . ' The SiteDetectionMiddleware was not able to determine the site!' ); } assert(is_string($siteNodeName));