Skip to content

Commit

Permalink
Merge pull request #81 from neos/task/adjust-to-CatchUpHookFactoryDep…
Browse files Browse the repository at this point in the history
…endencies

TASK: Adjust to use `CatchUpHookFactoryDependencies`
  • Loading branch information
mhsdesign authored Nov 4, 2024
2 parents cf8230b + dea2b2d commit 4d5f514
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
46 changes: 21 additions & 25 deletions Classes/CatchUpHook/DocumentUriPathProjectionHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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,
) {
}
Expand Down Expand Up @@ -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;
},
Expand All @@ -116,7 +117,7 @@ private function onAfterNodeAggregateWasRemoved(NodeAggregateWasRemoved $event):
array_map(
fn (DocumentNodeInfo $node) => $this->nodeRedirectService->createRedirectForRemovedAffectedNode(
$node,
$this->contentRepository->id
$this->contentRepositoryId
),
$documentNodeInfosBeforeRemoval
);
Expand Down Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 8 additions & 5 deletions Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<DocumentUriPathFinder>
*/
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
);
}
Expand Down

0 comments on commit 4d5f514

Please sign in to comment.