Skip to content

Commit

Permalink
BUGFIX: Create a 410 gone redirect for deleted nodes
Browse files Browse the repository at this point in the history
If a node cannot be read in the create redirect step it is considered to have been deleted and
the removeNodeRedirect method is triggered.

fixes: neos#31
  • Loading branch information
mficzel committed Jan 30, 2019
1 parent 4cbb121 commit 065c1ca
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions Classes/Service/NodeRedirectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,11 @@ protected function buildRedirects(string $nodeIdentifier, string $workspaceName,
protected function createRedirectFrom(string $oldUri, string $nodeIdentifer, string $workspaceName, array $dimensionCombination): bool
{
$node = $this->getNodeInWorkspaceAndDimensions($nodeIdentifer, $workspaceName, $dimensionCombination);

// the node is not accessible any more and thus is considered beeing removed
if ($node === null) {
return false;
$context = $this->getContextForWorkspaceAndDimensions($workspaceName, $dimensionCombination);
return $this->removeNodeRedirectIfNeeded($context, $oldUri);
}

if ($this->isRestrictedByNodeType($node) || $this->isRestrictedByPath($node)) {
Expand All @@ -258,10 +261,6 @@ protected function createRedirectFrom(string $oldUri, string $nodeIdentifer, str

$newUri = $this->buildUriPathForNode($node);

if ($node->isRemoved()) {
return $this->removeNodeRedirectIfNeeded($node, $newUri);
}

if ($oldUri === $newUri) {
return false;
}
Expand All @@ -278,20 +277,19 @@ protected function createRedirectFrom(string $oldUri, string $nodeIdentifer, str
/**
* Removes a redirect
*
* @param NodeInterface $node
* @param ContentContext $context
* @param string $newUri
* @return bool
*/
protected function removeNodeRedirectIfNeeded(NodeInterface $node, string $newUri): bool
protected function removeNodeRedirectIfNeeded(ContentContext $context, string $oldUri): bool
{
// By default the redirect handling for removed nodes is activated.
// If it is deactivated in your settings you will be able to handle the redirects on your own.
// For example redirect to dedicated landing pages for deleted campaign NodeTypes
if ($this->enableRemovedNodeRedirect) {
$hosts = $this->getHostnames($node->getContext());
$this->flushRoutingCacheForNode($node);
$hosts = $this->getHostnames($context);
$statusCode = (integer)$this->defaultStatusCode['gone'];
$this->redirectStorage->addRedirect($newUri, '', $statusCode, $hosts);
$this->redirectStorage->addRedirect($oldUri, '', $statusCode, $hosts);

return true;
}
Expand Down Expand Up @@ -464,12 +462,21 @@ protected function getNodeInWorkspace(NodeInterface $node, Workspace $targetWork
*/
protected function getNodeInWorkspaceAndDimensions(string $nodeIdentifier, string $workspaceName, array $dimensionCombination)
{
$context = $this->contextFactory->create([
$context = $this->getContextForWorkspaceAndDimensions($workspaceName, $dimensionCombination);
return $context->getNodeByIdentifier($nodeIdentifier);
}

/**
* @param string $workspaceName
* @param array $dimensionCombination
* @return ContentContext
*/
protected function getContextForWorkspaceAndDimensions(string $workspaceName, array $dimensionCombination): ContentContext
{
return $this->contextFactory->create([
'workspaceName' => $workspaceName,
'dimensions' => $dimensionCombination,
'invisibleContentShown' => true,
]);

return $context->getNodeByIdentifier($nodeIdentifier);
}
}

0 comments on commit 065c1ca

Please sign in to comment.