Skip to content

Commit

Permalink
Merge pull request #53 from neos/bugfix/52-catch-exceptions-when-reso…
Browse files Browse the repository at this point in the history
…lving-node-uris

BUGFIX: Catch exceptions while building node URIs
  • Loading branch information
bwaidelich authored Jan 13, 2021
2 parents 02af004 + c729b44 commit a46d920
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions Classes/Service/NodeRedirectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Http\Exception as HttpException;
use Neos\Flow\Http\HttpRequestHandlerInterface;
use Neos\Flow\Http\ServerRequestAttributes;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\Routing\Dto\RouteParameters;
use Neos\Flow\Mvc\Routing\Exception\MissingActionNameException;
Expand Down Expand Up @@ -282,7 +281,11 @@ protected function createUriPathsAcrossDimensionsForNode(string $nodeIdentifier,
continue;
}

$nodeUriPath = $this->buildUriPathForNode($nodeInDimensions);
try {
$nodeUriPath = $this->buildUriPathForNode($nodeInDimensions);
} catch (\Exception $_) {
continue;
}
$nodeUriPath = $this->removeContextInformationFromRelativeNodeUri($nodeUriPath);
$result[] = [
$nodeUriPath,
Expand All @@ -303,14 +306,23 @@ protected function createUriPathsAcrossDimensionsForNode(string $nodeIdentifier,
*/
protected function hasNodeUriChanged(NodeInterface $node, Workspace $targetWorkspace): bool
{
$newUriPath = $this->buildUriPathForNode($node);
$newUriPath = $this->removeContextInformationFromRelativeNodeUri($newUriPath);

$nodeInTargetWorkspace = $this->getNodeInWorkspace($node, $targetWorkspace);
if (!$nodeInTargetWorkspace) {
return false;
}
$oldUriPath = $this->buildUriPathForNode($nodeInTargetWorkspace);
try {
$newUriPath = $this->buildUriPathForNode($node);
} catch (\Exception $exception) {
$this->logger->info(sprintf('Failed to build new URI for updated node "%s": %s', $node->getContextPath(), $exception->getMessage()));
return false;
}
$newUriPath = $this->removeContextInformationFromRelativeNodeUri($newUriPath);
try {
$oldUriPath = $this->buildUriPathForNode($nodeInTargetWorkspace);
} catch (\Exception $exception) {
$this->logger->info(sprintf('Failed to build previous URI for updated node "%s": %s', $node->getContextPath(), $exception->getMessage()));
return false;
}
$oldUriPath = $this->removeContextInformationFromRelativeNodeUri($oldUriPath);

return ($newUriPath !== $oldUriPath);
Expand Down Expand Up @@ -353,7 +365,12 @@ protected function createRedirectFrom(string $oldUri, string $nodeIdentifer, str
return false;
}

$newUri = $this->buildUriPathForNode($node);
try {
$newUri = $this->buildUriPathForNode($node);
} catch (\Exception $exception) {
$this->logger->info(sprintf('Redirect creation skipped since URL for node "%s" could not be created and led to an exception: %s', $node->getContextPath(), $exception->getMessage()));
return false;
}

if ($node->isRemoved()) {
return $this->removeNodeRedirectIfNeeded($node, $newUri);
Expand Down Expand Up @@ -551,7 +568,7 @@ protected function flushRoutingCacheForNode(NodeInterface $node): void
protected function buildUriPathForNode(NodeInterface $node): string
{
return $this->getUriBuilder()
->uriFor('show', ['node' => $node], 'Frontend\\Node', 'Neos.Neos');
->uriFor('show', ['node' => $node], 'Frontend\\Node', 'Neos.Neos');
}

/**
Expand Down

0 comments on commit a46d920

Please sign in to comment.