Skip to content

Commit 1604ffa

Browse files
committed
AC-9755:Set default collation to utf8mb4 for MySQL
1 parent 4121b85 commit 1604ffa

File tree

1 file changed

+12
-1
lines changed
  • lib/internal/Magento/Framework/DB/Adapter/Pdo

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Magento\Framework\Stdlib\StringUtils;
3333
use Zend_Db_Adapter_Exception;
3434
use Zend_Db_Statement_Exception;
35+
use Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Table as DtoFactoriesTable;
3536

3637
// @codingStandardsIgnoreStart
3738

@@ -273,13 +274,19 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface, Rese
273274
*/
274275
private $mysqlversion;
275276

277+
/***
278+
* @var DtoFactoriesTable
279+
*/
280+
private $columnConfig;
281+
276282
/**
277283
* Constructor
278284
*
279285
* @param StringUtils $string
280286
* @param DateTime $dateTime
281287
* @param LoggerInterface $logger
282288
* @param SelectFactory $selectFactory
289+
* @param DtoFactoriesTable $dtoFactoriesTable
283290
* @param array $config
284291
* @param SerializerInterface|null $serializer
285292
*/
@@ -288,6 +295,7 @@ public function __construct(
288295
DateTime $dateTime,
289296
LoggerInterface $logger,
290297
SelectFactory $selectFactory,
298+
DtoFactoriesTable $dtoFactoriesTable,
291299
array $config = [],
292300
SerializerInterface $serializer = null
293301
) {
@@ -296,6 +304,7 @@ public function __construct(
296304
$this->dateTime = $dateTime;
297305
$this->logger = $logger;
298306
$this->selectFactory = $selectFactory;
307+
$this->columnConfig = $dtoFactoriesTable;
299308
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
300309
$this->exceptionMap = [
301310
// SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
@@ -4321,7 +4330,9 @@ private function applyCharsetAndCollation($columnType, $definition, $position) :
43214330
{
43224331
$pattern = '/\b(' . implode('|', array_map('preg_quote', self::COLUMN_TYPE)) . ')\b/i';
43234332
if (preg_match($pattern, $columnType) === 1) {
4324-
$charsets = 'CHARACTER SET ' . self::CHARSET. ' COLLATE ' . self::COLLATION;
4333+
$charset = $this->columnConfig->getDefaultCharset();
4334+
$collate = $this->columnConfig->getDefaultCollation();
4335+
$charsets = 'CHARACTER SET ' . $charset. ' COLLATE ' . $collate;
43254336
$columnsAttribute = explode(' ', trim($definition));
43264337
array_splice($columnsAttribute, $position, 0, $charsets);
43274338
return implode(' ', $columnsAttribute);

0 commit comments

Comments
 (0)