Skip to content

Commit

Permalink
Fix deprecated collate to collation
Browse files Browse the repository at this point in the history
  • Loading branch information
zonky2 committed Oct 21, 2022
1 parent 014cffa commit bf4e90c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"contao/core-bundle": "^4.13.0, <5.0",
"discordier/justtextwidgets": "^1.2",
"doctrine/cache": "^2.1",
"doctrine/dbal": "^3.3.2",
"menatwork/contao-multicolumnwizard-bundle": "^3.4",
"symfony/asset": "^5.4",
"symfony/cache": "^5.4",
Expand Down
18 changes: 11 additions & 7 deletions src/CoreBundle/Migration/TableCollationMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getName(): string
{
return \sprintf(
'Change collation to %1$s and/or DB engine to %2$s of all mm_* tables.',
$this->defaultTableOptions['collate'],
$this->defaultTableOptions['collation'],
$this->defaultTableOptions['engine']
);
}
Expand All @@ -76,9 +76,10 @@ public function getName(): string
* Must only run if:
* - the mm_* tables are present AND
* - there collation is not utf8mb4_unicode_ci OR
* - these engine is not InnoDB.
* - the engine is not InnoDB.
*
* @return bool
* @throws \Doctrine\DBAL\Exception
*/
public function shouldRun(): bool
{
Expand All @@ -94,6 +95,7 @@ public function shouldRun(): bool
* Collect the tables to be updated and update them.
*
* @return MigrationResult
* @throws \Doctrine\DBAL\Exception
*/
public function run(): MigrationResult
{
Expand All @@ -111,6 +113,7 @@ public function run(): MigrationResult
* Fetch all tables that are not right collection or DB engine yet.
*
* @return array
* @throws \Doctrine\DBAL\Exception
*/
private function fetchPendingTables(): array
{
Expand All @@ -120,17 +123,17 @@ private function fetchPendingTables(): array
$results = [];
foreach ($tableNames as $tableName) {
// Only MM model tables.
if ('mm_' !== substr($tableName, 0, 3)) {
if ('mm_' !== \substr($tableName, 0, 3)) {
continue;
}

// Retrieve table data.
$result = $this->connection
->executeQuery(sprintf('SHOW TABLE STATUS LIKE \'%1$s\'', $tableName))
->fetch();
->fetchAllAssociative();

// Check collation and DB engine and collect tables with false data.
if (($this->defaultTableOptions['collate'] !== $result['Collation'])
if (($this->defaultTableOptions['collation'] !== $result['Collation'])
|| ($this->defaultTableOptions['engine'] !== $result['Engine'])
) {
$results[] = $tableName;
Expand All @@ -146,19 +149,20 @@ private function fetchPendingTables(): array
* @param string $tableName The name of the table.
*
* @return void
* @throws \Doctrine\DBAL\Exception
*/
private function fixTable(string $tableName): void
{
$this->connection->executeQuery(
sprintf(
\sprintf(
'ALTER TABLE %1$s
ENGINE=%2$s
DEFAULT CHARSET=%3$s COLLATE %4$s
ROW_FORMAT=DYNAMIC',
$tableName,
$this->defaultTableOptions['engine'],
$this->defaultTableOptions['charset'],
$this->defaultTableOptions['collate']
$this->defaultTableOptions['collation']
)
);
}
Expand Down

0 comments on commit bf4e90c

Please sign in to comment.