Skip to content

Commit

Permalink
TASK: Check against LiveWorkspaceName Instead Of Comparing CS Ids
Browse files Browse the repository at this point in the history
With neos#5002 `\Neos\Neos\FrontendRouting\Projection\DocumentUriPathFinder::isLiveContentStream` is obsolete.
  • Loading branch information
mhsdesign committed Jun 19, 2024
1 parent a69fed4 commit 83caa70
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function onAfterCatchUp(): void

private function onBeforeSubtreeWasTagged(SubtreeWasTagged $event): void
{
if (!$this->getState()->isLiveContentStream($event->contentStreamId)) {
if (!$event->workspaceName->isLive()) {
return;
}

Expand All @@ -90,7 +90,7 @@ private function onBeforeSubtreeWasTagged(SubtreeWasTagged $event): void

private function onBeforeNodeAggregateWasRemoved(NodeAggregateWasRemoved $event): void
{
if (!$this->getState()->isLiveContentStream($event->contentStreamId)) {
if (!$event->workspaceName->isLive()) {
return;
}

Expand All @@ -110,7 +110,7 @@ private function onBeforeNodeAggregateWasRemoved(NodeAggregateWasRemoved $event)

private function onBeforeNodePropertiesWereSet(NodePropertiesWereSet $event): void
{
if (!$this->getState()->isLiveContentStream($event->contentStreamId)) {
if (!$event->workspaceName->isLive()) {
return;
}

Expand All @@ -135,7 +135,7 @@ private function onBeforeNodePropertiesWereSet(NodePropertiesWereSet $event): vo

private function onBeforeNodeAggregateWasMoved(NodeAggregateWasMoved $event): void
{
if (!$this->getState()->isLiveContentStream($event->contentStreamId)) {
if (!$event->workspaceName->isLive()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
final class DocumentUriPathFinder implements ProjectionStateInterface
{
private ?ContentStreamId $liveContentStreamIdRuntimeCache = null;
private bool $cacheEnabled = true;

/**
Expand Down Expand Up @@ -217,36 +216,6 @@ public function getLastChildNodeNotBeing(
);
}

/**
* @api
*/
public function getLiveContentStreamId(): ContentStreamId
{
if ($this->liveContentStreamIdRuntimeCache === null) {
try {
$contentStreamId = $this->dbal->fetchColumn(
'SELECT contentStreamId FROM '
. $this->tableNamePrefix . '_livecontentstreams LIMIT 1'
);
} catch (DBALException $e) {
throw new \RuntimeException(sprintf(
'Failed to fetch contentStreamId for live workspace: %s',
$e->getMessage()
), 1599666764, $e);
}
if (!is_string($contentStreamId)) {
throw new \RuntimeException(
'Failed to fetch contentStreamId for live workspace,'
. ' probably you have to replay the "documenturipath" projection',
1599667894
);
}
$this->liveContentStreamIdRuntimeCache
= ContentStreamId::fromString($contentStreamId);
}
return $this->liveContentStreamIdRuntimeCache;
}

/**
* @param array<string,mixed> $parameters
* @throws NodeNotFoundException
Expand Down Expand Up @@ -344,9 +313,4 @@ public function getDescendantsOfNode(DocumentNodeInfo $node): DocumentNodeInfos
]
);
}

public function isLiveContentStream(ContentStreamId $contentStreamId): bool
{
return $contentStreamId->equals($this->getLiveContentStreamId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use Neos\ContentRepository\Core\Feature\RootNodeCreation\Event\RootNodeAggregateWithNodeWasCreated;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Event\SubtreeWasTagged;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Event\SubtreeWasUntagged;
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Event\RootWorkspaceWasCreated;
use Neos\ContentRepository\Core\Infrastructure\DbalCheckpointStorage;
use Neos\ContentRepository\Core\Infrastructure\DbalSchemaDiff;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
Expand Down Expand Up @@ -129,7 +128,6 @@ private function truncateDatabaseTables(): void
{
try {
$this->dbal->exec('TRUNCATE ' . $this->tableNamePrefix . '_uri');
$this->dbal->exec('TRUNCATE ' . $this->tableNamePrefix . '_livecontentstreams');
} catch (DBALException $e) {
throw new \RuntimeException(sprintf('Failed to truncate tables: %s', $e->getMessage()), 1599655382, $e);
}
Expand All @@ -139,7 +137,6 @@ private function truncateDatabaseTables(): void
public function canHandle(EventInterface $event): bool
{
return in_array($event::class, [
RootWorkspaceWasCreated::class,
RootNodeAggregateWithNodeWasCreated::class,
RootNodeAggregateDimensionsWereUpdated::class,
NodeAggregateWithNodeWasCreated::class,
Expand All @@ -160,7 +157,6 @@ public function canHandle(EventInterface $event): bool
public function apply(EventInterface $event, EventEnvelope $eventEnvelope): void
{
match ($event::class) {
RootWorkspaceWasCreated::class => $this->whenRootWorkspaceWasCreated($event),
RootNodeAggregateWithNodeWasCreated::class => $this->whenRootNodeAggregateWithNodeWasCreated($event),
RootNodeAggregateDimensionsWereUpdated::class => $this->whenRootNodeAggregateDimensionsWereUpdated($event),
NodeAggregateWithNodeWasCreated::class => $this->whenNodeAggregateWithNodeWasCreated($event),
Expand Down Expand Up @@ -195,25 +191,9 @@ public function getState(): DocumentUriPathFinder
return $this->stateAccessor;
}

private function whenRootWorkspaceWasCreated(RootWorkspaceWasCreated $event): void
{
try {
$this->dbal->insert($this->tableNamePrefix . '_livecontentstreams', [
'contentStreamId' => $event->newContentStreamId->value,
'workspaceName' => $event->workspaceName->value,
]);
} catch (DBALException $e) {
throw new \RuntimeException(sprintf(
'Failed to insert root content stream id of the root workspace "%s": %s',
$event->workspaceName->value,
$e->getMessage()
), 1599646608, $e);
}
}

private function whenRootNodeAggregateWithNodeWasCreated(RootNodeAggregateWithNodeWasCreated $event): void
{
if (!$this->getState()->isLiveContentStream($event->contentStreamId)) {
if (!$event->workspaceName->isLive()) {
return;
}
foreach ($event->coveredDimensionSpacePoints as $dimensionSpacePoint) {
Expand All @@ -229,7 +209,7 @@ private function whenRootNodeAggregateWithNodeWasCreated(RootNodeAggregateWithNo

private function whenRootNodeAggregateDimensionsWereUpdated(RootNodeAggregateDimensionsWereUpdated $event): void
{
if (!$this->getState()->isLiveContentStream($event->contentStreamId)) {
if (!$event->workspaceName->isLive()) {
return;
}

Expand Down Expand Up @@ -269,7 +249,7 @@ private function whenRootNodeAggregateDimensionsWereUpdated(RootNodeAggregateDim

private function whenNodeAggregateWithNodeWasCreated(NodeAggregateWithNodeWasCreated $event): void
{
if (!$this->getState()->isLiveContentStream($event->contentStreamId)) {
if (!$event->workspaceName->isLive()) {
return;
}
if (!$this->isDocumentNodeType($event->nodeTypeName)) {
Expand Down Expand Up @@ -362,7 +342,7 @@ private function whenNodeAggregateWithNodeWasCreated(NodeAggregateWithNodeWasCre

private function whenNodeAggregateTypeWasChanged(NodeAggregateTypeWasChanged $event): void
{
if (!$this->getState()->isLiveContentStream($event->contentStreamId)) {
if (!$event->workspaceName->isLive()) {
return;
}
if ($this->isShortcutNodeType($event->newNodeTypeName)) {
Expand All @@ -384,7 +364,7 @@ private function whenNodeAggregateTypeWasChanged(NodeAggregateTypeWasChanged $ev

private function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event): void
{
if (!$this->getState()->isLiveContentStream($event->contentStreamId)) {
if (!$event->workspaceName->isLive()) {
return;
}
$this->copyVariants(
Expand All @@ -397,7 +377,7 @@ private function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event)

private function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVariantWasCreated $event): void
{
if (!$this->getState()->isLiveContentStream($event->contentStreamId)) {
if (!$event->workspaceName->isLive()) {
return;
}
$this->copyVariants(
Expand All @@ -410,7 +390,7 @@ private function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVaria

private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVariantWasCreated $event): void
{
if (!$this->getState()->isLiveContentStream($event->contentStreamId)) {
if (!$event->workspaceName->isLive()) {
return;
}
$this->copyVariants(
Expand Down Expand Up @@ -452,7 +432,7 @@ private function copyVariants(

private function whenSubtreeWasTagged(SubtreeWasTagged $event): void
{
if ($event->tag->value !== 'disabled' || !$this->getState()->isLiveContentStream($event->contentStreamId)) {
if ($event->tag->value !== 'disabled' || !$event->workspaceName->isLive()) {
return;
}
foreach ($event->affectedDimensionSpacePoints as $dimensionSpacePoint) {
Expand Down Expand Up @@ -483,7 +463,7 @@ private function whenSubtreeWasTagged(SubtreeWasTagged $event): void

private function whenSubtreeWasUntagged(SubtreeWasUntagged $event): void
{
if ($event->tag->value !== 'disabled' || !$this->getState()->isLiveContentStream($event->contentStreamId)) {
if ($event->tag->value !== 'disabled' || !$event->workspaceName->isLive()) {
return;
}
foreach ($event->affectedDimensionSpacePoints as $dimensionSpacePoint) {
Expand Down Expand Up @@ -514,7 +494,7 @@ private function whenSubtreeWasUntagged(SubtreeWasUntagged $event): void

private function whenNodeAggregateWasRemoved(NodeAggregateWasRemoved $event): void
{
if (!$this->getState()->isLiveContentStream($event->contentStreamId)) {
if (!$event->workspaceName->isLive()) {
return;
}
foreach ($event->affectedCoveredDimensionSpacePoints as $dimensionSpacePoint) {
Expand Down Expand Up @@ -544,7 +524,7 @@ private function whenNodeAggregateWasRemoved(NodeAggregateWasRemoved $event): vo

private function whenNodePropertiesWereSet(NodePropertiesWereSet $event, EventEnvelope $eventEnvelope): void
{
if (!$this->getState()->isLiveContentStream($event->contentStreamId)) {
if (!$event->workspaceName->isLive()) {
return;
}
$newPropertyValues = $event->propertyValues->getPlainValues();
Expand Down Expand Up @@ -611,7 +591,7 @@ private function whenNodePropertiesWereSet(NodePropertiesWereSet $event, EventEn

private function whenNodeAggregateWasMoved(NodeAggregateWasMoved $event): void
{
if (!$this->getState()->isLiveContentStream($event->getContentStreamId())) {
if (!$event->workspaceName->isLive()) {
return;
}

Expand Down Expand Up @@ -945,7 +925,7 @@ private function connectNodeWithSiblings(

private function whenDimensionSpacePointWasMoved(DimensionSpacePointWasMoved $event): void
{
if ($this->getState()->isLiveContentStream($event->contentStreamId)) {
if ($event->workspaceName->isLive()) {
$this->updateNodeQuery(
'SET dimensionspacepointhash = :newDimensionSpacePointHash
WHERE dimensionspacepointhash = :originalDimensionSpacePointHash',
Expand All @@ -969,7 +949,7 @@ private function whenDimensionSpacePointWasMoved(DimensionSpacePointWasMoved $ev

private function whenDimensionShineThroughWasAdded(DimensionShineThroughWasAdded $event): void
{
if ($this->getState()->isLiveContentStream($event->contentStreamId)) {
if ($event->workspaceName->isLive()) {
try {
$this->dbal->executeStatement('INSERT INTO ' . $this->tableNamePrefix . '_uri (
nodeaggregateid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public function __construct(
public function buildSchema(AbstractSchemaManager $schemaManager): Schema
{
$schema = DbalSchemaFactory::createSchemaWithTables($schemaManager, [
$this->createUriTable(),
$this->createLiveContentStreamsTable()
$this->createUriTable()
]);

return $schema;
Expand Down Expand Up @@ -55,13 +54,4 @@ private function createUriTable(): Table
], 'preceding_succeeding')
->addIndex(['sitenodename', 'uripath'], null, [], ['lengths' => [null,100]]);
}

private function createLiveContentStreamsTable(): Table
{
$table = new Table($this->tableNamePrefix . '_livecontentstreams', [
DbalSchemaFactory::columnForContentStreamId('contentstreamid')->setNotNull(true),
(new Column('workspacename', Type::getType(Types::STRING)))->setLength(255)->setDefault('')->setNotnull(true)
]);
return $table->setPrimaryKey(['contentstreamid']);
}
}
Loading

0 comments on commit 83caa70

Please sign in to comment.