Skip to content

Commit

Permalink
TASK: Apply review suggestions
Browse files Browse the repository at this point in the history
- Update Neos.ContentRepository.Core/Classes/Feature/Common/ContentStreamIdOverride.php
- Update Neos.ContentRepositoryRegistry/Classes/Service/EventMigrationService.php

Co-authored-by: Bastian Waidelich <b.waidelich@wwwision.de>
  • Loading branch information
2 people authored and ahaeslich committed Mar 15, 2024
1 parent 43827ba commit 8cd2f1d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function requireContentStream(
WorkspaceName $workspaceName,
ContentRepository $contentRepository
): ContentStreamId {
$contentStreamId = ContentStreamIdOverride::findContentStreamIdForWorkspace($contentRepository, $workspaceName);
$contentStreamId = ContentStreamIdOverride::resolveContentStreamIdForWorkspace($contentRepository, $workspaceName);
if (!$contentRepository->getContentStreamFinder()->hasContentStream($contentStreamId)) {
throw new ContentStreamDoesNotExistYet(
'Content stream "' . $contentStreamId->value . '" does not exist yet.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Neos\ContentRepository\Core\Feature\Common;

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\Feature\WorkspaceCommandHandler;
use Neos\ContentRepository\Core\SharedModel\Exception\ContentStreamDoesNotExistYet;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
Expand All @@ -25,32 +26,31 @@
class ContentStreamIdOverride
{
/**
* A content stream id that to use instead of the workspace one's {@see ConstraintChecks::requireContentStream()}
* A content stream id that is used instead of the workspace one's {@see ConstraintChecks::requireContentStream()}
*/
private static ?ContentStreamId $contentStreamIdToUse = null;

/**
* Makes the given content stream id available to be used in the given function {@see WorkspaceCommandHandler::handleRebaseWorkspace()}
* @internal
*/
public static function withContentStreamIdToUse(ContentStreamId $contentStreamIdToUse, \Closure $fn): void
public static function applyContentStreamIdToClosure(ContentStreamId $contentStreamIdToUse, \Closure $fn): void
{
if (self::$contentStreamIdToUse !== null) {
throw new \Exception('Recursive content stream override is not supported', 1710426945);
}
self::$contentStreamIdToUse = $contentStreamIdToUse;
try {
$fn();
} catch (\Throwable $th) {
} finally {
self::$contentStreamIdToUse = null;
throw $th;
}
self::$contentStreamIdToUse = null;
}

/**
* @internal
*/
public static function findContentStreamIdForWorkspace(ContentRepository $contentRepository, WorkspaceName $workspaceName): ContentStreamId
public static function resolveContentStreamIdForWorkspace(ContentRepository $contentRepository, WorkspaceName $workspaceName): ContentStreamId
{
$contentStreamId = self::$contentStreamIdToUse
?: $contentRepository->getWorkspaceFinder()->findOneByName($workspaceName)?->currentContentStreamId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ private function handleRebaseWorkspace(
// - extract the commands from the to-be-rebased content stream; and applies them on the new content stream
$originalCommands = $this->extractCommandsFromContentStreamMetadata($workspaceContentStreamName);
$rebaseStatistics = new WorkspaceRebaseStatistics();
ContentStreamIdOverride::withContentStreamIdToUse(
ContentStreamIdOverride::applyContentStreamIdToClosure(
$command->rebasedContentStreamId,
function () use ($originalCommands, $contentRepository, $rebaseStatistics, $workspaceContentStreamName, $baseWorkspace): void {
foreach ($originalCommands as $i => $originalCommand) {
Expand Down Expand Up @@ -531,7 +531,7 @@ private function handlePublishIndividualNodesFromWorkspace(

try {
// 4) using the new content stream, apply the matching commands
ContentStreamIdOverride::withContentStreamIdToUse(
ContentStreamIdOverride::applyContentStreamIdToClosure(
$command->contentStreamIdForMatchingPart,
function () use ($matchingCommands, $contentRepository, $baseWorkspace, $command): void {
foreach ($matchingCommands as $matchingCommand) {
Expand Down Expand Up @@ -565,7 +565,7 @@ function () use ($matchingCommands, $contentRepository, $baseWorkspace, $command
)->block();

// 7) apply REMAINING commands to the workspace's new content stream
ContentStreamIdOverride::withContentStreamIdToUse(
ContentStreamIdOverride::applyContentStreamIdToClosure(
$command->contentStreamIdForRemainingPart,
function () use ($contentRepository, $remainingCommands) {
foreach ($remainingCommands as $remainingCommand) {
Expand Down Expand Up @@ -668,7 +668,7 @@ private function handleDiscardIndividualNodesFromWorkspace(

// 4) using the new content stream, apply the commands to keep
try {
ContentStreamIdOverride::withContentStreamIdToUse(
ContentStreamIdOverride::applyContentStreamIdToClosure(
$command->newContentStreamId,
function () use ($commandsToKeep, $contentRepository, $baseWorkspace, $command): void {
foreach ($commandsToKeep as $matchingCommand) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function migratePropertiesToUnset(\Closure $outputFn)
$warnings = 0;

$backupEventTableName = DoctrineEventStoreFactory::databaseTableName($this->contentRepositoryId)
. '_bak_' . date('Y_m_d_H_i_s');
. '_bkp_' . date('Y_m_d_H_i_s');
$outputFn(sprintf('Backup: copying events table to %s', $backupEventTableName));

$this->copyEventTable($backupEventTableName);
Expand Down Expand Up @@ -251,7 +251,7 @@ public function migrateMetaDataToWorkspaceName(\Closure $outputFn)
$this->eventsModified = [];

$backupEventTableName = DoctrineEventStoreFactory::databaseTableName($this->contentRepositoryId)
. '_bak_' . date('Y_m_d_H_i_s');
. '_bkp_' . date('Y_m_d_H_i_s');
$outputFn('Backup: copying events table to %s', [$backupEventTableName]);

$this->copyEventTable($backupEventTableName);
Expand Down

0 comments on commit 8cd2f1d

Please sign in to comment.