Skip to content

Commit

Permalink
TASK: Make migration independent of workspaceService
Browse files Browse the repository at this point in the history
Otherwise, we would be implicitly still relying on the workspace finder and up-to-date projections
  • Loading branch information
mhsdesign committed Oct 1, 2024
1 parent 686ff3d commit 5c3e817
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use Neos\Neos\Domain\Model\WorkspaceClassification;
use Neos\Neos\Domain\Model\WorkspaceRole;
use Neos\Neos\Domain\Model\WorkspaceSubjectType;
use Neos\Neos\Domain\Service\WorkspaceService;

/**
* Content Repository service to perform migrations of events.
Expand All @@ -52,8 +51,7 @@ final class EventMigrationService implements ContentRepositoryServiceInterface
public function __construct(
private readonly ContentRepositoryId $contentRepositoryId,
private readonly EventStoreInterface $eventStore,
private readonly Connection $connection,
private readonly WorkspaceService $workspaceService,
private readonly Connection $connection
) {
}

Expand Down Expand Up @@ -585,12 +583,19 @@ public function migrateWorkspaceMetadataToWorkspaceService(\Closure $outputFn):
$isPersonalWorkspace = str_starts_with($workspaceName->value, 'user-');
$isPrivateWorkspace = $workspaceOwner !== null && !$isPersonalWorkspace;
$isInternalWorkspace = $baseWorkspaceName !== null && $workspaceOwner === null;
try {
$this->workspaceService->getWorkspaceMetadata($this->contentRepositoryId, $workspaceName);

$query = <<<SQL
SELECT COUNT(1) FROM neos_neos_workspace_metadata WHERE
content_repository_id = :contentRepositoryId
AND workspace_name = :workspaceName
SQL;
$metadataExists = $this->connection->fetchOne($query, [
'contentRepositoryId' => $this->contentRepositoryId->value,
'workspaceName' => $workspaceName->value,
]);
if ($metadataExists !== 0) {
$outputFn(sprintf('Metadata for "%s" exists already.', $workspaceName->value));
continue;
} catch (\Exception $e) {
// metadata does not exist yet
}
if ($baseWorkspaceName === null) {
$classification = WorkspaceClassification::ROOT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Neos\ContentRepositoryRegistry\Command\MigrateEventsCommandController;
use Neos\EventStore\DoctrineAdapter\DoctrineEventStore;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Service\WorkspaceService;

/**
* Factory for the {@see EventMigrationService}
Expand All @@ -22,8 +21,7 @@
final class EventMigrationServiceFactory implements ContentRepositoryServiceFactoryInterface
{
public function __construct(
private readonly Connection $connection,
private readonly WorkspaceService $workspaceService
private readonly Connection $connection
) {
}

Expand All @@ -36,8 +34,7 @@ public function build(ContentRepositoryServiceFactoryDependencies $serviceFactor
return new EventMigrationService(
$serviceFactoryDependencies->contentRepositoryId,
$serviceFactoryDependencies->eventStore,
$this->connection,
$this->workspaceService,
$this->connection
);
}
}

0 comments on commit 5c3e817

Please sign in to comment.