Skip to content

Commit

Permalink
TASK: Ensure that all Publish-related command handlers throw `Conflic…
Browse files Browse the repository at this point in the history
…tsOccurred`
  • Loading branch information
grebaldi committed Apr 22, 2024
1 parent 4f503a2 commit 8e4a03d
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Neos\Neos\Ui\Application\PublishChangesInDocument;

use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
Expand All @@ -32,18 +33,22 @@ public function __construct(
public ContentRepositoryId $contentRepositoryId,
public WorkspaceName $workspaceName,
public NodeAggregateId $documentId,
public ?DimensionSpacePoint $preferredDimensionSpacePoint,
) {
}

/**
* @param array<string,string> $values
* @param array{contentRepositoryId:string,workspaceName:string,documentId:string,preferredDimensionSpacePoint?:array<string,string[]>} $values
*/
public static function fromArray(array $values): self
{
return new self(
ContentRepositoryId::fromString($values['contentRepositoryId']),
WorkspaceName::fromString($values['workspaceName']),
NodeAggregateId::fromString($values['documentId']),
isset($values['preferredDimensionSpacePoint']) && !empty($values['preferredDimensionSpacePoint'])
? DimensionSpacePoint::fromLegacyDimensionArray($values['preferredDimensionSpacePoint'])
: null,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@

namespace Neos\Neos\Ui\Application\PublishChangesInDocument;

use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Exception\WorkspaceRebaseFailed;
use Neos\ContentRepository\Core\SharedModel\Exception\NodeAggregateCurrentlyDoesNotExist;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Workspace\WorkspaceProvider;
use Neos\Neos\Ui\Application\Shared\Conflicts;
use Neos\Neos\Ui\Application\Shared\ConflictsOccurred;
use Neos\Neos\Ui\Application\Shared\PublishSucceeded;

/**
Expand All @@ -28,6 +32,9 @@
#[Flow\Scope("singleton")]
final class PublishChangesInDocumentCommandHandler
{
#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

#[Flow\Inject]
protected WorkspaceProvider $workspaceProvider;

Expand All @@ -52,6 +59,22 @@ public function handle(PublishChangesInDocumentCommand $command): PublishSucceed
'Node could not be published, probably because of a missing parentNode. Please check that the parentNode has been published.',
1682762156
);
} catch (WorkspaceRebaseFailed $e) {
$conflictsBuilder = Conflicts::builder(
contentRepository: $this->contentRepositoryRegistry
->get($command->contentRepositoryId),
workspaceName: $command->workspaceName,
preferredDimensionSpacePoint: $command->preferredDimensionSpacePoint
);

foreach ($e->commandsThatFailedDuringRebase as $commandThatFailedDuringRebase) {
$conflictsBuilder->addCommandThatFailedDuringRebase($commandThatFailedDuringRebase);
}

throw new ConflictsOccurred(
$conflictsBuilder->build(),
1712832228
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Neos\Neos\Ui\Application\PublishChangesInSite;

use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
Expand All @@ -32,18 +33,22 @@ public function __construct(
public ContentRepositoryId $contentRepositoryId,
public WorkspaceName $workspaceName,
public NodeAggregateId $siteId,
public ?DimensionSpacePoint $preferredDimensionSpacePoint,
) {
}

/**
* @param array<string,string> $values
* @param array{contentRepositoryId:string,workspaceName:string,siteId:string,preferredDimensionSpacePoint?:array<string,string[]>} $values
*/
public static function fromArray(array $values): self
{
return new self(
ContentRepositoryId::fromString($values['contentRepositoryId']),
WorkspaceName::fromString($values['workspaceName']),
NodeAggregateId::fromString($values['siteId']),
isset($values['preferredDimensionSpacePoint']) && !empty($values['preferredDimensionSpacePoint'])
? DimensionSpacePoint::fromLegacyDimensionArray($values['preferredDimensionSpacePoint'])
: null,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@

namespace Neos\Neos\Ui\Application\PublishChangesInSite;

use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Exception\WorkspaceRebaseFailed;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Workspace\WorkspaceProvider;
use Neos\Neos\Ui\Application\Shared\Conflicts;
use Neos\Neos\Ui\Application\Shared\ConflictsOccurred;
use Neos\Neos\Ui\Application\Shared\PublishSucceeded;

/**
Expand All @@ -27,20 +31,41 @@
#[Flow\Scope("singleton")]
final class PublishChangesInSiteCommandHandler
{
#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

#[Flow\Inject]
protected WorkspaceProvider $workspaceProvider;

public function handle(PublishChangesInSiteCommand $command): PublishSucceeded
{
$workspace = $this->workspaceProvider->provideForWorkspaceName(
$command->contentRepositoryId,
$command->workspaceName
);
$publishingResult = $workspace->publishChangesInSite($command->siteId);

return new PublishSucceeded(
numberOfAffectedChanges: $publishingResult->numberOfPublishedChanges,
baseWorkspaceName: $workspace->getCurrentBaseWorkspaceName()?->value
);
try {
$workspace = $this->workspaceProvider->provideForWorkspaceName(
$command->contentRepositoryId,
$command->workspaceName
);
$publishingResult = $workspace->publishChangesInSite($command->siteId);

return new PublishSucceeded(
numberOfAffectedChanges: $publishingResult->numberOfPublishedChanges,
baseWorkspaceName: $workspace->getCurrentBaseWorkspaceName()?->value
);
} catch (WorkspaceRebaseFailed $e) {
$conflictsBuilder = Conflicts::builder(
contentRepository: $this->contentRepositoryRegistry
->get($command->contentRepositoryId),
workspaceName: $command->workspaceName,
preferredDimensionSpacePoint: $command->preferredDimensionSpacePoint
);

foreach ($e->commandsThatFailedDuringRebase as $commandThatFailedDuringRebase) {
$conflictsBuilder->addCommandThatFailedDuringRebase($commandThatFailedDuringRebase);
}

throw new ConflictsOccurred(
$conflictsBuilder->build(),
1712832228
);
}
}
}
4 changes: 2 additions & 2 deletions Classes/Controller/BackendServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function changeAction(array $changes): void
/**
* Publish all changes in the current site
*
* @phpstan-param array<string,string> $command
* @phpstan-param array{workspaceName:string,siteId:string,preferredDimensionSpacePoint?:array<string,string[]>} $command
*/
public function publishChangesInSiteAction(array $command): void
{
Expand Down Expand Up @@ -236,7 +236,7 @@ public function publishChangesInSiteAction(array $command): void
/**
* Publish all changes in the current document
*
* @phpstan-param array<string,string> $command
* @phpstan-param array{workspaceName:string,documentId:string,preferredDimensionSpacePoint?:array<string,string[]>} $command
*/
public function publishChangesInDocumentAction(array $command): void
{
Expand Down
8 changes: 4 additions & 4 deletions packages/neos-ui-backend-connector/src/Endpoints/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default (routes: Routes) => {
})).then(response => fetchWithErrorHandling.parseJson(response))
.catch(reason => fetchWithErrorHandling.generalErrorHandler(reason));

const publishChangesInSite = (siteId: NodeContextPath, workspaceName: WorkspaceName) => fetchWithErrorHandling.withCsrfToken(csrfToken => ({
const publishChangesInSite = (siteId: NodeContextPath, workspaceName: WorkspaceName, preferredDimensionSpacePoint: null|DimensionCombination) => fetchWithErrorHandling.withCsrfToken(csrfToken => ({
url: routes.ui.service.publishChangesInSite,
method: 'POST',
credentials: 'include',
Expand All @@ -78,12 +78,12 @@ export default (routes: Routes) => {
'Content-Type': 'application/json'
},
body: JSON.stringify({
command: {siteId, workspaceName}
command: {siteId, workspaceName, preferredDimensionSpacePoint}
})
})).then(response => fetchWithErrorHandling.parseJson(response))
.catch(reason => fetchWithErrorHandling.generalErrorHandler(reason));

const publishChangesInDocument = (documentId: NodeContextPath, workspaceName: WorkspaceName) => fetchWithErrorHandling.withCsrfToken(csrfToken => ({
const publishChangesInDocument = (documentId: NodeContextPath, workspaceName: WorkspaceName, preferredDimensionSpacePoint: null|DimensionCombination) => fetchWithErrorHandling.withCsrfToken(csrfToken => ({
url: routes.ui.service.publishChangesInDocument,
method: 'POST',
credentials: 'include',
Expand All @@ -92,7 +92,7 @@ export default (routes: Routes) => {
'Content-Type': 'application/json'
},
body: JSON.stringify({
command: {documentId, workspaceName}
command: {documentId, workspaceName, preferredDimensionSpacePoint}
})
})).then(response => fetchWithErrorHandling.parseJson(response))
.catch(reason => fetchWithErrorHandling.generalErrorHandler(reason));
Expand Down
5 changes: 3 additions & 2 deletions packages/neos-ui-sagas/src/Publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import {put, call, select, takeEvery, take, race, all} from 'redux-saga/effects';

import {AnyError} from '@neos-project/neos-ui-error';
import {NodeContextPath, WorkspaceName} from '@neos-project/neos-ts-interfaces';
import {DimensionCombination, NodeContextPath, WorkspaceName} from '@neos-project/neos-ts-interfaces';
import {actionTypes, actions, selectors} from '@neos-project/neos-ui-redux-store';
import {GlobalState} from '@neos-project/neos-ui-redux-store/src/System';
import {FeedbackEnvelope} from '@neos-project/neos-ui-redux-store/src/ServerFeedback';
Expand Down Expand Up @@ -83,6 +83,7 @@ export function * watchPublishing({routes}: {routes: Routes}) {
const {ancestorIdSelector} = SELECTORS_BY_SCOPE[scope];

const workspaceName: WorkspaceName = yield select(selectors.CR.Workspaces.personalWorkspaceNameSelector);
const dimensionSpacePoint: null|DimensionCombination = yield select(selectors.CR.ContentDimensions.active);
const ancestorId: NodeContextPath = ancestorIdSelector
? yield select(ancestorIdSelector)
: null;
Expand All @@ -92,7 +93,7 @@ export function * watchPublishing({routes}: {routes: Routes}) {
window.addEventListener('beforeunload', handleWindowBeforeUnload);
const result: PublishingResponse = scope === PublishingScope.ALL
? yield call(endpoint as any, workspaceName)
: yield call(endpoint, ancestorId, workspaceName);
: yield call(endpoint, ancestorId, workspaceName, dimensionSpacePoint);

if ('success' in result) {
yield put(actions.CR.Publishing.succeed(result.success.numberOfAffectedChanges));
Expand Down

0 comments on commit 8e4a03d

Please sign in to comment.