Skip to content

Commit

Permalink
Merge pull request #5071 from neos/task/remove-dbal-client
Browse files Browse the repository at this point in the history
TASK: Remove DbalClient abstraction
  • Loading branch information
bwaidelich committed May 19, 2024
2 parents bb3aa5c + 4d81a81 commit 22acc13
Show file tree
Hide file tree
Showing 40 changed files with 254 additions and 597 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Neos\ContentGraph\DoctrineDbalAdapter\Tests\Behavior\Features\Bootstrap;

use Behat\Gherkin\Node\TableNode;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Neos\ContentGraph\DoctrineDbalAdapter\ContentGraphTableNames;
Expand All @@ -27,7 +28,6 @@
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\CRTestSuiteRuntimeVariables;
use Neos\ContentRepositoryRegistry\DoctrineDbalClient\DoctrineDbalClient;
use Neos\Error\Messages\Error;
use Neos\Error\Messages\Result;
use PHPUnit\Framework\Assert;
Expand All @@ -41,7 +41,7 @@ trait ProjectionIntegrityViolationDetectionTrait
{
use CRTestSuiteRuntimeVariables;

private DoctrineDbalClient $dbalClient;
private Connection $dbal;

protected Result $lastIntegrityViolationDetectionResult;

Expand All @@ -62,7 +62,7 @@ private function tableNames(): ContentGraphTableNames

public function setupDbalGraphAdapterIntegrityViolationTrait()
{
$this->dbalClient = $this->getObject(DoctrineDbalClient::class);
$this->dbal = $this->getObject(Connection::class);
}

/**
Expand All @@ -80,7 +80,7 @@ public function iRemoveTheFollowingSubtreeTag(TableNode $payloadTable): void
if (!$subtreeTags->contain($subtreeTagToRemove)) {
throw new \RuntimeException(sprintf('Failed to remove subtree tag "%s" because that tag is not set', $subtreeTagToRemove->value), 1708618267);
}
$this->dbalClient->getConnection()->update(
$this->dbal->update(
$this->tableNames()->hierarchyRelation(),
[
'subtreetags' => json_encode($subtreeTags->without($subtreeTagToRemove), JSON_THROW_ON_ERROR | JSON_FORCE_OBJECT),
Expand All @@ -97,7 +97,7 @@ public function iAddTheFollowingHierarchyRelation(TableNode $payloadTable): void
{
$dataset = $this->transformPayloadTableToDataset($payloadTable);
$record = $this->transformDatasetToHierarchyRelationRecord($dataset);
$this->dbalClient->getConnection()->insert(
$this->dbal->insert(
$this->tableNames()->hierarchyRelation(),
$record
);
Expand All @@ -114,7 +114,7 @@ public function iChangeTheFollowingHierarchyRelationsDimensionSpacePointHash(Tab
$record = $this->transformDatasetToHierarchyRelationRecord($dataset);
unset($record['position']);

$this->dbalClient->getConnection()->update(
$this->dbal->update(
$this->tableNames()->hierarchyRelation(),
[
'dimensionspacepointhash' => $dataset['newDimensionSpacePointHash']
Expand All @@ -132,7 +132,7 @@ public function iChangeTheFollowingNodesName(TableNode $payloadTable): void
{
$dataset = $this->transformPayloadTableToDataset($payloadTable);

$relationAnchorPoint = $this->dbalClient->getConnection()->executeQuery(
$relationAnchorPoint = $this->dbal->executeQuery(
'SELECT n.relationanchorpoint FROM ' . $this->tableNames()->node() . ' n
JOIN ' . $this->tableNames()->hierarchyRelation() . ' h ON h.childnodeanchor = n.relationanchorpoint
WHERE h.contentstreamid = :contentStreamId
Expand All @@ -145,7 +145,7 @@ public function iChangeTheFollowingNodesName(TableNode $payloadTable): void
]
)->fetchOne();

$this->dbalClient->getConnection()->update(
$this->dbal->update(
$this->tableNames()->node(),
[
'name' => $dataset['newName']
Expand All @@ -171,7 +171,7 @@ public function iSetTheFollowingPosition(TableNode $payloadTable): void
'childnodeanchor' => $this->findRelationAnchorPointByDataset($dataset)
];

$this->dbalClient->getConnection()->update(
$this->dbal->update(
$this->tableNames()->hierarchyRelation(),
[
'position' => $dataset['newPosition']
Expand All @@ -189,7 +189,7 @@ public function iDetachTheFollowingReferenceRelationFromItsSource(TableNode $pay
{
$dataset = $this->transformPayloadTableToDataset($payloadTable);

$this->dbalClient->getConnection()->update(
$this->dbal->update(
$this->tableNames()->referenceRelation(),
[
'nodeanchorpoint' => 7777777
Expand All @@ -207,7 +207,7 @@ public function iSetTheFollowingReferencePosition(TableNode $payloadTable): void
{
$dataset = $this->transformPayloadTableToDataset($payloadTable);

$this->dbalClient->getConnection()->update(
$this->dbal->update(
$this->tableNames()->referenceRelation(),
[
'position' => $dataset['newPosition']
Expand Down Expand Up @@ -277,7 +277,7 @@ private function findHierarchyRelationByIds(
DimensionSpacePoint $dimensionSpacePoint,
NodeAggregateId $nodeAggregateId
): array {
$nodeRecord = $this->dbalClient->getConnection()->executeQuery(
$nodeRecord = $this->dbal->executeQuery(
'SELECT h.*
FROM ' . $this->tableNames()->node() . ' n
INNER JOIN ' . $this->tableNames()->hierarchyRelation() . ' h
Expand Down Expand Up @@ -313,7 +313,7 @@ private function transformPayloadTableToDataset(TableNode $payloadTable): array
*/
public function iRunIntegrityViolationDetection(): void
{
$projectionIntegrityViolationDetectionRunner = $this->getContentRepositoryService(new DoctrineDbalProjectionIntegrityViolationDetectionRunnerFactory($this->dbalClient));
$projectionIntegrityViolationDetectionRunner = $this->getContentRepositoryService(new DoctrineDbalProjectionIntegrityViolationDetectionRunnerFactory($this->dbal));
$this->lastIntegrityViolationDetectionResult = $projectionIntegrityViolationDetectionRunner->run();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

namespace Neos\ContentGraph\DoctrineDbalAdapter;

use Doctrine\DBAL\Connection;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ContentGraph;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory;
use Neos\ContentRepository\Core\ContentGraphFactoryInterface;
use Neos\ContentRepository\Core\Infrastructure\DbalClientInterface;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist;
Expand All @@ -29,7 +29,7 @@
final readonly class ContentGraphFactory implements ContentGraphFactoryInterface
{
public function __construct(
private DbalClientInterface $client,
private Connection $dbal,
private NodeFactory $nodeFactory,
private ContentRepositoryId $contentRepositoryId,
private NodeTypeManager $nodeTypeManager,
Expand All @@ -46,7 +46,7 @@ public function buildForWorkspace(WorkspaceName $workspaceName): ContentGraph
'workspace'
));

$row = $this->client->getConnection()->executeQuery(
$row = $this->dbal->executeQuery(
'
SELECT * FROM ' . $tableName . '
WHERE workspaceName = :workspaceName
Expand All @@ -66,6 +66,6 @@ public function buildForWorkspace(WorkspaceName $workspaceName): ContentGraph

public function buildForWorkspaceAndContentStream(WorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraph
{
return new ContentGraph($this->client, $this->nodeFactory, $this->contentRepositoryId, $this->nodeTypeManager, $this->tableNames, $workspaceName, $contentStreamId);
return new ContentGraph($this->dbal, $this->nodeFactory, $this->contentRepositoryId, $this->nodeTypeManager, $this->tableNames, $workspaceName, $contentStreamId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Event\SubtreeWasTagged;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Event\SubtreeWasUntagged;
use Neos\ContentRepository\Core\Infrastructure\DbalCheckpointStorage;
use Neos\ContentRepository\Core\Infrastructure\DbalClientInterface;
use Neos\ContentRepository\Core\Infrastructure\DbalSchemaDiff;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\CheckpointStorageStatusType;
Expand Down Expand Up @@ -76,14 +75,14 @@ final class DoctrineDbalContentGraphProjection implements ProjectionInterface
private DbalCheckpointStorage $checkpointStorage;

public function __construct(
private readonly DbalClientInterface $dbalClient,
private readonly Connection $dbal,
private readonly ProjectionContentGraph $projectionContentGraph,
private readonly ContentGraphTableNames $tableNames,
private readonly DimensionSpacePointsRepository $dimensionSpacePointsRepository,
private readonly ContentGraphFinder $contentGraphFinder
) {
$this->checkpointStorage = new DbalCheckpointStorage(
$this->dbalClient->getConnection(),
$this->dbal,
$this->tableNames->checkpoint(),
self::class
);
Expand All @@ -107,13 +106,12 @@ public function setUp(): void
*/
private function determineRequiredSqlStatements(): array
{
$connection = $this->dbalClient->getConnection();
$schemaManager = $connection->getSchemaManager();
$schemaManager = $this->dbal->getSchemaManager();
if (!$schemaManager instanceof AbstractSchemaManager) {
throw new \RuntimeException('Failed to retrieve Schema Manager', 1625653914);
}
$schema = (new DoctrineDbalContentGraphSchemaBuilder($this->tableNames))->buildSchema($schemaManager);
return DbalSchemaDiff::determineRequiredSqlStatements($connection, $schema);
return DbalSchemaDiff::determineRequiredSqlStatements($this->dbal, $schema);
}

public function status(): ProjectionStatus
Expand Down Expand Up @@ -152,11 +150,10 @@ public function reset(): void

private function truncateDatabaseTables(): void
{
$connection = $this->dbalClient->getConnection();
$connection->executeQuery('TRUNCATE table ' . $this->tableNames->node());
$connection->executeQuery('TRUNCATE table ' . $this->tableNames->hierarchyRelation());
$connection->executeQuery('TRUNCATE table ' . $this->tableNames->referenceRelation());
$connection->executeQuery('TRUNCATE table ' . $this->tableNames->dimensionSpacePoints());
$this->dbal->executeQuery('TRUNCATE table ' . $this->tableNames->node());
$this->dbal->executeQuery('TRUNCATE table ' . $this->tableNames->hierarchyRelation());
$this->dbal->executeQuery('TRUNCATE table ' . $this->tableNames->referenceRelation());
$this->dbal->executeQuery('TRUNCATE table ' . $this->tableNames->dimensionSpacePoints());
}

public function canHandle(EventInterface $event): bool
Expand Down Expand Up @@ -988,7 +985,7 @@ private function transactional(\Closure $operations): void

private function getDatabaseConnection(): Connection
{
return $this->dbalClient->getConnection();
return $this->dbal;
}

private static function initiatingDateTime(EventEnvelope $eventEnvelope): \DateTimeImmutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

namespace Neos\ContentGraph\DoctrineDbalAdapter;

use Doctrine\DBAL\Connection;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\DimensionSpacePointsRepository;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ProjectionContentGraph;
use Neos\ContentRepository\Core\ContentGraphFinder;
use Neos\ContentRepository\Core\Factory\ProjectionFactoryDependencies;
use Neos\ContentRepository\Core\Infrastructure\DbalClientInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphProjection;
use Neos\ContentRepository\Core\Projection\ProjectionFactoryInterface;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;

/**
* Use this class as ProjectionFactory in your configuration to construct a content graph
Expand All @@ -24,7 +23,7 @@
final class DoctrineDbalContentGraphProjectionFactory implements ProjectionFactoryInterface
{
public function __construct(
private readonly DbalClientInterface $dbalClient
private readonly Connection $dbal,
) {
}

Expand All @@ -36,7 +35,7 @@ public function build(
$projectionFactoryDependencies->contentRepositoryId
);

$dimensionSpacePointsRepository = new DimensionSpacePointsRepository($this->dbalClient->getConnection(), $tableNames);
$dimensionSpacePointsRepository = new DimensionSpacePointsRepository($this->dbal, $tableNames);

$nodeFactory = new NodeFactory(
$projectionFactoryDependencies->contentRepositoryId,
Expand All @@ -46,7 +45,7 @@ public function build(
);

$contentGraphFactory = new ContentGraphFactory(
$this->dbalClient,
$this->dbal,
$nodeFactory,
$projectionFactoryDependencies->contentRepositoryId,
$projectionFactoryDependencies->nodeTypeManager,
Expand All @@ -55,9 +54,9 @@ public function build(

return new ContentGraphProjection(
new DoctrineDbalContentGraphProjection(
$this->dbalClient,
$this->dbal,
new ProjectionContentGraph(
$this->dbalClient,
$this->dbal,
$tableNames
),
$tableNames,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Neos\ContentGraph\DoctrineDbalAdapter;

use Doctrine\DBAL\Connection;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\ProjectionIntegrityViolationDetector;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryDependencies;
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceFactoryInterface;
use Neos\ContentRepository\Core\Infrastructure\DbalClientInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\ProjectionIntegrityViolationDetectionRunner;

/**
Expand All @@ -15,7 +15,7 @@
class DoctrineDbalProjectionIntegrityViolationDetectionRunnerFactory implements ContentRepositoryServiceFactoryInterface
{
public function __construct(
private readonly DbalClientInterface $dbalClient
private readonly Connection $dbal,
) {
}

Expand All @@ -24,7 +24,7 @@ public function build(
): ProjectionIntegrityViolationDetectionRunner {
return new ProjectionIntegrityViolationDetectionRunner(
new ProjectionIntegrityViolationDetector(
$this->dbalClient,
$this->dbal,
ContentGraphTableNames::create(
$serviceFactoryDependencies->contentRepositoryId
)
Expand Down

0 comments on commit 22acc13

Please sign in to comment.