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

BUGFIX 4298 content stream creation deduplication #4674

Closed
wants to merge 7 commits into from
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 @@ -400,10 +400,8 @@ private function connectRestrictionRelationsFromParentNodeToNewlyCreatedNode(
NodeAggregateId $newlyCreatedNodeAggregateId,
DimensionSpacePointSet $dimensionSpacePointsInWhichNewlyCreatedNodeAggregateIsVisible
): void {
// TODO: still unsure why we need an "INSERT IGNORE" here;
Copy link
Member

Choose a reason for hiding this comment

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

this should probably be extracted into a separate change?

// normal "INSERT" can trigger a duplicate key constraint exception
$this->getDatabaseConnection()->executeUpdate('
INSERT IGNORE INTO ' . $this->tableNamePrefix . '_restrictionrelation (
INSERT INTO ' . $this->tableNamePrefix . '_restrictionrelation (
contentstreamid,
dimensionspacepointhash,
originnodeaggregateid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@ abstract protected function getTableNamePrefix(): string;
private function whenNodeAggregateWasDisabled(NodeAggregateWasDisabled $event): void
{
$this->transactional(function () use ($event) {


// TODO: still unsure why we need an "INSERT IGNORE" here;
// normal "INSERT" can trigger a duplicate key constraint exception
$this->getDatabaseConnection()->executeStatement(
'
-- GraphProjector::whenNodeAggregateWasDisabled
insert ignore into ' . $this->getTableNamePrefix() . '_restrictionrelation
insert into ' . $this->getTableNamePrefix() . '_restrictionrelation
(contentstreamid, dimensionspacepointhash, originnodeaggregateid, affectednodeaggregateid)

-- we build a recursive tree
Expand Down
2 changes: 1 addition & 1 deletion Neos.ContentRepository.Export/src/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public function __construct(
private readonly Filesystem $filesystem,
private readonly ContentStreamId $contentStreamIdentifier,

Check failure on line 29 in Neos.ContentRepository.Export/src/ImportService.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Property Neos\ContentRepository\Export\ImportService::$contentStreamIdentifier is never read, only written.

Check failure on line 29 in Neos.ContentRepository.Export/src/ImportService.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test linting-unit-functionaltests-mysql (deps: highest)

Property Neos\ContentRepository\Export\ImportService::$contentStreamIdentifier is never read, only written.

Check failure on line 29 in Neos.ContentRepository.Export/src/ImportService.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Property Neos\ContentRepository\Export\ImportService::$contentStreamIdentifier is never read, only written.

Check failure on line 29 in Neos.ContentRepository.Export/src/ImportService.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test linting-unit-functionaltests-mysql (deps: highest)

Property Neos\ContentRepository\Export\ImportService::$contentStreamIdentifier is never read, only written.
private readonly AssetRepository $assetRepository,
private readonly ResourceRepository $resourceRepository,
private readonly ResourceManager $resourceManager,
Expand Down Expand Up @@ -56,7 +56,7 @@
$this->filesystem,
$this->eventStore,
$this->eventNormalizer,
$this->contentStreamIdentifier,
null,
)
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ public function run(): ProcessorResult

$keepStreamName = false;
while (($line = fgets($eventFileResource)) !== false) {
$isContentStreamDefiningEvent = false;
$event = ExportedEvent::fromJson(trim($line));
if ($this->contentStreamId === null) {
$this->contentStreamId = self::extractContentStreamId($event->payload);
$keepStreamName = true;
$isContentStreamDefiningEvent = true;
}
if (!$keepStreamName) {
$event = $event->processPayload(fn(array $payload) => isset($payload['contentStreamId']) ? [...$payload, 'contentStreamId' => $this->contentStreamId->value] : $payload);
Expand Down Expand Up @@ -102,6 +104,10 @@ public function run(): ProcessorResult
Event\EventMetadata::fromArray($event->metadata)
)
);
if ($isContentStreamDefiningEvent && $domainEvent instanceof ContentStreamWasCreated) {
// will be applied separately, so we prevent duplication here
continue;
}
$domainEvent = DecoratedEvent::create($domainEvent, eventId: EventId::fromString($event->identifier), metadata: $event->metadata);
$domainEvents[] = $this->normalizeEvent($domainEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,37 +158,6 @@ Feature: Routing behavior of removed, disabled and re-enabled nodes
And The node "sir-david-nodenborough" in content stream "cs-identifier" and dimension "{}" should resolve to URL "/david-nodenborough"
And The node "earl-o-documentbourgh" in content stream "cs-identifier" and dimension "{}" should resolve to URL "/david-nodenborough/earl-document"

Scenario: Disable the same node twice
When the command "DisableNodeAggregate" is executed with payload:
| Key | Value |
| contentStreamId | "cs-identifier" |
| nodeAggregateId | "sir-david-nodenborough" |
| coveredDimensionSpacePoint | {} |
| nodeVariantSelectionStrategy | "allVariants" |
And the event NodeAggregateWasDisabled was published with payload:
| Key | Value |
| contentStreamId | "cs-identifier" |
| nodeAggregateId | "sir-david-nodenborough" |
| affectedDimensionSpacePoints | [{}] |
ahaeslich marked this conversation as resolved.
Show resolved Hide resolved
And the graph projection is fully up to date
And The documenturipath projection is up to date
Then No node should match URL "/david-nodenborough"
And No node should match URL "/david-nodenborough/earl-document"
And The node "sir-david-nodenborough" in content stream "cs-identifier" and dimension "{}" should resolve to URL "/david-nodenborough"
And The node "earl-o-documentbourgh" in content stream "cs-identifier" and dimension "{}" should resolve to URL "/david-nodenborough/earl-document"
When the command "EnableNodeAggregate" is executed with payload:
| Key | Value |
| contentStreamId | "cs-identifier" |
| nodeAggregateId | "sir-david-nodenborough" |
| coveredDimensionSpacePoint | {} |
| nodeVariantSelectionStrategy | "allVariants" |
And the graph projection is fully up to date
And The documenturipath projection is up to date
When I am on URL "/david-nodenborough"
Then the matched node should be "sir-david-nodenborough" in content stream "cs-identifier" and dimension "{}"
And The node "sir-david-nodenborough" in content stream "cs-identifier" and dimension "{}" should resolve to URL "/david-nodenborough"
And The node "earl-o-documentbourgh" in content stream "cs-identifier" and dimension "{}" should resolve to URL "/david-nodenborough/earl-document"

Scenario: Re-enable the same node twice
When the command "DisableNodeAggregate" is executed with payload:
| Key | Value |
Expand Down
49 changes: 49 additions & 0 deletions Neos.Neos/Tests/Functional/Command/CrCommandControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Neos.Neos package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

declare(strict_types=1);

namespace Neos\Neos\Tests\Functional\Command;

use Neos\ContentRepository\Core\Factory\ContentRepositoryId;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Tests\FunctionalTestCase;
use Neos\Neos\Command\CrCommandController;
use Neos\Utility\Arrays;

class CrCommandControllerTest extends FunctionalTestCase
{
private CrCommandController $subject;

private ContentRepositoryRegistry $contentRepositoryRegistry;

public function setUp(): void
{
parent::setUp();
$this->subject = $this->objectManager->get(CrCommandController::class);
$this->contentRepositoryRegistry = $this->objectManager->get(ContentRepositoryRegistry::class);
}

public function testImportThenExport()
{
$this->contentRepositoryRegistry->get(ContentRepositoryId::fromString('default'))->setUp();
$sourcePath = __DIR__ . '/../Fixtures';
$this->subject->importCommand($sourcePath);
$targetPath = FLOW_PATH_DATA . 'Temporary';
$this->subject->exportCommand($targetPath);

$expectedEvents = Arrays::trimExplode("\n", file_get_contents($sourcePath. '/events.jsonl'));
$actualEvents = Arrays::trimExplode("\n", file_get_contents($targetPath. '/events.jsonl'));

self::assertSame(count($expectedEvents), count($actualEvents));
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved
}
}
3 changes: 3 additions & 0 deletions Neos.Neos/Tests/Functional/Fixtures/events.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"identifier":"5f2da12d-7037-4524-acb0-d52037342c77","type":"ContentStreamWasCreated","payload":{"contentStreamId":"6ea2f6e1-4c9c-44f9-8a86-991705d13770"},"metadata":[]}
{"identifier":"9f64c281-e5b0-48d9-900b-288a8faf92a9","type":"RootNodeAggregateWithNodeWasCreated","payload":{"contentStreamId":"6ea2f6e1-4c9c-44f9-8a86-991705d13770","nodeAggregateId":"acme-site-sites","nodeTypeName":"Neos.Neos:Sites","coveredDimensionSpacePoints":[[]],"nodeAggregateClassification":"root"},"metadata":[]}
{"identifier":"1640ebbf-7ffe-4526-b0f4-7575cefabfab","type":"NodeAggregateWithNodeWasCreated","payload":{"contentStreamId":"6ea2f6e1-4c9c-44f9-8a86-991705d13770","nodeAggregateId":"acme-site","nodeTypeName":"Neos.Neos:Site","originDimensionSpacePoint":[],"coveredDimensionSpacePoints":[[]],"parentNodeAggregateId":"acme-site-sites","nodeName":"acme-site","initialPropertyValues":{"title":{"value":"My Site","type":"string"},"uriPathSegment":{"value":"my-site","type":"string"}},"nodeAggregateClassification":"regular","succeedingNodeAggregateId":null},"metadata":[]}
Loading