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

!!! TASK: Refactor Node property mapper to use new NodeAddress #5068

Merged
merged 5 commits into from
Jul 1, 2024

Conversation

mhsdesign
Copy link
Member

@mhsdesign mhsdesign commented May 18, 2024

Solves: #4873

This is an intermediate step after !!! FEATURE: Overhaul node uri building before we fully move to the new node address serialisation in the Neos Ui.
Everything was refactored here that does not require adjustments in the Neos Ui (and the workspace module was also not really touched).

  • avoid using the legacy node address instance in the code. The NodeAddressFactory is only used at the places where we still depend on the legacy format, but we create already new node address instances via createCoreNodeAddressFromLegacyUriString
  • removed the $contentStreamId field from the legacy NodeAddress already (as we can otherwise not transform a new node address to this one). Also this prevents the $contentStreamId field from accidentally being used again in the migration time.
  • removed the the unused legacy node address isInLiveWorkspace method.
  • The currently unused method Neos.Node.serializedNodeAddress(node) will return the new node address format
  • where previously Node $node was used to trigger property mapping (DataSourceController and WorkspaceController) we now pass the node as string and use the legacy node address factory to handle the legacy format manually. A followup will adjust everything to work with the new node address.
  • the unused linkinservice will use the new node address string format if a string is passed as $node
  • the Node property mappers were adjusted to use the new node address and not depend on the global active request handler
  • lint Neos.Workspace.Ui/Classes with phpstan

Upgrade instructions

This change is breaking for existing Neos 9 users as the node being property mapped will require a new serialised input.

public function someAction(Node $node): {}

In Neos 8.3 you could call this action with the node like

?node=/sites/neosdemo/features/multiple-columns@user-admin;language=en_US

in Neos9-dev it was

?node=user-admin__eyJsYW5ndWFnZSI6ImVuX1VTIn0%3D__995c9174-ddd6-4d5c-cfc0-1ffc82184677

and now it must be the node address in json NodeAddress::toJson()

?node=%7B%22contentRepositoryId%22%3A%22default%22%2C%22workspaceName%22%3A%22live%22%2C%22dimensionSpacePoint%22%3A%7B%22language%22%3A%22es%22%2C%22country%22%3A%22ar%22%7D%2C%22aggregateId%22%3A%22node-1%22%7D

to build such a uri you can simply use:

$myActionUri = new Uri($this->uriBuilder->uriFor(...));
$myActionUriWithNode = UriHelper::uriWithAdditionalQueryParameters(
    $myActionUri,
    ['node' => NodeAddress::fromNode($node)->toJson()]
);

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

@github-actions github-actions bot added the 9.0 label May 18, 2024
@mhsdesign mhsdesign force-pushed the task/nodeAddressFlowPropertyMapper branch 2 times, most recently from 2053ce7 to 106cde2 Compare June 16, 2024 09:03
@mhsdesign mhsdesign force-pushed the task/nodeAddressFlowPropertyMapper branch from 106cde2 to 931304f Compare June 16, 2024 09:25
@mhsdesign mhsdesign changed the title !!! TASK: Provide pure NodeAddress property converter !!! TASK: Refactor Node property mapper to use new NodeAddress Jun 16, 2024
@mhsdesign mhsdesign closed this Jun 23, 2024
@mhsdesign mhsdesign reopened this Jun 23, 2024
@mhsdesign mhsdesign marked this pull request as ready for review June 23, 2024 20:12
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 just left some comments on first flyover, but I don't understand all the implications yet

@@ -150,14 +150,15 @@ public function uploadAssetAction(Asset $asset, string $metadata, string $node,
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())
->contentRepositoryId;
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
$nodeAddress = NodeAddressFactory::create($contentRepository)->createFromUriString($nodeAddressString);
// todo legacy uri node address notation used. Should be refactored to use json encoded NodeAddress
Copy link
Member

Choose a reason for hiding this comment

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

The TODO is related to line 149, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

jip a followup will change the whole neos ui and neos.neos to work on the new format we agreed upon.

* in contentStreamId $contentStreamId
*
* It is used in Neos Routing to build a URI to a node.
*
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove those?

Copy link
Member Author

Choose a reason for hiding this comment

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

because its just @deprecated and will be removed soon.
The statements are not true anymore: It is used in Neos Routing to build a URI to a node.

Copy link
Member

Choose a reason for hiding this comment

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

Right, thanks for clarifying, I briefly confused the two NodeAddresses.. Good that we are getting rid of one :)

@@ -42,8 +32,9 @@
/**
* @internal use NodeAddressFactory, if you want to create a NodeAddress
*/
/** @phpstan-ignore-next-line its all just temporary */
Copy link
Member

Choose a reason for hiding this comment

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

Could you elaborate the comment a bit? Why do we need it?

Copy link
Member Author

Choose a reason for hiding this comment

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

i dindt want to remove the param yet as it would break the neos ui now (we construct it over there) this is just intermediate

public function __construct(
public ContentStreamId $contentStreamId,
?ContentStreamId $_contentStreamId,
Copy link
Member

Choose a reason for hiding this comment

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

I assume, you just kept this to keep the PR smaller? But is it necessary to rename the parameter?

Copy link
Member Author

Choose a reason for hiding this comment

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

its just a dummy stub, and _ indicates its unused. the class will be obliterated into nothing.

public function __toString(): string
{
return sprintf(
'NodeAddress[contentStream=%s, dimensionSpacePoint=%s, nodeAggregateId=%s, workspaceName=%s]',
$this->contentStreamId->value,
'NodeAddress[dimensionSpacePoint=%s, nodeAggregateId=%s, workspaceName=%s]',
Copy link
Member

Choose a reason for hiding this comment

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

I hope that we don' relay on this string representation (=> do we really need it, what about using __debugInfo() instead?) – and if we keep it: Why did you decide to move the workspace name to the end?

Copy link
Member Author

Choose a reason for hiding this comment

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

we probably dont even need the __toString anymore at this time ... but i kept it ... it will all go away. Its legacy.

* @throws NeosException
*/
public function indexAction($dataSourceIdentifier, Node $node = null): void
public function indexAction($dataSourceIdentifier, string $node = null): void
Copy link
Member

Choose a reason for hiding this comment

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

you removed the param annotation – I would instead suggest to keep it and add some docs instead – what is this $node string expected to contain?

Copy link
Member Author

Choose a reason for hiding this comment

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

as per my main description:

where previously Node $node was used to trigger property mapping (DataSourceController and WorkspaceController) we now pass the node as string and use the legacy node address factory to handle the legacy format manually. A followup will adjust everything to work with the new node address.

Copy link
Member

Choose a reason for hiding this comment

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

OK, sorry, missed that one!


$this->view->assign('value', $values);
}

private function deserializeNodeFromLegacyAddress(?string $stringFormattedNodeAddress): ?Node
{
if (!$stringFormattedNodeAddress) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (!$stringFormattedNodeAddress) {
if ($stringFormattedNodeAddress === null) {

Copy link
Member Author

@mhsdesign mhsdesign left a comment

Choose a reason for hiding this comment

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

regarding the why of this change, i tried to put it into words in my main description above but i would also be happy to elaborate on that or have a quick huddle.

@@ -150,14 +150,15 @@ public function uploadAssetAction(Asset $asset, string $metadata, string $node,
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())
->contentRepositoryId;
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
$nodeAddress = NodeAddressFactory::create($contentRepository)->createFromUriString($nodeAddressString);
// todo legacy uri node address notation used. Should be refactored to use json encoded NodeAddress
Copy link
Member Author

Choose a reason for hiding this comment

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

jip a followup will change the whole neos ui and neos.neos to work on the new format we agreed upon.

* in contentStreamId $contentStreamId
*
* It is used in Neos Routing to build a URI to a node.
*
Copy link
Member Author

Choose a reason for hiding this comment

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

because its just @deprecated and will be removed soon.
The statements are not true anymore: It is used in Neos Routing to build a URI to a node.

@@ -42,8 +32,9 @@
/**
* @internal use NodeAddressFactory, if you want to create a NodeAddress
*/
/** @phpstan-ignore-next-line its all just temporary */
Copy link
Member Author

Choose a reason for hiding this comment

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

i dindt want to remove the param yet as it would break the neos ui now (we construct it over there) this is just intermediate

public function __construct(
public ContentStreamId $contentStreamId,
?ContentStreamId $_contentStreamId,
Copy link
Member Author

Choose a reason for hiding this comment

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

its just a dummy stub, and _ indicates its unused. the class will be obliterated into nothing.

public function __toString(): string
{
return sprintf(
'NodeAddress[contentStream=%s, dimensionSpacePoint=%s, nodeAggregateId=%s, workspaceName=%s]',
$this->contentStreamId->value,
'NodeAddress[dimensionSpacePoint=%s, nodeAggregateId=%s, workspaceName=%s]',
Copy link
Member Author

Choose a reason for hiding this comment

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

we probably dont even need the __toString anymore at this time ... but i kept it ... it will all go away. Its legacy.

* @throws NeosException
*/
public function indexAction($dataSourceIdentifier, Node $node = null): void
public function indexAction($dataSourceIdentifier, string $node = null): void
Copy link
Member Author

Choose a reason for hiding this comment

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

as per my main description:

where previously Node $node was used to trigger property mapping (DataSourceController and WorkspaceController) we now pass the node as string and use the legacy node address factory to handle the legacy format manually. A followup will adjust everything to work with the new node address.

Copy link
Member

@kitsunet kitsunet left a comment

Choose a reason for hiding this comment

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

There is one little code suggestion from bwaidelich I would think should be merged, the rest seems fine to me.

@mhsdesign
Copy link
Member Author

Okay in that case id merge it ;)

@mhsdesign mhsdesign merged commit 9b79f68 into neos:9.0 Jul 1, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants