Skip to content

Commit c441b38

Browse files
committed
AC-9755:Set default collation to utf8mb4 for MySQL
1 parent 11410fc commit c441b38

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ public function modifyColumn($tableName, $columnName, $definition, $flushData =
12701270
// Add charset and collation for DBC failures
12711271
if (!empty($definition)) {
12721272
$type = explode(' ', trim($definition));
1273-
$definition = $this->applyCharsetAndCollation($type[0], $definition, 1);
1273+
$definition = $this->setDefaultCharsetAndCollation($type[0], $definition, 1);
12741274
}
12751275
$sql = sprintf(
12761276
'ALTER TABLE %s MODIFY COLUMN %s %s',
@@ -2450,7 +2450,7 @@ protected function _getColumnsDefinition(Table $table)
24502450
if (count($definition)) {
24512451
foreach ($definition as $index => $columnDefinition) {
24522452
$type = explode(' ', trim($columnDefinition));
2453-
$definition[$index] = $this->applyCharsetAndCollation($type[1], $columnDefinition, 2);
2453+
$definition[$index] = $this->setDefaultCharsetAndCollation($type[1], $columnDefinition, 2);
24542454
}
24552455
}
24562456
// PRIMARY KEY
@@ -4309,14 +4309,14 @@ public function __debugInfo()
43094309
}
43104310

43114311
/***
4312-
* Adding charset and collation for DBC failures
4312+
* Set default collation & charset (e.g.,utf8mb4_general_ci & utf8mb4) for tables
43134313
*
43144314
* @param string $columnType
43154315
* @param string $definition
43164316
* @param int $position
43174317
* @return string
43184318
*/
4319-
private function applyCharsetAndCollation($columnType, $definition, $position) : string
4319+
private function setDefaultCharsetAndCollation($columnType, $definition, $position) : string
43204320
{
43214321
$pattern = '/\b(' . implode('|', array_map('preg_quote', self::COLUMN_TYPE)) . ')\b/i';
43224322
if (preg_match($pattern, $columnType) === 1) {

lib/internal/Magento/Framework/Setup/Declaration/Schema/Db/MySQL/DbSchemaWriter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function createTable($tableName, $resource, array $definition, array $opt
112112
foreach ($definition as $index => $value) {
113113
if ($this->isColumnExists($value, self::COLUMN_TYPE)) {
114114
if (str_contains($index, 'column')) {
115-
$definition[$index] = $this->applyCharsetAndCollation($value);
115+
$definition[$index] = $this->setDefaultCharsetAndCollation($value);
116116
}
117117
}
118118
}
@@ -238,7 +238,7 @@ public function modifyTableOption($tableName, $resource, $optionName, $optionVal
238238
public function modifyColumn($columnName, $resource, $tableName, $columnDefinition)
239239
{
240240
if ($this->isColumnExists($columnDefinition, self::COLUMN_TYPE)) {
241-
$columnDefinition = $this->applyCharsetAndCollation($columnDefinition);
241+
$columnDefinition = $this->setDefaultCharsetAndCollation($columnDefinition);
242242
}
243243

244244
$sql = sprintf(
@@ -483,12 +483,12 @@ private function getPreparedStatements(array $statementBank) : array
483483
}
484484

485485
/***
486-
* Adding charset and collation for DBC failures
486+
* Set default collation & charset (e.g.,utf8mb4_general_ci & utf8mb4) for tables
487487
*
488488
* @param string $columnDefinition
489489
* @return string
490490
*/
491-
private function applyCharsetAndCollation(string $columnDefinition): string
491+
private function setDefaultCharsetAndCollation(string $columnDefinition): string
492492
{
493493
$charset = $this->columnConfig->getDefaultCharset();
494494
$collate = $this->columnConfig->getDefaultCollation();

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ private function setupModuleRegistry(SchemaSetupInterface $setup)
667667
$columns = ['module' => ['varchar(50)',''],
668668
'schema_version' => ['varchar(50)',''],
669669
'data_version' => ['varchar(50)','']];
670-
$this->setColumnCollationAndCharset($tableName, $columns, $connection);
670+
$this->setDefaultCharsetAndCollation($tableName, $columns, $connection);
671671
}
672672
}
673673
}
@@ -734,7 +734,7 @@ private function setupSessionTable(
734734
if (preg_match('/\b('. self::OLDCHARSET .')\b/', $getTableSchema)) {
735735
$tableName = $setup->getTable('session');
736736
$columns = ['session_id' => ['varchar(255)','']];
737-
$this->setColumnCollationAndCharset($tableName, $columns, $connection);
737+
$this->setDefaultCharsetAndCollation($tableName, $columns, $connection);
738738
}
739739
}
740740
}
@@ -797,7 +797,7 @@ private function setupCacheTable(
797797
if (preg_match('/\b('. self::OLDCHARSET .')\b/', $getTableSchema)) {
798798
$tableName = $setup->getTable('cache');
799799
$columns = ['id' => ['varchar(200)','']];
800-
$this->setColumnCollationAndCharset($tableName, $columns, $connection);
800+
$this->setDefaultCharsetAndCollation($tableName, $columns, $connection);
801801
}
802802
}
803803
}
@@ -842,7 +842,7 @@ private function setupCacheTagTable(
842842
if (preg_match('/\b('. self::OLDCHARSET .')\b/', $getTableSchema)) {
843843
$tableName = $setup->getTable('cache_tag');
844844
$columns = ['tag' => ['varchar(100)',''],'cache_id' => ['varchar(200)','']];
845-
$this->setColumnCollationAndCharset($tableName, $columns, $connection);
845+
$this->setDefaultCharsetAndCollation($tableName, $columns, $connection);
846846
}
847847
}
848848
}
@@ -906,7 +906,7 @@ private function setupFlagTable(
906906
$getTableSchema = $connection->getCreateTable($tableName) ?? '';
907907
if (preg_match('/\b('. self::OLDCHARSET .')\b/', $getTableSchema)) {
908908
$columns = ['flag_code' => ['varchar(255)','NOT NULL'],'flag_data' => ['mediumtext','']];
909-
$this->setColumnCollationAndCharset($tableName, $columns, $connection);
909+
$this->setDefaultCharsetAndCollation($tableName, $columns, $connection);
910910
}
911911
}
912912
}
@@ -1884,14 +1884,14 @@ private function reindexAll(): void
18841884
}
18851885

18861886
/**
1887-
* Add column attribute and update table
1887+
* Set default collation & charset (e.g.,utf8mb4_general_ci & utf8mb4) for core setup tables
18881888
*
18891889
* @param string $tableName
18901890
* @param array $columns
18911891
* @param AdapterInterface $connection
18921892
* @return void
18931893
*/
1894-
private function setColumnCollationAndCharset(string $tableName, array $columns, $connection) : void
1894+
private function setDefaultCharsetAndCollation(string $tableName, array $columns, $connection) : void
18951895
{
18961896
$charset = $this->columnConfig->getDefaultCharset();
18971897
$collate = $this->columnConfig->getDefaultCollation();

0 commit comments

Comments
 (0)