Skip to content

Commit

Permalink
Merge pull request #5149 from mhsdesign/task/refactorIsLiveContentStr…
Browse files Browse the repository at this point in the history
…eamToUseWorkspaceNameOfEvent

TASK: Check against LiveWorkspaceName Instead Of Comparing CS Ids
  • Loading branch information
mhsdesign authored Sep 25, 2024
2 parents 7edcefc + 2ea5e98 commit 1fb99b7
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function onAfterCatchUp(): void

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

Expand All @@ -92,7 +92,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 @@ -112,7 +112,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 @@ -137,7 +137,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 @@ -8,7 +8,6 @@
use Doctrine\DBAL\Exception as DBALException;
use Neos\ContentRepository\Core\Projection\ProjectionStateInterface;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Model\SiteNodeName;
use Neos\Neos\FrontendRouting\Exception\NodeNotFoundException;
Expand All @@ -18,7 +17,6 @@
*/
final class DocumentUriPathFinder implements ProjectionStateInterface
{
private ?ContentStreamId $liveContentStreamIdRuntimeCache = null;
private bool $cacheEnabled = true;

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

/**
* @api
*/
public function getLiveContentStreamId(): ContentStreamId
{
if ($this->liveContentStreamIdRuntimeCache === null) {
try {
$contentStreamId = $this->dbal->fetchOne(
'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 @@ -345,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 @@ -6,7 +6,6 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Types\Types;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\EventStore\EventInterface;
Expand All @@ -25,7 +24,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 @@ -109,7 +107,12 @@ private function determineRequiredSqlStatements(): array
{
$schemaManager = $this->dbal->createSchemaManager();
$schema = (new DocumentUriPathSchemaBuilder($this->tableNamePrefix))->buildSchema($schemaManager);
return DbalSchemaDiff::determineRequiredSqlStatements($this->dbal, $schema);
$statements = DbalSchemaDiff::determineRequiredSqlStatements($this->dbal, $schema);
// MIGRATIONS
if ($this->dbal->getSchemaManager()->tablesExist([$this->tableNamePrefix . '_livecontentstreams'])) {
$statements[] = sprintf('DROP table %s_livecontentstreams;', $this->tableNamePrefix);
}
return $statements;
}


Expand All @@ -125,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 @@ -135,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 @@ -156,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 @@ -191,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 @@ -225,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 @@ -265,7 +249,7 @@ private function whenRootNodeAggregateDimensionsWereUpdated(RootNodeAggregateDim

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

private function whenNodeAggregateTypeWasChanged(NodeAggregateTypeWasChanged $event): void
{
if (!$this->getState()->isLiveContentStream($event->contentStreamId)) {
if (!$event->workspaceName->isLive()) {
return;
}
switch ($this->getDocumentTypeClassification($event->newNodeTypeName)) {
Expand Down Expand Up @@ -395,7 +379,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 @@ -408,7 +392,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 @@ -421,7 +405,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 @@ -463,7 +447,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 @@ -494,7 +478,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 @@ -525,7 +509,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 @@ -555,7 +539,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 @@ -623,7 +607,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 @@ -941,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 @@ -965,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 @@ -33,8 +33,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 @@ -67,13 +66,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),
DbalSchemaFactory::columnForWorkspaceName('workspacename')->setDefault('')
]);
return $table->setPrimaryKey(['contentstreamid']);
}
}
Loading

0 comments on commit 1fb99b7

Please sign in to comment.