Skip to content

Commit

Permalink
TASK: neos#4732 serialized node fully qualified for fusion uncached mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Feb 3, 2024
1 parent d45e946 commit dbed114
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 98 deletions.
93 changes: 0 additions & 93 deletions Neos.Neos/Classes/Fusion/NewNodeConverter.php

This file was deleted.

96 changes: 96 additions & 0 deletions Neos.Neos/Classes/TypeConverter/JsonStringToNodeConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

namespace Neos\Neos\TypeConverter;

/*
* This file is part of the Neos.ContentRepository package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\Factory\ContentRepositoryId;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Property\PropertyMappingConfigurationInterface;
use Neos\Flow\Property\TypeConverter\AbstractTypeConverter;

/**
* !!! Only needed for uncached Fusion segments; as in Fusion ContentCache, the PropertyMapper is used to serialize
* and deserialize the context. {@see ContentCache::serializeContext()}
*
* Serialized implementation {@see NodeToJsonStringSerializer}
*
* @Flow\Scope("singleton")
* @deprecated
*/
class JsonStringToNodeConverter extends AbstractTypeConverter
{
/**
* @var array<int,string>
*/
protected $sourceTypes = ['string'];

/**
* @var string
*/
protected $targetType = Node::class;

/**
* @var integer
*/
protected $priority = 2;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

/**
* @param string $source
* @param string $targetType
* @param array<string,string> $subProperties
* @return Node|null|\Neos\Error\Messages\Error
*/
public function convertFrom(
$source,
$targetType = null,
array $subProperties = [],
PropertyMappingConfigurationInterface $configuration = null
) {
assert(is_string($source));

try {
$serializedNode = json_decode($source, true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
return new \Neos\Error\Messages\Error(sprintf('Cannot convert assumed json string %s to node. %s', $source, $e->getMessage()));
}

$contentRepositoryId = ContentRepositoryId::fromString($serializedNode['contentRepositoryId']);

$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);

$workspace = $contentRepository->getWorkspaceFinder()->findOneByName(WorkspaceName::fromString($serializedNode['workspaceName']));
if (!$workspace) {
return new \Neos\Error\Messages\Error('Could not find workspace while trying to convert node from json string %s.', 1699782153, [$source]);
}

$subgraph = $contentRepository->getContentGraph()->getSubgraph(
$workspace->currentContentStreamId,
DimensionSpacePoint::fromArray($serializedNode['dimensionSpacePoint']),
$workspace->isPublicWorkspace()
? VisibilityConstraints::frontend()
: VisibilityConstraints::withoutRestrictions()
);

return $subgraph->findNodeById(NodeAggregateId::fromString($serializedNode['nodeAggregateId']));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

namespace Neos\Neos\TypeConverter;

use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
Expand All @@ -24,13 +23,14 @@

/**
* !!! Only needed for uncached Fusion segments; as in Fusion ContentCache, the PropertyMapper is used to serialize
* and deserialize the context.
* {@see ContentCache::serializeContext()}
* and deserialize the context. {@see ContentCache::serializeContext()}
*
* Converter implementation {@see JsonStringToNodeConverter}
*
* @Flow\Scope("singleton")
* @deprecated
*/
class NodeConverter extends AbstractTypeConverter
class NodeToJsonStringSerializer extends AbstractTypeConverter
{
/**
* @Flow\Inject
Expand Down Expand Up @@ -65,9 +65,23 @@ public function convertFrom(
array $subProperties = [],
PropertyMappingConfigurationInterface $configuration = null
) {
assert($source instanceof Node);

$contentRepository = $this->contentRepositoryRegistry->get(
$source->subgraphIdentity->contentRepositoryId
);
return NodeAddressFactory::create($contentRepository)->createFromNode($source)->serializeForUri();

$workspace = $contentRepository->getWorkspaceFinder()->findOneByCurrentContentStreamId($source->subgraphIdentity->contentStreamId);

if (!$workspace) {
return new \Neos\Error\Messages\Error('Could not fetch workspace for node (%s) in content stream (%s).', 1699780153, [$source->nodeAggregateId->value, $source->subgraphIdentity->contentStreamId->value]);
}

return json_encode([
'contentRepositoryId' => $source->subgraphIdentity->contentRepositoryId->value,
'workspaceName' => $workspace->workspaceName->value,
'dimensionSpacePoint' => $source->subgraphIdentity->dimensionSpacePoint->jsonSerialize(),
'nodeAggregateId' => $source->nodeAggregateId->value
], JSON_THROW_ON_ERROR);
}
}

0 comments on commit dbed114

Please sign in to comment.