Skip to content

Commit a3e74e8

Browse files
committed
AC-9755:Set default collation to utf8mb4 for MySQL
1 parent 0be2cb2 commit a3e74e8

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

app/code/Magento/Theme/Model/Indexer/Design/IndexerHandler.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class IndexerHandler extends Grid
2929
/***
3030
* Old Charset for flat table
3131
*/
32-
private const OLDCHARSET = 'utf8mb3';
32+
private const OLDCHARSET = 'utf8|utf8mb3';
3333

3434
/***
3535
* table design_config_grid_flat
@@ -88,9 +88,8 @@ public function cleanIndex($dimensions)
8888
$this->connection->delete($tableName);
8989
// change the charset to utf8mb4
9090
if ($tableName === self::DESIGN_CONFIG_GRID_FLAT) {
91-
$getTableSchema = $this->connection->showTableStatus($tableName);
92-
$collation = $getTableSchema['Collation'] ?? '';
93-
if (str_contains($collation, self::OLDCHARSET)) {
91+
$getTableSchema = $this->connection->getCreateTable($tableName) ?? '';
92+
if (preg_match('/\b('. self::OLDCHARSET .')\b/', $getTableSchema)) {
9493
$charset = $this->columnConfig->getDefaultCharset();
9594
$collate = $this->columnConfig->getDefaultCollation();
9695
$columnEncoding = " CHARACTER SET ".$charset." COLLATE ".$collate;

lib/internal/Magento/Framework/Mview/View/Changelog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Changelog implements ChangelogInterface
6969
/***
7070
* Old Charset for cl tables
7171
*/
72-
private const OLDCHARSET = 'utf8mb3';
72+
private const OLDCHARSET = 'utf8|utf8mb3';
7373

7474
/***
7575
* @var DtoFactoriesTable|null
@@ -149,7 +149,7 @@ public function create()
149149
} else {
150150
// change the charset to utf8mb4
151151
$getTableSchema = $this->connection->getCreateTable($changelogTableName) ?? '';
152-
if (str_contains($getTableSchema, self::OLDCHARSET)) {
152+
if (preg_match('/\b('. self::OLDCHARSET .')\b/', $getTableSchema)) {
153153
$charset = $this->columnConfig->getDefaultCharset();
154154
$collate = $this->columnConfig->getDefaultCollation();
155155
$this->connection->query(

lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Factories/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Table implements FactoryInterface
4848
* @var array|string[]
4949
*/
5050
private static array $defaultCharset = [
51-
'10.4.' => 'utf8',
51+
'10.4.' => 'utf8mb4',
5252
'10.6.' => 'utf8mb4',
5353
'11.4.' => 'utf8mb4',
5454
'mysql_8_29' => 'utf8mb4',
@@ -59,7 +59,7 @@ class Table implements FactoryInterface
5959
* @var array|string[]
6060
*/
6161
private static array $defaultCollation = [
62-
'10.4.' => 'utf8_general_ci',
62+
'10.4.' => 'utf8mb4_general_ci',
6363
'10.6.' => 'utf8mb4_general_ci',
6464
'11.4.' => 'utf8mb4_general_ci',
6565
'mysql_8_29' => 'utf8mb4_general_ci',

setup/src/Magento/Setup/Model/Installer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class Installer
263263
/***
264264
* Old Charset for cl tables
265265
*/
266-
private const OLDCHARSET = 'utf8mb3';
266+
private const OLDCHARSET = 'utf8|utf8mb3';
267267

268268
/***
269269
* @var DtoFactoriesTable
@@ -662,7 +662,7 @@ private function setupModuleRegistry(SchemaSetupInterface $setup)
662662
} else {
663663
// change the charset to utf8mb4
664664
$getTableSchema = $connection->getCreateTable($setup->getTable('setup_module')) ?? '';
665-
if (str_contains($getTableSchema, self::OLDCHARSET)) {
665+
if (preg_match('/\b('. self::OLDCHARSET .')\b/', $getTableSchema)) {
666666
$tableName = $setup->getTable('setup_module');
667667
$columns = ['module' => ['varchar(50)',''],
668668
'schema_version' => ['varchar(50)',''],
@@ -731,7 +731,7 @@ private function setupSessionTable(
731731
} else {
732732
// change the charset to utf8mb4
733733
$getTableSchema = $connection->getCreateTable($setup->getTable('session')) ?? '';
734-
if (str_contains($getTableSchema, self::OLDCHARSET)) {
734+
if (preg_match('/\b('. self::OLDCHARSET .')\b/', $getTableSchema)) {
735735
$tableName = $setup->getTable('session');
736736
$columns = ['session_id' => ['varchar(255)','']];
737737
$this->updateDBTable($tableName, $columns, $connection);
@@ -794,7 +794,7 @@ private function setupCacheTable(
794794
} else {
795795
// change the charset to utf8mb4
796796
$getTableSchema = $connection->getCreateTable($setup->getTable('cache')) ?? '';
797-
if (str_contains($getTableSchema, self::OLDCHARSET)) {
797+
if (preg_match('/\b('. self::OLDCHARSET .')\b/', $getTableSchema)) {
798798
$tableName = $setup->getTable('cache');
799799
$columns = ['id' => ['varchar(200)','']];
800800
$this->updateDBTable($tableName, $columns, $connection);
@@ -839,7 +839,7 @@ private function setupCacheTagTable(
839839
} else {
840840
// change the charset to utf8mb4
841841
$getTableSchema = $connection->getCreateTable($setup->getTable('cache_tag')) ?? '';
842-
if (str_contains($getTableSchema, self::OLDCHARSET)) {
842+
if (preg_match('/\b('. self::OLDCHARSET .')\b/', $getTableSchema)) {
843843
$tableName = $setup->getTable('cache_tag');
844844
$columns = ['tag' => ['varchar(100)',''],'cache_id' => ['varchar(200)','']];
845845
$this->updateDBTable($tableName, $columns, $connection);
@@ -904,7 +904,7 @@ private function setupFlagTable(
904904
$this->updateColumnType($connection, $tableName, 'flag_data', 'mediumtext');
905905
// change the charset to utf8mb4
906906
$getTableSchema = $connection->getCreateTable($tableName) ?? '';
907-
if (str_contains($getTableSchema, self::OLDCHARSET)) {
907+
if (preg_match('/\b('. self::OLDCHARSET .')\b/', $getTableSchema)) {
908908
$columns = ['flag_code' => ['varchar(255)','NOT NULL'],'flag_data' => ['mediumtext','']];
909909
$this->updateDBTable($tableName, $columns, $connection);
910910
}

0 commit comments

Comments
 (0)