From dea2b2de7d0acef1f7d949d8683ebe58f5ed1af0 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Mon, 4 Nov 2024 09:51:09 +0100 Subject: [PATCH] TASK: Adjust to use `CatchUpHookFactoryDependencies` see https://github.com/neos/neos-development-collection/pull/5328 --- .../DocumentUriPathProjectionHook.php | 46 +++++++++---------- .../DocumentUriPathProjectionHookFactory.php | 13 ++++-- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/Classes/CatchUpHook/DocumentUriPathProjectionHook.php b/Classes/CatchUpHook/DocumentUriPathProjectionHook.php index dd97482..389962f 100644 --- a/Classes/CatchUpHook/DocumentUriPathProjectionHook.php +++ b/Classes/CatchUpHook/DocumentUriPathProjectionHook.php @@ -2,19 +2,19 @@ namespace Neos\RedirectHandler\NeosAdapter\CatchUpHook; -use Neos\ContentRepository\Core\Projection\CatchUpHookInterface; -use Neos\ContentRepository\Core\ContentRepository; use Neos\ContentRepository\Core\EventStore\EventInterface; -use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress; -use Neos\EventStore\Model\EventEnvelope; use Neos\ContentRepository\Core\Feature\NodeModification\Event\NodePropertiesWereSet; use Neos\ContentRepository\Core\Feature\NodeMove\Event\NodeAggregateWasMoved; use Neos\ContentRepository\Core\Feature\NodeRemoval\Event\NodeAggregateWasRemoved; -use Neos\RedirectHandler\NeosAdapter\Service\NodeRedirectService; -use Neos\Neos\FrontendRouting\Projection\DocumentUriPathFinder; -use Neos\Neos\FrontendRouting\Projection\DocumentNodeInfo; -use Neos\Neos\FrontendRouting\Exception\NodeNotFoundException; +use Neos\ContentRepository\Core\Projection\CatchUpHookInterface; +use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; +use Neos\EventStore\Model\EventEnvelope; +use Neos\Neos\FrontendRouting\Exception\NodeNotFoundException; +use Neos\Neos\FrontendRouting\Projection\DocumentNodeInfo; +use Neos\Neos\FrontendRouting\Projection\DocumentUriPathFinder; +use Neos\RedirectHandler\NeosAdapter\Service\NodeRedirectService; final class DocumentUriPathProjectionHook implements CatchUpHookInterface { @@ -25,7 +25,8 @@ final class DocumentUriPathProjectionHook implements CatchUpHookInterface private array $documentNodeInfosBeforeRemoval; public function __construct( - private readonly ContentRepository $contentRepository, + private readonly ContentRepositoryId $contentRepositoryId, + private readonly DocumentUriPathFinder $documentUriPathFinder, private readonly NodeRedirectService $nodeRedirectService, ) { } @@ -82,16 +83,16 @@ private function onBeforeNodeAggregateWasRemoved(NodeAggregateWasRemoved $event) $this->nodeRedirectService->appendAffectedNode( $node, - NodeAddress::create($this->contentRepository->id, $event->workspaceName, $dimensionSpacePoint, $node->getNodeAggregateId()) + NodeAddress::create($this->contentRepositoryId, $event->workspaceName, $dimensionSpacePoint, $node->getNodeAggregateId()) ); $this->documentNodeInfosBeforeRemoval[$dimensionSpacePoint->hash][] = $node; - $descendantsOfNode = $this->getState()->getDescendantsOfNode($node); + $descendantsOfNode = $this->documentUriPathFinder->getDescendantsOfNode($node); array_map( function ($descendantOfNode) use ($event, $dimensionSpacePoint) { $this->nodeRedirectService->appendAffectedNode( $descendantOfNode, - NodeAddress::create($this->contentRepository->id, $event->workspaceName, $dimensionSpacePoint, $descendantOfNode->getNodeAggregateId()) + NodeAddress::create($this->contentRepositoryId, $event->workspaceName, $dimensionSpacePoint, $descendantOfNode->getNodeAggregateId()) ); $this->documentNodeInfosBeforeRemoval[$dimensionSpacePoint->hash][] = $descendantOfNode; }, @@ -116,7 +117,7 @@ private function onAfterNodeAggregateWasRemoved(NodeAggregateWasRemoved $event): array_map( fn (DocumentNodeInfo $node) => $this->nodeRedirectService->createRedirectForRemovedAffectedNode( $node, - $this->contentRepository->id + $this->contentRepositoryId ), $documentNodeInfosBeforeRemoval ); @@ -160,12 +161,12 @@ private function handleNodePropertiesWereSet(NodePropertiesWereSet $event, \Clos continue; } - $closure($node, NodeAddress::create($this->contentRepository->id, $event->workspaceName, $affectedDimensionSpacePoint, $node->getNodeAggregateId())); + $closure($node, NodeAddress::create($this->contentRepositoryId, $event->workspaceName, $affectedDimensionSpacePoint, $node->getNodeAggregateId())); - $descendantsOfNode = $this->getState()->getDescendantsOfNode($node); + $descendantsOfNode = $this->documentUriPathFinder->getDescendantsOfNode($node); array_map(fn (DocumentNodeInfo $descendantOfNode) => $closure( $descendantOfNode, - NodeAddress::create($this->contentRepository->id, $event->workspaceName, $affectedDimensionSpacePoint, $descendantOfNode->getNodeAggregateId()) + NodeAddress::create($this->contentRepositoryId, $event->workspaceName, $affectedDimensionSpacePoint, $descendantOfNode->getNodeAggregateId()) ), iterator_to_array($descendantsOfNode)); } } @@ -206,25 +207,20 @@ private function handleNodeWasMoved(NodeAggregateWasMoved $event, \Closure $clos continue; } - $closure($node, NodeAddress::create($this->contentRepository->id, $event->workspaceName, $interdimensionalSibling->dimensionSpacePoint, $node->getNodeAggregateId())); + $closure($node, NodeAddress::create($this->contentRepositoryId, $event->workspaceName, $interdimensionalSibling->dimensionSpacePoint, $node->getNodeAggregateId())); - $descendantsOfNode = $this->getState()->getDescendantsOfNode($node); + $descendantsOfNode = $this->documentUriPathFinder->getDescendantsOfNode($node); array_map(fn (DocumentNodeInfo $descendantOfNode) => $closure( $descendantOfNode, - NodeAddress::create($this->contentRepository->id, $event->workspaceName, $interdimensionalSibling->dimensionSpacePoint, $descendantOfNode->getNodeAggregateId()) + NodeAddress::create($this->contentRepositoryId, $event->workspaceName, $interdimensionalSibling->dimensionSpacePoint, $descendantOfNode->getNodeAggregateId()) ), iterator_to_array($descendantsOfNode)); } } - private function getState(): DocumentUriPathFinder - { - return $this->contentRepository->projectionState(DocumentUriPathFinder::class); - } - private function findNodeByIdAndDimensionSpacePointHash(NodeAggregateId $nodeAggregateId, string $dimensionSpacePointHash): ?DocumentNodeInfo { try { - return $this->getState()->getByIdAndDimensionSpacePointHash($nodeAggregateId, $dimensionSpacePointHash); + return $this->documentUriPathFinder->getByIdAndDimensionSpacePointHash($nodeAggregateId, $dimensionSpacePointHash); } catch (NodeNotFoundException $_) { return null; } diff --git a/Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php b/Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php index 2d3e3bc..0a032ef 100644 --- a/Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php +++ b/Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php @@ -2,24 +2,27 @@ namespace Neos\RedirectHandler\NeosAdapter\CatchUpHook; +use Neos\ContentRepository\Core\Projection\CatchUpHookFactoryDependencies; use Neos\ContentRepository\Core\Projection\CatchUpHookFactoryInterface; -use Neos\ContentRepository\Core\ContentRepository; use Neos\ContentRepository\Core\Projection\CatchUpHookInterface; +use Neos\Neos\FrontendRouting\Projection\DocumentUriPathFinder; use Neos\RedirectHandler\NeosAdapter\Service\NodeRedirectService; -use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; +/** + * @implements CatchUpHookFactoryInterface + */ final class DocumentUriPathProjectionHookFactory implements CatchUpHookFactoryInterface { public function __construct( protected readonly NodeRedirectService $redirectService, - protected readonly ContentRepositoryRegistry $contentRepositoryRegistry, ) { } - public function build(ContentRepository $contentRepository): CatchUpHookInterface + public function build(CatchUpHookFactoryDependencies $dependencies): CatchUpHookInterface { return new DocumentUriPathProjectionHook( - $contentRepository, + $dependencies->contentRepositoryId, + $dependencies->projectionState, $this->redirectService ); }