Skip to content

Commit

Permalink
TASK: Simplify code and remove reopen cs logic into publishWorkspace
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Nov 9, 2024
1 parent 913ef45 commit 9c9f6b0
Showing 1 changed file with 40 additions and 42 deletions.
82 changes: 40 additions & 42 deletions Classes/Feature/WorkspaceCommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,19 @@ private function handlePublishWorkspace(
)
);

try {
yield from $this->publishWorkspace(
$workspace,
$baseWorkspace,
$baseWorkspaceContentStreamVersion,
$command->newContentStreamId,
$rebaseableCommands
);
} catch (WorkspaceRebaseFailed|ConcurrencyException $publishFailed) {
// todo catch all? Dont catch ANY ConcurrencyException because say if forking failed we dont need to reopen?
yield $this->reopenContentStreamWithoutConstraints(
$workspace->currentContentStreamId
);
throw $publishFailed;
}
yield from $this->publishWorkspace(
$workspace,
$baseWorkspace,
$baseWorkspaceContentStreamVersion,
$command->newContentStreamId,
$rebaseableCommands
);
}

/**
* Note that the workspaces content stream must be closed beforehand.
* It will be reopened here in case of error.
*/
private function publishWorkspace(
Workspace $workspace,
Workspace $baseWorkspace,
Expand All @@ -245,20 +241,29 @@ static function ($handle) use ($rebaseableCommands): void {
);

if ($commandSimulator->hasCommandsThatFailed()) {
yield $this->reopenContentStreamWithoutConstraints(
$workspace->currentContentStreamId
);
throw WorkspaceRebaseFailed::duringPublish($commandSimulator->getCommandsThatFailed());
}

// todo throw base workspace was modified in the meantime to distinguish exception above to reopen?
$commitResult = yield new EventsToPublish(
ContentStreamEventStreamName::fromContentStreamId($baseWorkspace->currentContentStreamId)
->getEventStreamName(),
$this->getCopiedEventsOfEventStream(
$baseWorkspace->workspaceName,
$baseWorkspace->currentContentStreamId,
$commandSimulator->eventStream(),
),
ExpectedVersion::fromVersion($baseWorkspaceContentStreamVersion)
);
try {
$commitResult = yield new EventsToPublish(
ContentStreamEventStreamName::fromContentStreamId($baseWorkspace->currentContentStreamId)
->getEventStreamName(),
$this->getCopiedEventsOfEventStream(
$baseWorkspace->workspaceName,
$baseWorkspace->currentContentStreamId,
$commandSimulator->eventStream(),
),
ExpectedVersion::fromVersion($baseWorkspaceContentStreamVersion)
);
} catch (ConcurrencyException $concurrencyException) {
yield $this->reopenContentStreamWithoutConstraints(
$workspace->currentContentStreamId
);
throw $concurrencyException;
}

yield $this->forkContentStream(
$newContentStreamId,
Expand Down Expand Up @@ -474,22 +479,15 @@ private function handlePublishIndividualNodesFromWorkspace(
}

if ($remainingCommands->isEmpty()) {
try {
// do a full publish, this is simpler for the projections to handle
yield from $this->publishWorkspace(
$workspace,
$baseWorkspace,
$baseWorkspaceContentStreamVersion,
$command->contentStreamIdForRemainingPart,
$matchingCommands
);
return;
} catch (WorkspaceRebaseFailed $workspaceRebaseFailed) {
yield $this->reopenContentStreamWithoutConstraints(
$workspace->currentContentStreamId
);
throw $workspaceRebaseFailed;
}
// do a full publish, this is simpler for the projections to handle
yield from $this->publishWorkspace(
$workspace,
$baseWorkspace,
$baseWorkspaceContentStreamVersion,
$command->contentStreamIdForRemainingPart,
$matchingCommands
);
return;
}

$commandSimulator = $this->commandSimulatorFactory->createSimulatorForWorkspace($baseWorkspace->workspaceName);
Expand Down

0 comments on commit 9c9f6b0

Please sign in to comment.