From d43826e558d5db5f8af54e39c623702896a5437f Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Thu, 15 Aug 2024 12:29:19 +0200 Subject: [PATCH] TASK: Ensure migration works case sensitive and will end in a workspaceName with a leading letter. Also applying to baseWorkspaceName. --- .../MigrateEventsCommandController.php | 16 ++++++ .../Classes/Service/EventMigrationService.php | 49 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/Neos.ContentRepositoryRegistry/Classes/Command/MigrateEventsCommandController.php b/Neos.ContentRepositoryRegistry/Classes/Command/MigrateEventsCommandController.php index d3a5ec19d3d..413290f86b7 100644 --- a/Neos.ContentRepositoryRegistry/Classes/Command/MigrateEventsCommandController.php +++ b/Neos.ContentRepositoryRegistry/Classes/Command/MigrateEventsCommandController.php @@ -64,4 +64,20 @@ public function migratePayloadToWorkspaceNameCommand(string $contentRepository = $eventMigrationService = $this->contentRepositoryRegistry->buildService($contentRepositoryId, $this->eventMigrationServiceFactory); $eventMigrationService->migratePayloadToWorkspaceName($this->outputLine(...)); } + + /** + * Rewrites all workspaceNames, that are not matching new constraints. + * + * Needed for feature "Stabilize WorkspaceName value object": https://github.com/neos/neos-development-collection/pull/5193 + * + * Included in August 2024 - before final Neos 9.0 release + * + * @param string $contentRepository Identifier of the Content Repository to migrate + */ + public function migratePayloadToValidWorkspaceNamesCommand(string $contentRepository = 'default'): void + { + $contentRepositoryId = ContentRepositoryId::fromString($contentRepository); + $eventMigrationService = $this->contentRepositoryRegistry->buildService($contentRepositoryId, $this->eventMigrationServiceFactory); + $eventMigrationService->migratePayloadToValidWorkspaceNames($this->outputLine(...)); + } } diff --git a/Neos.ContentRepositoryRegistry/Classes/Service/EventMigrationService.php b/Neos.ContentRepositoryRegistry/Classes/Service/EventMigrationService.php index f865d275860..50eb79b7315 100644 --- a/Neos.ContentRepositoryRegistry/Classes/Service/EventMigrationService.php +++ b/Neos.ContentRepositoryRegistry/Classes/Service/EventMigrationService.php @@ -367,6 +367,55 @@ public function migratePayloadToWorkspaceName(\Closure $outputFn): void $outputFn(sprintf('Migration applied to %s events.', $numberOfMigratedEvents)); } + /** + * Rewrites all workspaceNames, that are not matching new constraints. + * + * Needed for feature "Stabilize WorkspaceName value object": https://github.com/neos/neos-development-collection/pull/5193 + * + * Included in August 2024 - before final Neos 9.0 release + * + * @param \Closure $outputFn + * @return void + */ + public function migratePayloadToValidWorkspaceNames(\Closure $outputFn): void + { + $backupEventTableName = DoctrineEventStoreFactory::databaseTableName($this->contentRepositoryId) . '_bkp_' . date('Y_m_d_H_i_s'); + $outputFn('Backup: copying events table to %s', [$backupEventTableName]); + $this->copyEventTable($backupEventTableName); + + $eventTableName = DoctrineEventStoreFactory::databaseTableName($this->contentRepositoryId); + $this->connection->beginTransaction(); + $statementWorkspaceName = <<connection->executeStatement($statementWorkspaceName); + + $statementBaseWorkspaceName = <<connection->executeStatement($statementBaseWorkspaceName); + $this->connection->commit(); + + if ($affectedRowsWorkspaceName + $affectedRowsBaseWorkspaceName === 0) { + $outputFn('Migration was not necessary.'); + return; + } + + $outputFn(); + $outputFn(sprintf('Migration applied to %s events and changed the workspaceName.', $affectedRowsWorkspaceName)); + $outputFn(sprintf('Migration applied to %s events and changed the baseWorkspaceName.', $affectedRowsBaseWorkspaceName)); + } + /** ------------------------ */ /**