Skip to content

Commit

Permalink
TASK: Use workspaceName instead of ContentStreamId in AssetUsageProje…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
crydotsnake committed Jun 1, 2024
1 parent cd86371 commit 29062df
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ public static function columnForNodeTypeName(string $columnName): Column
->setCustomSchemaOption('collation', 'ascii_general_ci');
}

/**
* The WorkspaceName is an utf8mb4 string, we should be able to sort it properly, but we don't need unicode here.
*
* @see NodeTypeName
*/
public static function columnForWorkspaceName(string $columnName): Column
{
return (new Column($columnName, Type::getType(Types::STRING)))
->setLength(255)
->setNotnull(true)
->setCustomSchemaOption('collation', 'utf8mb4_unicode_520_ci');
}

/**
* @param AbstractSchemaManager $schemaManager
* @param Table[] $tables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ private function determineRequiredSqlStatements(): array
}

$workspaceTable = new Table($this->tableName, [
(new Column('workspacename', Type::getType(Types::STRING)))->setLength(255)->setNotnull(true)->setCustomSchemaOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('baseworkspacename', Type::getType(Types::STRING)))->setLength(255)->setNotnull(false)->setCustomSchemaOption('collation', self::DEFAULT_TEXT_COLLATION),
DbalSchemaFactory::columnForWorkspaceName('workspacename')->setNotNull(true),
DbalSchemaFactory::columnForWorkspaceName('baseworkspacename')->setNotNull(false),
(new Column('workspacetitle', Type::getType(Types::STRING)))->setLength(255)->setNotnull(true)->setCustomSchemaOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('workspacedescription', Type::getType(Types::STRING)))->setLength(255)->setNotnull(true)->setCustomSchemaOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('workspaceowner', Type::getType(Types::STRING)))->setLength(255)->setNotnull(false)->setCustomSchemaOption('collation', self::DEFAULT_TEXT_COLLATION),
Expand Down
2 changes: 1 addition & 1 deletion Neos.Media.Browser/Classes/Controller/UsageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function relatedNodesAction(AssetInterface $asset)

$contentRepository = $this->contentRepositoryRegistry->get($usage->getContentRepositoryId());

$workspace = $contentRepository->getWorkspaceFinder()->findOneByCurrentContentStreamId($usage->getContentStreamId());
$workspace = $contentRepository->getWorkspaceFinder()->findOneByName($usage->getWorkspaceName());

// FIXME: AssetUsageReference->workspaceName ?
$nodeAggregate = $contentRepository->getContentGraph($workspace->workspaceName)->findNodeAggregateById(
Expand Down
4 changes: 2 additions & 2 deletions Neos.Neos/Classes/AssetUsage/Dto/AssetUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\Flow\Annotations as Flow;

/**
Expand All @@ -17,7 +17,7 @@
{
public function __construct(
public string $assetId,
public ContentStreamId $contentStreamId,
public WorkspaceName $workspaceName,
public OriginDimensionSpacePoint $originDimensionSpacePoint,
public NodeAggregateId $nodeAggregateId,
public string $propertyName,
Expand Down
20 changes: 10 additions & 10 deletions Neos.Neos/Classes/AssetUsage/Dto/AssetUsageFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Neos\Neos\AssetUsage\Dto;

use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\Flow\Annotations as Flow;

/**
Expand All @@ -15,7 +15,7 @@
{
private function __construct(
public ?string $assetId,
public ?ContentStreamId $contentStreamId,
public ?WorkspaceName $workspaceName,
public bool $groupByAsset,
public bool $groupByNode,
public bool $includeVariantsOfAsset,
Expand All @@ -29,36 +29,36 @@ public static function create(): self

public function withAsset(string $assetId): self
{
return new self($assetId, $this->contentStreamId, $this->groupByAsset, $this->groupByNode, $this->includeVariantsOfAsset);
return new self($assetId, $this->workspaceName, $this->groupByAsset, $this->groupByNode, $this->includeVariantsOfAsset);
}

public function withContentStream(ContentStreamId $contentStreamId): self
public function withWorkspaceName(WorkspaceName $workspaceName): self
{
return new self($this->assetId, $contentStreamId, $this->groupByAsset, $this->groupByNode, $this->includeVariantsOfAsset);
return new self($this->assetId, $workspaceName, $this->groupByAsset, $this->groupByNode, $this->includeVariantsOfAsset);
}

public function includeVariantsOfAsset(): self
{
return new self($this->assetId, $this->contentStreamId, $this->groupByAsset, $this->groupByNode, true);
return new self($this->assetId, $this->workspaceName, $this->groupByAsset, $this->groupByNode, true);
}

public function groupByAsset(): self
{
return new self($this->assetId, $this->contentStreamId, true, $this->groupByNode, $this->includeVariantsOfAsset);
return new self($this->assetId, $this->workspaceName, true, $this->groupByNode, $this->includeVariantsOfAsset);
}

public function groupByNode(): self
{
return new self($this->assetId, $this->contentStreamId, $this->groupByAsset, true, $this->includeVariantsOfAsset);
return new self($this->assetId, $this->workspaceName, $this->groupByAsset, true, $this->includeVariantsOfAsset);
}

public function hasAssetId(): bool
{
return $this->assetId !== null;
}

public function hasContentStreamId(): bool
public function hasWorkspaceName(): bool
{
return $this->contentStreamId !== null;
return $this->workspaceName !== null;
}
}
4 changes: 2 additions & 2 deletions Neos.Neos/Classes/AssetUsage/Dto/AssetUsageNodeAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\Flow\Annotations as Flow;

/**
Expand All @@ -21,7 +21,7 @@
final readonly class AssetUsageNodeAddress
{
public function __construct(
public ContentStreamId $contentStreamId,
public WorkspaceName $workspaceName,
public DimensionSpacePoint $dimensionSpacePoint,
public NodeAggregateId $nodeAggregateId,
) {
Expand Down
8 changes: 4 additions & 4 deletions Neos.Neos/Classes/AssetUsage/Dto/AssetUsageReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\Flow\Annotations as Flow;
use Neos\Media\Domain\Model\AssetInterface;
use Neos\Media\Domain\Model\Dto\UsageReference;
Expand All @@ -21,7 +21,7 @@ final class AssetUsageReference extends UsageReference
public function __construct(
AssetInterface $asset,
private readonly ContentRepositoryId $contentRepositoryId,
private readonly ContentStreamId $contentStreamId,
private readonly WorkspaceName $workspaceName,
private readonly OriginDimensionSpacePoint $originDimensionSpacePointHash,
private readonly NodeAggregateId $nodeAggregateId,
) {
Expand All @@ -33,9 +33,9 @@ public function getContentRepositoryId(): ContentRepositoryId
return $this->contentRepositoryId;
}

public function getContentStreamId(): ContentStreamId
public function getWorkspaceName(): WorkspaceName
{
return $this->contentStreamId;
return $this->workspaceName;
}

public function getOriginDimensionSpacePoint(): OriginDimensionSpacePoint
Expand Down
45 changes: 19 additions & 26 deletions Neos.Neos/Classes/AssetUsage/Projection/AssetUsageProjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Exception\ORMException;
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\ContentRepository\Core\Feature\ContentStreamForking\Event\ContentStreamWasForked;
use Neos\ContentRepository\Core\Feature\ContentStreamRemoval\Event\ContentStreamWasRemoved;
use Neos\ContentRepository\Core\Feature\NodeCreation\Event\NodeAggregateWithNodeWasCreated;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\Feature\NodeModification\Event\NodePropertiesWereSet;
use Neos\ContentRepository\Core\Feature\NodeRemoval\Event\NodeAggregateWasRemoved;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodePeerVariantWasCreated;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Event\WorkspaceWasRemoved;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasDiscarded;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasPartiallyDiscarded;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasPartiallyPublished;
Expand Down Expand Up @@ -85,9 +84,9 @@ public function whenNodeAggregateWithNodeWasCreated(NodeAggregateWithNodeWasCrea
);
}
$nodeAddress = new AssetUsageNodeAddress(
$event->getContentStreamId(),
$event->workspaceName,
$event->getOriginDimensionSpacePoint()->toDimensionSpacePoint(),
$event->getNodeAggregateId()
$event->nodeAggregateId
);
$this->repository->addUsagesForNode($nodeAddress, $assetIdsByProperty);
}
Expand All @@ -108,17 +107,17 @@ public function whenNodePropertiesWereSet(NodePropertiesWereSet $event, EventEnv
);
}
$nodeAddress = new AssetUsageNodeAddress(
$event->getContentStreamId(),
$event->workspaceName,
$event->getOriginDimensionSpacePoint()->toDimensionSpacePoint(),
$event->getNodeAggregateId()
$event->nodeAggregateId
);
$this->repository->addUsagesForNode($nodeAddress, $assetIdsByProperty);
}

public function whenNodeAggregateWasRemoved(NodeAggregateWasRemoved $event): void
{
$this->repository->removeNode(
$event->getNodeAggregateId(),
$event->nodeAggregateId,
$event->affectedOccupiedDimensionSpacePoints->toDimensionSpacePointSet()
);
}
Expand All @@ -129,42 +128,38 @@ public function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event):
$this->repository->copyDimensions($event->sourceOrigin, $event->peerOrigin);
}

public function whenContentStreamWasForked(ContentStreamWasForked $event): void
{
$this->repository->copyContentStream(
$event->sourceContentStreamId,
$event->newContentStreamId
);
}

public function whenWorkspaceWasDiscarded(WorkspaceWasDiscarded $event): void
{
$this->repository->removeContentStream($event->previousContentStreamId);
$this->repository->removeWorkspaceName($event->workspaceName);
}

// @TODO: Check if asset is part of partially discarded
// use NodeIdsToPublishOrDiscard?
public function whenWorkspaceWasPartiallyDiscarded(WorkspaceWasPartiallyDiscarded $event): void
{
$this->repository->removeContentStream($event->previousContentStreamId);
$this->repository->removeWorkspaceName($event->workspaceName);
}

// @TODO: Check if asset is part of partially published
// use NodeIdsToPublishOrDiscard?
public function whenWorkspaceWasPartiallyPublished(WorkspaceWasPartiallyPublished $event): void
{
$this->repository->removeContentStream($event->previousSourceContentStreamId);
$this->repository->removeWorkspaceName($event->sourceWorkspaceName);
}

public function whenWorkspaceWasPublished(WorkspaceWasPublished $event): void
{
$this->repository->removeContentStream($event->previousSourceContentStreamId);
$this->repository->removeWorkspaceName($event->targetWorkspaceName);
}

public function whenWorkspaceWasRebased(WorkspaceWasRebased $event): void
{
$this->repository->removeContentStream($event->previousContentStreamId);
$this->repository->removeWorkspaceName($event->workspaceName);
}

public function whenContentStreamWasRemoved(ContentStreamWasRemoved $event): void
public function whenWorkspaceWasRemoved(WorkspaceWasRemoved $event): void
{
$this->repository->removeContentStream($event->contentStreamId);
$this->repository->removeWorkspaceName($event->workspaceName);
}


Expand Down Expand Up @@ -260,13 +255,12 @@ public function canHandle(EventInterface $event): bool
NodePropertiesWereSet::class,
NodeAggregateWasRemoved::class,
NodePeerVariantWasCreated::class,
ContentStreamWasForked::class,
WorkspaceWasDiscarded::class,
WorkspaceWasPartiallyDiscarded::class,
WorkspaceWasPartiallyPublished::class,
WorkspaceWasPublished::class,
WorkspaceWasRebased::class,
ContentStreamWasRemoved::class,
WorkspaceWasRemoved::class
]);
}

Expand All @@ -277,13 +271,12 @@ public function apply(EventInterface $event, EventEnvelope $eventEnvelope): void
NodePropertiesWereSet::class => $this->whenNodePropertiesWereSet($event, $eventEnvelope),
NodeAggregateWasRemoved::class => $this->whenNodeAggregateWasRemoved($event),
NodePeerVariantWasCreated::class => $this->whenNodePeerVariantWasCreated($event),
ContentStreamWasForked::class => $this->whenContentStreamWasForked($event),
WorkspaceWasDiscarded::class => $this->whenWorkspaceWasDiscarded($event),
WorkspaceWasPartiallyDiscarded::class => $this->whenWorkspaceWasPartiallyDiscarded($event),
WorkspaceWasPartiallyPublished::class => $this->whenWorkspaceWasPartiallyPublished($event),
WorkspaceWasPublished::class => $this->whenWorkspaceWasPublished($event),
WorkspaceWasRebased::class => $this->whenWorkspaceWasRebased($event),
ContentStreamWasRemoved::class => $this->whenContentStreamWasRemoved($event),
WorkspaceWasRemoved::class => $this->whenWorkspaceWasRemoved($event),
default => throw new \InvalidArgumentException(sprintf('Unsupported event %s', get_debug_type($event))),
};
}
Expand Down
Loading

0 comments on commit 29062df

Please sign in to comment.