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: Check against LiveWorkspaceName Instead Of Comparing CS Ids #5149

Merged
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 @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a huge fan.... I would just leave this dangling, we can consider something for these cases after release...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not a huge fan either from these hardcoded migrations, but Sebastian started introducing them and we can delete them at some point if we want. So thats why ill merge it.

}
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a more general question:
Wouldn't this be also responsible for now removing the deprecated table?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question in general. Have the same issue with another table. But does it make sence to check for removal on each setup? How long? When will we remove the removal code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Create" is a bit misleading here – it creates the schema for the table. There is no way to remove a schema here.
That's currently done in the projection itself (see https://github.com/neos/neos-development-collection/pull/5149/files#diff-2e3df51a3340b51e08cf9d2ba5aade329a8c0e073354c1d5a72e42c3aaf5a127R112)
But I'm with @kitsunet on this one: Let's leave those dangling for now. For 9.0 -> 9.1 ect we'll have to think of a way to migrate those things once

$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
Loading