Skip to content

Commit ebb761f

Browse files
committed
AC-9755:Set default collation to utf8mb4 for MySQL
1 parent 2fa21e4 commit ebb761f

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\Theme\Model\Indexer\Design;
1010

11+
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\App\ResourceConnection;
1213
use Magento\Framework\Indexer\IndexStructureInterface;
1314
use Magento\Framework\Indexer\SaveHandler\Batch;
@@ -16,6 +17,7 @@
1617
use Magento\Framework\Indexer\ScopeResolver\FlatScopeResolver;
1718
use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver;
1819
use Magento\Framework\Search\Request\Dimension;
20+
use Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Table as DtoFactoriesTable;
1921

2022
class IndexerHandler extends Grid
2123
{
@@ -24,16 +26,6 @@ class IndexerHandler extends Grid
2426
*/
2527
private $flatScopeResolver;
2628

27-
/***
28-
* Charset for flat table
29-
*/
30-
private const CHARSET = 'utf8mb4';
31-
32-
/***
33-
* Collation for flat table
34-
*/
35-
private const COLLATION = 'utf8mb4_general_ci';
36-
3729
/***
3830
* Old Charset for flat table
3931
*/
@@ -45,9 +37,9 @@ class IndexerHandler extends Grid
4537
private const DESIGN_CONFIG_GRID_FLAT = "design_config_grid_flat";
4638

4739
/***
48-
* charset and collation for column level
40+
* @var DtoFactoriesTable
4941
*/
50-
private const COLUMN_ENCODING = " CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci";
42+
private $columnConfig;
5143

5244
/**
5345
* @param IndexStructureInterface $indexStructure
@@ -57,6 +49,7 @@ class IndexerHandler extends Grid
5749
* @param FlatScopeResolver $flatScopeResolver
5850
* @param array $data
5951
* @param int $batchSize
52+
* @param DtoFactoriesTable|null $dtoFactoriesTable
6053
*/
6154
public function __construct(
6255
IndexStructureInterface $indexStructure,
@@ -65,7 +58,8 @@ public function __construct(
6558
IndexScopeResolver $indexScopeResolver,
6659
FlatScopeResolver $flatScopeResolver,
6760
array $data,
68-
$batchSize = 100
61+
$batchSize = 100,
62+
?DtoFactoriesTable $dtoFactoriesTable = null
6963
) {
7064
parent::__construct(
7165
$indexStructure,
@@ -77,6 +71,7 @@ public function __construct(
7771
$batchSize
7872
);
7973
$this->flatScopeResolver = $flatScopeResolver;
74+
$this->columnConfig = $dtoFactoriesTable ?: ObjectManager::getInstance()->get(DtoFactoriesTable::class);
8075
}
8176

8277
/**
@@ -96,15 +91,18 @@ public function cleanIndex($dimensions)
9691
$getTableSchema = $this->connection->showTableStatus($tableName);
9792
$collation = $getTableSchema['Collation'] ?? '';
9893
if (str_contains($collation, self::OLDCHARSET)) {
94+
$charset = $this->columnConfig->getDefaultCharset();
95+
$collate = $this->columnConfig->getDefaultCollation();
96+
$columnEncoding = " CHARACTER SET ".$charset." COLLATE ".$collate;
9997
$this->connection->query(
10098
sprintf(
10199
'ALTER TABLE `%s` MODIFY COLUMN `theme_theme_id` varchar(255) %s %s,
102100
DEFAULT CHARSET=%s, DEFAULT COLLATE=%s',
103101
$tableName,
104-
self::COLUMN_ENCODING,
102+
$columnEncoding,
105103
"COMMENT 'Theme_theme_id'",
106-
self::CHARSET,
107-
self::COLLATION
104+
$charset,
105+
$collate
108106
)
109107
);
110108
}

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Exception\RuntimeException;
1313
use Magento\Framework\Mview\Config;
1414
use Magento\Framework\Mview\View\AdditionalColumnsProcessor\ProcessorFactory;
15+
use Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Table as DtoFactoriesTable;
1516
use Magento\Framework\Phrase;
1617

1718
/**
@@ -64,36 +65,34 @@ class Changelog implements ChangelogInterface
6465
private $additionalColumnsProcessorFactory;
6566

6667
/***
67-
* Charset for cl tables
68-
*/
69-
private const CHARSET = 'utf8mb4';
70-
71-
/***
72-
* Collation for cl tables
68+
* Old Charset for cl tables
7369
*/
74-
private const COLLATION = 'utf8mb4_general_ci';
70+
private const OLDCHARSET = 'utf8mb3';
7571

7672
/***
77-
* Old Charset for cl tables
73+
* @var DtoFactoriesTable|null
7874
*/
79-
private const OLDCHARSET = 'utf8mb3';
75+
private $columnConfig;
8076

8177
/**
8278
* @param \Magento\Framework\App\ResourceConnection $resource
8379
* @param Config $mviewConfig
8480
* @param ProcessorFactory $additionalColumnsProcessorFactory
81+
* @param DtoFactoriesTable|null $dtoFactoriesTable
8582
* @throws ConnectionException
8683
*/
8784
public function __construct(
8885
\Magento\Framework\App\ResourceConnection $resource,
8986
Config $mviewConfig,
90-
ProcessorFactory $additionalColumnsProcessorFactory
87+
ProcessorFactory $additionalColumnsProcessorFactory,
88+
?DtoFactoriesTable $dtoFactoriesTable = null
9189
) {
9290
$this->connection = $resource->getConnection();
9391
$this->resource = $resource;
9492
$this->checkConnection();
9593
$this->mviewConfig = $mviewConfig;
9694
$this->additionalColumnsProcessorFactory = $additionalColumnsProcessorFactory;
95+
$this->columnConfig = $dtoFactoriesTable ?: ObjectManager::getInstance()->get(DtoFactoriesTable::class);
9796
}
9897

9998
/**
@@ -149,12 +148,14 @@ public function create()
149148
// change the charset to utf8mb4
150149
$getTableSchema = $this->connection->getCreateTable($changelogTableName) ?? '';
151150
if (str_contains($getTableSchema, self::OLDCHARSET)) {
151+
$charset = $this->columnConfig->getDefaultCharset();
152+
$collate = $this->columnConfig->getDefaultCollation();
152153
$this->connection->query(
153154
sprintf(
154155
'ALTER TABLE %s DEFAULT CHARSET=%s, DEFAULT COLLATE=%s',
155156
$changelogTableName,
156-
self::CHARSET,
157-
self::COLLATION
157+
$charset,
158+
$collate
158159
)
159160
);
160161
}

0 commit comments

Comments
 (0)