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: Handle nodes with missing UriPathSegments in uriPathProjection #5412

Open
wants to merge 3 commits into
base: 9.0
Choose a base branch
from

Conversation

mficzel
Copy link
Member

@mficzel mficzel commented Dec 22, 2024

Use nodeAggregateId as fallback for missing uriPathSegments in uriPathProjection.

This is necessary as the fallback to "" can create empty pathes for documents without uriPathSegment which is later on confused with root urls of the site. Falling back to the nodeAggregate id which is by definition unique and url-safe ensures that all documents get a valid url by the projection that can be adjusted later.

Empty uriPathSegments are usually avoided by validation and autocreation from the title but those mechanisms do not work for tethered nodes. This is even more problematic as this cannot be fixed later since the full uriPath is only created oCreate and laster on only the last segment of the path is adjusted without ever reevaluating the parentPath.

In addition this pr adds a nodeName to the site node in multiple test cases as this is actually required and only worked in the past because the empty uriPathSegment behaved like a site node.

Resolves: #5413

Upgrade instructions

Review instructions

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

mficzel added a commit to mficzel/neos-development-collection that referenced this pull request Dec 22, 2024
Since "" is treated as the uriPath for a site node this causes confusion if it is projected for a document in cases where one was created without an uriPathSegment which may happen for tethered nodes.

Resolves: neos#5412
@mficzel mficzel force-pushed the bugfix/resilienceAgainstMissingUriPathSegments branch from 43fdcb5 to 107b282 Compare December 22, 2024 11:43
…gments

The testcase verifies that the nodeAggregateId is used as fallback in case no uriPathSegment
was set and that this can be overwritten afterwards of a proper uriPathSegment is set later.

Relates: neos#5413
mficzel added a commit to mficzel/neos-development-collection that referenced this pull request Dec 22, 2024
Since "" is treated as the uriPath for a site node this causes confusion if it is projected for a document in cases where one was created without an uriPathSegment which may happen for tethered nodes.

Resolves: neos#5412
@mficzel mficzel force-pushed the bugfix/resilienceAgainstMissingUriPathSegments branch from 107b282 to dd3ff9d Compare December 22, 2024 11:56
@mficzel mficzel changed the title BUGFIX: Handle nodes with missing UriPathSrents in uri projection BUGFIX: Handle nodes with missing UriPathSegments in uri PathProjection Dec 22, 2024
@mficzel mficzel changed the title BUGFIX: Handle nodes with missing UriPathSegments in uri PathProjection BUGFIX: Handle nodes with missing UriPathSegments in uriPathProjection Dec 22, 2024
@mficzel mficzel force-pushed the bugfix/resilienceAgainstMissingUriPathSegments branch 5 times, most recently from a16aeb8 to d81eb9f Compare December 22, 2024 14:06
@mficzel
Copy link
Member Author

mficzel commented Dec 22, 2024

I wonder wether the site node detection that is currently done in handCreateNodeAggregateWith is wise because a
site node is basically defined as a named node that is directly below a rootNode.

@mficzel mficzel force-pushed the bugfix/resilienceAgainstMissingUriPathSegments branch 2 times, most recently from 9abce68 to d9772d3 Compare December 22, 2024 15:09
@mficzel mficzel marked this pull request as ready for review December 22, 2024 15:19
Since "" is treated as the uriPath for a site node this causes confusion if it is projected for a document in cases where one was created without an uriPathSegment which may happen for tethered nodes.

Resolves: neos#5412
…vior

The projection detects site nodes that should have an empty path by verifying that the parent is a root node and they have a nodeName.
@mficzel mficzel force-pushed the bugfix/resilienceAgainstMissingUriPathSegments branch from d9772d3 to 64d52a7 Compare December 22, 2024 15:25
Copy link
Member

@bwaidelich bwaidelich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand, why some seemingly unrelated tests needed adjustments, but the change itself makes sense to me, thanks!

@mficzel
Copy link
Member Author

mficzel commented Dec 22, 2024

The definition of site node (with path „“) used in the uriPathProjection is that it is a child of a rootNode and has a nodeName.

The adjusted tests only worked in the past because an empty uriPathSegment was treated implicitly like a site node. Since we now have fallback for empty uriPathSegments the tests that relied on that now need a proper site Node.

@mficzel mficzel requested a review from nezaniel December 22, 2024 16:19
@@ -209,7 +209,7 @@ private function whenNodeAggregateWithNodeWasCreated(NodeAggregateWithNodeWasCre
}

$propertyValues = $event->initialPropertyValues->getPlainValues();
$uriPathSegment = $propertyValues['uriPathSegment'] ?? '';
$uriPathSegment = $propertyValues['uriPathSegment'] ?? $event->nodeAggregateId->value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we discussed an alternative in line 273 but it doesnt really work :D

                $uriPath = $this->nodeTypeManager->getNodeType($parentNode->getNodeTypeName())?->isOfType(NodeTypeNameFactory::NAME_SITE)
                    ? $uriPathSegment
                    : $parentNode->getUriPath() . '/' . $uriPathSegment;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still think resilience against missing uri path segments is better than adding an even tighter bond to the Neos NodeTypes. Even if this would work ;-)

The fallback way makes uriPathes more like a soft concern (which it is technically anyways) and allows routing of documents in cases where it is missing for any reason.

Only thing that would speak against that would be a case where the node-identifier based fallback does harm anything but i do not see a way for this to happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: UriPathProjection cannot recover from missing UriPathSegments in nested+tethered documentNodes
3 participants