Skip to content

Commit

Permalink
Make ContentGraphAdapterFactory configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsunet committed Apr 5, 2024
1 parent 8e3fd57 commit d0f89bd
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 15 deletions.
@@ -1,5 +1,5 @@
<?php
namespace Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository;
namespace Neos\ContentGraph\DoctrineDbalAdapter;

use Doctrine\DBAL\Connection;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
Expand All @@ -9,10 +9,14 @@
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
use Neos\ContentRepository\Core\Projection\ContentGraph\Nodes;
use Neos\ContentRepository\Core\Projection\Workspace\Workspace;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamState;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\EventStore\Model\EventStream\MaybeVersion;

/**
*
Expand Down Expand Up @@ -86,7 +90,7 @@ public function findChildNodeByNameInSubgraph(ContentStreamId $contentStreamId,
// TODO: Implement findChildNodeByNameInSubgraph() method.
}

public function findPreceedingSiblingNodesInSubgraph(ContentStreamId $contentStreamId, WorkspaceName $workspaceName, DimensionSpacePoint $coveredDimensionSpacePoint, NodeAggregateId $startingSiblingNodeAggregateId): Nodes
public function findPreceedingSiblingNodesInSubgraph(ContentStreamId $contentStreamId, WorkspaceName $workspaceName, DimensionSpacePoint $coveredDimensionSpacePoint, NodeAggregateId $startingSiblingNodeAggregateId): Nodesy
{
// TODO: Implement findPreceedingSiblingNodesInSubgraph() method.
}
Expand Down Expand Up @@ -120,4 +124,21 @@ public function findWorkspaceByCurrentContentStreamId(ContentStreamId $contentSt
{
// TODO: Implement findWorkspaceByCurrentContentStreamId() method.
}

private function getTablenameForNode(): string
{
return $this->tableNamePrefix . '_node';
}

private function getTablenameForHierachyRelation(): string
{
return $this->tableNamePrefix . '_hierarchyrelation';
}

private function getTablenameForDimensionSpacePoints(): string
{
return $this->tableNamePrefix . '_dimensionspacepoints';
}


}
@@ -1,8 +1,7 @@
<?php
namespace Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository;
namespace Neos\ContentGraph\DoctrineDbalAdapter;

use Doctrine\DBAL\Connection;
use Neos\ContentGraph\DoctrineDbalAdapter\DoctrineDbalContentGraphProjectionFactory;
use Neos\ContentRepository\Core\Feature\ContentGraphAdapterFactoryInterface;
use Neos\ContentRepository\Core\Feature\ContentGraphAdapterInterface;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
Expand All @@ -17,7 +16,7 @@ public function __construct(
) {
}

public function build(ContentRepositoryId $contentRepositoryId): ContentGraphAdapterInterface
public function build(ContentRepositoryId $contentRepositoryId, array $options): ContentGraphAdapterInterface
{
$tableNamePrefix = DoctrineDbalContentGraphProjectionFactory::graphProjectionTableNamePrefix(
$contentRepositoryId
Expand Down
Expand Up @@ -21,7 +21,7 @@
use Neos\ContentRepository\Core\DimensionSpace\InterDimensionalVariationGraph;
use Neos\ContentRepository\Core\EventStore\EventNormalizer;
use Neos\ContentRepository\Core\EventStore\EventPersister;
use Neos\ContentRepository\Core\Feature\ContentGraphAdapterFactoryInterface;
use Neos\ContentRepository\Core\Feature\ContentGraphAdapterInterface;
use Neos\ContentRepository\Core\Feature\ContentStreamCommandHandler;
use Neos\ContentRepository\Core\Feature\DimensionSpaceAdjustment\DimensionSpaceCommandHandler;
use Neos\ContentRepository\Core\Feature\NodeAggregateCommandHandler;
Expand Down Expand Up @@ -57,7 +57,7 @@ public function __construct(
private readonly ProjectionCatchUpTriggerInterface $projectionCatchUpTrigger,
private readonly UserIdProviderInterface $userIdProvider,
private readonly ClockInterface $clock,
private readonly ContentGraphAdapterFactoryInterface $contentGraphAdapterFactory,
private readonly ContentGraphAdapterInterface $contentGraphAdapter,
) {
$contentDimensionZookeeper = new ContentDimensionZookeeper($contentDimensionSource);
$interDimensionalVariationGraph = new InterDimensionalVariationGraph(
Expand Down Expand Up @@ -134,27 +134,27 @@ public function buildService(
private function buildCommandBus(): CommandBus
{
if (!$this->commandBus) {
$contentGraphAdapter = $this->contentGraphAdapterFactory->build($this->projectionFactoryDependencies->contentRepositoryId);
$this->commandBus = new CommandBus(
new ContentStreamCommandHandler(
$contentGraphAdapter
$this->contentGraphAdapter
),
new WorkspaceCommandHandler(
$this->buildEventPersister(),
$this->projectionFactoryDependencies->eventStore,
$this->projectionFactoryDependencies->eventNormalizer,
$contentGraphAdapter
$this->contentGraphAdapter
),
new NodeAggregateCommandHandler(
$this->projectionFactoryDependencies->nodeTypeManager,
$this->projectionFactoryDependencies->contentDimensionZookeeper,
$this->projectionFactoryDependencies->interDimensionalVariationGraph,
$this->projectionFactoryDependencies->propertyConverter,
$contentGraphAdapter
$this->contentGraphAdapter
),
new DimensionSpaceCommandHandler(
$this->projectionFactoryDependencies->contentDimensionZookeeper,
$this->projectionFactoryDependencies->interDimensionalVariationGraph
$this->projectionFactoryDependencies->interDimensionalVariationGraph,
$this->contentGraphAdapter
),
new NodeDuplicationCommandHandler(
$this->projectionFactoryDependencies->nodeTypeManager,
Expand Down
Expand Up @@ -14,8 +14,6 @@

namespace Neos\ContentRepository\Core\Feature\Common;

use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ContentGraphAdapter;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\Feature\ContentGraphAdapterInterface;
use Neos\ContentRepository\Core\Feature\WorkspaceCommandHandler;
use Neos\ContentRepository\Core\SharedModel\Exception\ContentStreamDoesNotExistYet;
Expand Down
Expand Up @@ -11,5 +11,10 @@
*/
interface ContentGraphAdapterFactoryInterface
{
public function build(ContentRepositoryId $contentRepositoryId): ContentGraphAdapterInterface;
/**
* @param ContentRepositoryId $contentRepositoryId
* @param array<mixed, mixed> $options
* @return ContentGraphAdapterInterface
*/
public function build(ContentRepositoryId $contentRepositoryId, array $options): ContentGraphAdapterInterface;
}
Expand Up @@ -7,3 +7,5 @@ Neos:
# catchUpHooks for content cache flushing
'Neos.ContentRepository:ContentGraph':
factoryObjectName: Neos\ContentGraph\DoctrineDbalAdapter\DoctrineDbalContentGraphProjectionFactory
contentGraphAdapter:
factoryObjectName: Neos\ContentGraph\DoctrineDbalAdapter\DoctrineDbalContentGraphAdapterFactory
Expand Up @@ -9,6 +9,8 @@
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryInterface;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceInterface;
use Neos\ContentRepository\Core\Factory\ProjectionsAndCatchUpHooksFactory;
use Neos\ContentRepository\Core\Feature\ContentGraphAdapterFactoryInterface;
use Neos\ContentRepository\Core\Feature\ContentGraphAdapterInterface;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\Projection\CatchUpHookFactoryInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentSubgraphInterface;
Expand Down Expand Up @@ -158,6 +160,7 @@ private function buildFactory(ContentRepositoryId $contentRepositoryId): Content
$this->buildProjectionCatchUpTrigger($contentRepositoryId, $contentRepositorySettings),
$this->buildUserIdProvider($contentRepositoryId, $contentRepositorySettings),
$clock,
$this->buildContentGraphAdapter($contentRepositoryId, $contentRepositorySettings),
);
} catch (\Exception $exception) {
throw InvalidConfigurationException::fromException($contentRepositoryId, $exception);
Expand Down Expand Up @@ -281,4 +284,16 @@ private function buildClock(ContentRepositoryId $contentRepositoryIdentifier, ar
}
return $clockFactory->build($contentRepositoryIdentifier, $contentRepositorySettings['clock']['options'] ?? []);
}

/** @param array<string, mixed> $contentRepositorySettings */
private function buildContentGraphAdapter(ContentRepositoryId $contentRepositoryIdentifier, array $contentRepositorySettings): ContentGraphAdapterInterface
{
isset($contentRepositorySettings['contentGraphAdapter']['factoryObjectName']) || throw InvalidConfigurationException::fromMessage('Content repository "%s" does not have contentGraphAdapter.factoryObjectName configured.', $contentRepositoryIdentifier->value);
$contentGraphAdapterFactory = $this->objectManager->get($contentRepositorySettings['contentGraphAdapter']['factoryObjectName']);
if (!$contentGraphAdapterFactory instanceof ContentGraphAdapterFactoryInterface) {
throw InvalidConfigurationException::fromMessage('contentGraphAdapter.factoryObjectName for content repository "%s" is not an instance of %s but %s.', $contentRepositoryIdentifier->value, ContentGraphAdapterFactoryInterface::class, get_debug_type($contentGraphAdapterFactory));
}

return $contentGraphAdapterFactory->build($contentRepositoryIdentifier, $contentRepositorySettings['contentGraphAdapter']['options'] ?? []);
}
}

0 comments on commit d0f89bd

Please sign in to comment.