Skip to content

Commit

Permalink
TASK: introduce and use removeNodeInWorkspace method
Browse files Browse the repository at this point in the history
  • Loading branch information
crydotsnake committed Jun 3, 2024
1 parent 29062df commit b0efca7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
26 changes: 18 additions & 8 deletions Neos.Neos/Classes/AssetUsage/Projection/AssetUsageProjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\DBAL\Connection;
use Doctrine\ORM\Exception\ORMException;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\ContentRepository\Core\Feature\NodeCreation\Event\NodeAggregateWithNodeWasCreated;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
Expand Down Expand Up @@ -116,9 +117,10 @@ public function whenNodePropertiesWereSet(NodePropertiesWereSet $event, EventEnv

public function whenNodeAggregateWasRemoved(NodeAggregateWasRemoved $event): void
{
$this->repository->removeNode(
$this->repository->removeNodeInWorkspace(
$event->nodeAggregateId,
$event->affectedOccupiedDimensionSpacePoints->toDimensionSpacePointSet()
$event->affectedOccupiedDimensionSpacePoints->toDimensionSpacePointSet(),
$event->workspaceName
);
}

Expand All @@ -133,18 +135,26 @@ public function whenWorkspaceWasDiscarded(WorkspaceWasDiscarded $event): void
$this->repository->removeWorkspaceName($event->workspaceName);
}

// @TODO: Check if asset is part of partially discarded
// use NodeIdsToPublishOrDiscard?
public function whenWorkspaceWasPartiallyDiscarded(WorkspaceWasPartiallyDiscarded $event): void
{
$this->repository->removeWorkspaceName($event->workspaceName);
foreach ($event->discardedNodes as $discardedNode) {
$this->repository->removeNodeInWorkspace(
$discardedNode->nodeAggregateId,
DimensionSpacePointSet::fromArray([$discardedNode->dimensionSpacePoint]),
$event->workspaceName
);
}
}

// @TODO: Check if asset is part of partially published
// use NodeIdsToPublishOrDiscard?
public function whenWorkspaceWasPartiallyPublished(WorkspaceWasPartiallyPublished $event): void
{
$this->repository->removeWorkspaceName($event->sourceWorkspaceName);
foreach ($event->publishedNodes as $publishedNode) {
$this->repository->removeNodeInWorkspace(
$publishedNode->nodeAggregateId,
DimensionSpacePointSet::fromArray([$publishedNode->dimensionSpacePoint]),
$event->sourceWorkspaceName
);
}
}

public function whenWorkspaceWasPublished(WorkspaceWasPublished $event): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,20 @@ public function removeAsset(string $assetId): void
]);
}

public function removeNode(
public function removeNodeInWorkspace(
NodeAggregateId $nodeAggregateId,
DimensionSpacePointSet $dimensionSpacePoints,
WorkspaceName $workspaceName
): void {
$this->dbal->executeStatement(
'DELETE FROM ' . $this->tableNamePrefix
. ' WHERE nodeAggregateId = :nodeAggregateId'
. ' AND originDimensionSpacePointHash IN (:dimensionSpacePointHashes)',
. ' WHERE nodeaggregateid = :nodeAggregateId'
. ' AND origindimensionspacepointhash IN (:dimensionSpacePointHashes)'
. ' AND workspacename = :workspaceName',
[
'nodeAggregateId' => $nodeAggregateId->value,
'dimensionSpacePointHashes' => $dimensionSpacePoints->getPointHashes(),
'workspaceName' => $workspaceName->value,
],
[
'dimensionSpacePointHashes' => Connection::PARAM_STR_ARRAY,
Expand Down

0 comments on commit b0efca7

Please sign in to comment.