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..d51eabd5ef2 100644 --- a/Neos.ContentRepositoryRegistry/Classes/Service/EventMigrationService.php +++ b/Neos.ContentRepositoryRegistry/Classes/Service/EventMigrationService.php @@ -367,6 +367,44 @@ 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(); + $statement = <<connection->executeStatement($statement); + $this->connection->commit(); + + if ($affectedRows === 0) { + $outputFn('Migration was not necessary.'); + return; + } + + $outputFn(); + $outputFn(sprintf('Migration applied to %s events.', $affectedRows)); + } + /** ------------------------ */ /**