Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: SiteDetectionMiddleware should not crash without doctrine migrations #4715

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,19 +43,27 @@ 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)) {
$activeDomain = $this->domainRepository->findOneByHost($requestUriHost, true);
if ($activeDomain !== null) {
$site = $activeDomain->getSite();
}
}
}
if ($site === null) {
$site = $this->siteRepository->findFirstOnline();
if ($site === null) {
$site = $this->siteRepository->findFirstOnline();
}
} catch (DatabaseException) {
// doctrine might have not been migrated yet or not database exists.
// this doesn't have to be handled here, and we should allow other middlewares / routes to work
return $handler->handle($request);
}

if (!$site instanceof Site) {
// no site has been created yet,
// but we allow other middlewares / routes to work
return $handler->handle($request);
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading