Skip to content

Commit

Permalink
TASK: Ensure migration works case sensitive and will end in a workspa…
Browse files Browse the repository at this point in the history
…ceName with a leading letter. Also applying to baseWorkspaceName.
  • Loading branch information
dlubitz committed Aug 15, 2024
1 parent f782401 commit 4ef9987
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,24 +385,35 @@ public function migratePayloadToValidWorkspaceNames(\Closure $outputFn): void

$eventTableName = DoctrineEventStoreFactory::databaseTableName($this->contentRepositoryId);
$this->connection->beginTransaction();
$statement = <<<SQL
$statementWorkspaceName = <<<SQL
UPDATE {$eventTableName}
SET
payload = JSON_SET(payload, '$.workspaceName', SUBSTR(MD5(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName'))), 1, 30))
payload = JSON_SET(payload, '$.workspaceName', LEFT(CONCAT('w', MD5(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName')))), 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}$'
AND BINARY JSON_UNQUOTE(JSON_EXTRACT(payload, '$.workspaceName')) NOT REGEXP '^[a-z][a-z0-9\-]{0,30}$'
SQL;
$affectedRows = $this->connection->executeStatement($statement);
$affectedRowsWorkspaceName = $this->connection->executeStatement($statementWorkspaceName);

$statementBaseWorkspaceName = <<<SQL
UPDATE {$eventTableName}
SET
payload = JSON_SET(payload, '$.baseWorkspaceName', LEFT(CONCAT('w', MD5(JSON_UNQUOTE(JSON_EXTRACT(payload, '$.baseWorkspaceName')))), 30))
WHERE
JSON_EXTRACT(payload, '$.baseWorkspaceName') IS NOT NULL
AND BINARY JSON_UNQUOTE(JSON_EXTRACT(payload, '$.baseWorkspaceName')) NOT REGEXP '^[a-z][a-z0-9\-]{0,30}$'
SQL;
$affectedRowsBaseWorkspaceName = $this->connection->executeStatement($statementBaseWorkspaceName);
$this->connection->commit();

if ($affectedRows === 0) {
if ($affectedRowsWorkspaceName + $affectedRowsBaseWorkspaceName === 0) {

Check failure on line 409 in Neos.ContentRepositoryRegistry/Classes/Service/EventMigrationService.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Binary operation "+" between int|string and int|string results in an error.

Check failure on line 409 in Neos.ContentRepositoryRegistry/Classes/Service/EventMigrationService.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test linting-unit-functionaltests-mysql (deps: highest)

Binary operation "+" between int|string and int|string results in an error.
$outputFn('Migration was not necessary.');
return;
}

$outputFn();
$outputFn(sprintf('Migration applied to %s events.', $affectedRows));
$outputFn(sprintf('Migration applied to %s events and changed the workspaceName.', $affectedRowsWorkspaceName));
$outputFn(sprintf('Migration applied to %s events and changed the baseWorkspaceName.', $affectedRowsBaseWorkspaceName));
}

/** ------------------------ */
Expand Down

0 comments on commit 4ef9987

Please sign in to comment.