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: Adjust to use CatchUpHookFactoryDependencies #81

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Check failure on line 14 in Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php

View workflow job for this annotation

GitHub Actions / build (8.2)

PHPDoc tag @implements contains generic type Neos\ContentRepository\Core\Projection\CatchUpHookFactoryInterface<Neos\Neos\FrontendRouting\Projection\DocumentUriPathFinder> but interface Neos\ContentRepository\Core\Projection\CatchUpHookFactoryInterface is not generic.

Check failure on line 14 in Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php

View workflow job for this annotation

GitHub Actions / build (8.3)

PHPDoc tag @implements contains generic type Neos\ContentRepository\Core\Projection\CatchUpHookFactoryInterface<Neos\Neos\FrontendRouting\Projection\DocumentUriPathFinder> but interface Neos\ContentRepository\Core\Projection\CatchUpHookFactoryInterface is not generic.
{
public function __construct(
protected readonly NodeRedirectService $redirectService,
protected readonly ContentRepositoryRegistry $contentRepositoryRegistry,
) {
}

public function build(ContentRepository $contentRepository): CatchUpHookInterface
public function build(CatchUpHookFactoryDependencies $dependencies): CatchUpHookInterface

Check failure on line 21 in Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Parameter #1 $dependencies (Neos\ContentRepository\Core\Projection\CatchUpHookFactoryDependencies) of method Neos\RedirectHandler\NeosAdapter\CatchUpHook\DocumentUriPathProjectionHookFactory::build() is not contravariant with parameter #1 $contentRepository (Neos\ContentRepository\Core\ContentRepository) of method Neos\ContentRepository\Core\Projection\CatchUpHookFactoryInterface::build().

Check failure on line 21 in Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Parameter $dependencies of method Neos\RedirectHandler\NeosAdapter\CatchUpHook\DocumentUriPathProjectionHookFactory::build() has invalid type Neos\ContentRepository\Core\Projection\CatchUpHookFactoryDependencies.

Check failure on line 21 in Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Parameter #1 $dependencies (Neos\ContentRepository\Core\Projection\CatchUpHookFactoryDependencies) of method Neos\RedirectHandler\NeosAdapter\CatchUpHook\DocumentUriPathProjectionHookFactory::build() is not contravariant with parameter #1 $contentRepository (Neos\ContentRepository\Core\ContentRepository) of method Neos\ContentRepository\Core\Projection\CatchUpHookFactoryInterface::build().

Check failure on line 21 in Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Parameter $dependencies of method Neos\RedirectHandler\NeosAdapter\CatchUpHook\DocumentUriPathProjectionHookFactory::build() has invalid type Neos\ContentRepository\Core\Projection\CatchUpHookFactoryDependencies.
{
return new DocumentUriPathProjectionHook(
$contentRepository,
$dependencies->contentRepositoryId,

Check failure on line 24 in Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Access to property $contentRepositoryId on an unknown class Neos\ContentRepository\Core\Projection\CatchUpHookFactoryDependencies.

Check failure on line 24 in Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Access to property $contentRepositoryId on an unknown class Neos\ContentRepository\Core\Projection\CatchUpHookFactoryDependencies.
$dependencies->projectionState,

Check failure on line 25 in Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php

View workflow job for this annotation

GitHub Actions / build (8.2)

Access to property $projectionState on an unknown class Neos\ContentRepository\Core\Projection\CatchUpHookFactoryDependencies.

Check failure on line 25 in Classes/CatchUpHook/DocumentUriPathProjectionHookFactory.php

View workflow job for this annotation

GitHub Actions / build (8.3)

Access to property $projectionState on an unknown class Neos\ContentRepository\Core\Projection\CatchUpHookFactoryDependencies.
$this->redirectService
);
}
Expand Down
Loading