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: Use workspaceName instead of contentStreamId in AssetUsageProjection #5109

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ public static function columnForNodeTypeName(string $columnName): Column
->setPlatformOption('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<AbstractPlatform> $schemaManager
* @param Table[] $tables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ private function determineRequiredSqlStatements(): array
{
$schemaManager = $this->dbal->createSchemaManager();
$workspaceTable = new Table($this->tableName, [
(new Column('workspacename', Type::getType(Types::STRING)))->setLength(WorkspaceName::MAX_LENGTH)->setNotnull(true)->setPlatformOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('baseworkspacename', Type::getType(Types::STRING)))->setLength(WorkspaceName::MAX_LENGTH)->setNotnull(false)->setPlatformOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('workspacetitle', Type::getType(Types::STRING)))->setLength(255)->setNotnull(true)->setPlatformOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('workspacedescription', Type::getType(Types::STRING)))->setLength(255)->setNotnull(true)->setPlatformOption('collation', self::DEFAULT_TEXT_COLLATION),
(new Column('workspaceowner', Type::getType(Types::STRING)))->setLength(255)->setNotnull(false)->setPlatformOption('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),
DbalSchemaFactory::columnForContentStreamId('currentcontentstreamid')->setNotNull(true),
(new Column('status', Type::getType(Types::BINARY)))->setLength(20)->setNotnull(false)
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function run(): ProcessorResult
if ($liveWorkspace === null) {
return ProcessorResult::error('Failed to find live workspace');
}
$assetFilter = AssetUsageFilter::create()->withContentStream($liveWorkspace->currentContentStreamId)->groupByAsset();
$assetFilter = AssetUsageFilter::create()->withWorkspaceName($liveWorkspace->workspaceName)->groupByAsset();

$numberOfExportedAssets = 0;
$numberOfExportedImageVariants = 0;
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
2 changes: 1 addition & 1 deletion Neos.Neos/Classes/AssetUsage/AssetUsageStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getUsageReferences(AssetInterface $asset): array
$convertedUsages[] = new AssetUsageReference(
$asset,
ContentRepositoryId::fromString($contentRepositoryId),
$usage->contentStreamId,
$usage->workspaceName,
$usage->originDimensionSpacePoint,
$usage->nodeAggregateId
);
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
102 changes: 73 additions & 29 deletions Neos.Neos/Classes/AssetUsage/Projection/AssetUsageProjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@

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\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\NodeGeneralizationVariantWasCreated;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodePeerVariantWasCreated;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodeSpecializationVariantWasCreated;
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Event\RootWorkspaceWasCreated;
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Event\WorkspaceWasCreated;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Event\WorkspaceBaseWorkspaceWasChanged;
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 +90,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,65 +113,96 @@ public function whenNodePropertiesWereSet(NodePropertiesWereSet $event, EventEnv
);
}
$nodeAddress = new AssetUsageNodeAddress(
$event->getContentStreamId(),
$event->workspaceName,
$event->getOriginDimensionSpacePoint()->toDimensionSpacePoint(),
$event->getNodeAggregateId()
$event->nodeAggregateId
);

$this->repository->deleteAssetUsageByNodeAddressAndPropertyNames($nodeAddress, $event->propertiesToUnset);
$this->repository->addUsagesForNode($nodeAddress, $assetIdsByProperty);
}

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


public function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event): void
{
$this->repository->copyDimensions($event->sourceOrigin, $event->peerOrigin);
$this->repository->copyNodeAggregateFromBaseWorkspace($event->nodeAggregateId, $event->workspaceName, $event->sourceOrigin, $event->peerOrigin);
}

public function whenContentStreamWasForked(ContentStreamWasForked $event): void
public function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVariantWasCreated $event): void
{
$this->repository->copyContentStream(
$event->sourceContentStreamId,
$event->newContentStreamId
);
$this->repository->copyNodeAggregateFromBaseWorkspace($event->nodeAggregateId, $event->workspaceName, $event->sourceOrigin, $event->generalizationOrigin);
}

public function whenNodeSpecializationVariantWasCreated(NodeSpecializationVariantWasCreated $event): void
{
$this->repository->copyNodeAggregateFromBaseWorkspace($event->nodeAggregateId, $event->workspaceName, $event->sourceOrigin, $event->specializationOrigin);
}

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

public function whenWorkspaceWasPartiallyDiscarded(WorkspaceWasPartiallyDiscarded $event): void
{
$this->repository->removeContentStream($event->previousContentStreamId);
foreach ($event->discardedNodes as $discardedNode) {
$this->repository->removeNodeInWorkspace(
$discardedNode->nodeAggregateId,
DimensionSpacePointSet::fromArray([$discardedNode->dimensionSpacePoint]),
$event->workspaceName
);
}
}

public function whenWorkspaceWasPartiallyPublished(WorkspaceWasPartiallyPublished $event): void
{
$this->repository->removeContentStream($event->previousSourceContentStreamId);
foreach ($event->publishedNodes as $publishedNode) {
$this->repository->removeNodeInWorkspace(
$publishedNode->nodeAggregateId,
DimensionSpacePointSet::fromArray([$publishedNode->dimensionSpacePoint]),
$event->sourceWorkspaceName
);
}
}

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

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

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

public function whenWorkspaceWasCreated(WorkspaceWasCreated $event): void
{
$this->repository->addWorkspace($event->workspaceName, $event->baseWorkspaceName);
}

private function whenRootWorkspaceWasCreated(RootWorkspaceWasCreated $event): void
{
$this->repository->addWorkspace($event->workspaceName, null);
}

private function whenWorkspaceBaseWorkspaceWasChanged(WorkspaceBaseWorkspaceWasChanged $event): void
{
$this->repository->updateWorkspace($event->workspaceName, $event->baseWorkspaceName);
}

// ----------------

Expand Down Expand Up @@ -260,30 +296,38 @@ public function canHandle(EventInterface $event): bool
NodePropertiesWereSet::class,
NodeAggregateWasRemoved::class,
NodePeerVariantWasCreated::class,
ContentStreamWasForked::class,
NodeGeneralizationVariantWasCreated::class,
NodeSpecializationVariantWasCreated::class,
WorkspaceWasDiscarded::class,
WorkspaceWasPartiallyDiscarded::class,
WorkspaceWasPartiallyPublished::class,
WorkspaceWasPublished::class,
WorkspaceWasRebased::class,
ContentStreamWasRemoved::class,
WorkspaceWasRemoved::class,
WorkspaceWasCreated::class,
RootWorkspaceWasCreated::class,
WorkspaceBaseWorkspaceWasChanged::class,
]);
}

public function apply(EventInterface $event, EventEnvelope $eventEnvelope): void
{
match ($event::class) {
NodeAggregateWithNodeWasCreated::class => $this->whenNodeAggregateWithNodeWasCreated($event, $eventEnvelope),
NodeGeneralizationVariantWasCreated::class => $this->whenNodeGeneralizationVariantWasCreated($event),
NodeSpecializationVariantWasCreated::class => $this->whenNodeSpecializationVariantWasCreated($event),
NodePeerVariantWasCreated::class => $this->whenNodePeerVariantWasCreated($event),
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),
WorkspaceWasCreated::class => $this->whenWorkspaceWasCreated($event),
RootWorkspaceWasCreated::class => $this->whenRootWorkspaceWasCreated($event),
WorkspaceBaseWorkspaceWasChanged::class => $this->whenWorkspaceBaseWorkspaceWasChanged($event),
default => throw new \InvalidArgumentException(sprintf('Unsupported event %s', get_debug_type($event))),
};
}
Expand All @@ -310,7 +354,7 @@ private function findOriginalAssetId(string $assetId): ?string
} /** @noinspection PhpRedundantCatchClauseInspection */ catch (ORMException) {
return null;
}
/** @phpstan-ignore-next-line */
/** @phpstan-ignore-next-line */
$this->originalAssetIdMappingRuntimeCache[$assetId] = $asset instanceof AssetVariantInterface ? $asset->getOriginalAsset()->getIdentifier() : null;
}

Expand Down
Loading
Loading