Skip to content

Commit

Permalink
Merge pull request #5202 from dlubitz/task/5201-workspacename-migration
Browse files Browse the repository at this point in the history
TASK: Add migration for workspaceName constraints
  • Loading branch information
kitsunet authored Aug 15, 2024
2 parents b2d5f28 + a8977db commit 380a945
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(...));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<<SQL
UPDATE {$eventTableName}
SET
payload = JSON_SET(payload, '$.workspaceName', SUBSTR(MD5(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName'))), 1, 30))
WHERE
JSON_EXTRACT(payload, '$.workspaceName') IS NOT NULL
AND JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName')) NOT REGEXP '^[a-z][a-z0-9\-]{0,30}$'
SQL;
$affectedRows = $this->connection->executeStatement($statement);
$this->connection->commit();

if ($affectedRows === 0) {
$outputFn('Migration was not necessary.');
return;
}

$outputFn();
$outputFn(sprintf('Migration applied to %s events.', $affectedRows));
}

/** ------------------------ */

/**
Expand Down

0 comments on commit 380a945

Please sign in to comment.