Skip to content

Commit 2beb0fd

Browse files
committed
Merge branch 'ACP2E-2144' of https://github.com/magento-l3/magento2ce into PR-L3-08112023
2 parents bdd4ddd + 3dfb95d commit 2beb0fd

File tree

2 files changed

+105
-11
lines changed

2 files changed

+105
-11
lines changed

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

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,23 +1769,44 @@ public function describeTable($tableName, $schemaName = null)
17691769
$cacheKey = $this->_getTableName($tableName, $schemaName);
17701770
$ddl = $this->loadDdlCache($cacheKey, self::DDL_DESCRIBE);
17711771
if ($ddl === false) {
1772-
$ddl = parent::describeTable($tableName, $schemaName);
1773-
/**
1774-
* Remove bug in some MySQL versions, when int-column without default value is described as:
1775-
* having default empty string value
1776-
*/
1777-
$affected = ['tinyint', 'smallint', 'mediumint', 'int', 'bigint'];
1778-
foreach ($ddl as $key => $columnData) {
1779-
if (($columnData['DEFAULT'] === '') && (array_search($columnData['DATA_TYPE'], $affected) !== false)) {
1780-
$ddl[$key]['DEFAULT'] = null;
1781-
}
1782-
}
1772+
$ddl = $this->prepareColumnData(parent::describeTable($tableName, $schemaName));
17831773
$this->saveDdlCache($cacheKey, self::DDL_DESCRIBE, $ddl);
17841774
}
17851775

17861776
return $ddl;
17871777
}
17881778

1779+
/**
1780+
* Prepares column data for describeTable() method
1781+
*
1782+
* @param array $ddl
1783+
* @return array
1784+
*/
1785+
private function prepareColumnData(array $ddl): array
1786+
{
1787+
/**
1788+
* Remove bug in some MySQL versions, when int-column without default value is described as:
1789+
* having default empty string value
1790+
*/
1791+
$affected = ['tinyint', 'smallint', 'mediumint', 'int', 'bigint'];
1792+
foreach ($ddl as $key => $columnData) {
1793+
if (($columnData['DEFAULT'] === '') && (array_search($columnData['DATA_TYPE'], $affected) !== false)) {
1794+
$ddl[$key]['DEFAULT'] = null;
1795+
}
1796+
}
1797+
1798+
/**
1799+
* Starting from MariaDB 10.5.1 columns with old temporal formats are marked with a \/* mariadb-5.3 *\/
1800+
* comment in the output of SHOW CREATE TABLE, SHOW COLUMNS, DESCRIBE statements,
1801+
* as well as in the COLUMN_TYPE column of the INFORMATION_SCHEMA.COLUMNS Table.
1802+
*/
1803+
foreach ($ddl as $key => $columnData) {
1804+
$ddl[$key]['DATA_TYPE'] = str_replace(' /* mariadb-5.3 */', '', $columnData['DATA_TYPE']);
1805+
}
1806+
1807+
return $ddl;
1808+
}
1809+
17891810
/**
17901811
* Format described column to definition, ready to be added to ddl table.
17911812
*

lib/internal/Magento/Framework/DB/Test/Unit/Adapter/Pdo/MysqlTest.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,4 +793,77 @@ private function addConnectionMock(MockObject $pdoAdapterMock): void
793793
$resourceProperty->setAccessible(true);
794794
$resourceProperty->setValue($pdoAdapterMock, $this->connection);
795795
}
796+
797+
/**
798+
* @param array $actual
799+
* @param array $expected
800+
* @dataProvider columnDataForTest
801+
* @return void
802+
* @throws \ReflectionException
803+
*/
804+
public function testPrepareColumnData(array $actual, array $expected)
805+
{
806+
$adapter = $this->getMysqlPdoAdapterMock([]);
807+
$result = $this->invokeModelMethod($adapter, 'prepareColumnData', [$actual]);
808+
809+
foreach ($result as $key => $value) {
810+
$this->assertEquals($expected[$key], $value);
811+
}
812+
}
813+
814+
/**
815+
* Data provider for testPrepareColumnData
816+
*
817+
* @return array[]
818+
*/
819+
public function columnDataForTest(): array
820+
{
821+
return [
822+
[
823+
'actual' => [
824+
[
825+
'DATA_TYPE' => 'int',
826+
'DEFAULT' => ''
827+
],
828+
[
829+
'DATA_TYPE' => 'timestamp /* mariadb-5.3 */',
830+
'DEFAULT' => 'CURRENT_TIMESTAMP'
831+
],
832+
[
833+
'DATA_TYPE' => 'varchar',
834+
'DEFAULT' => ''
835+
]
836+
],
837+
'expected' => [
838+
[
839+
'DATA_TYPE' => 'int',
840+
'DEFAULT' => null
841+
],
842+
[
843+
'DATA_TYPE' => 'timestamp',
844+
'DEFAULT' => 'CURRENT_TIMESTAMP'
845+
],
846+
[
847+
'DATA_TYPE' => 'varchar',
848+
'DEFAULT' => ''
849+
]
850+
]
851+
]
852+
];
853+
}
854+
855+
/**
856+
* @param string $method
857+
* @param array $parameters
858+
* @return mixed
859+
* @throws \ReflectionException
860+
*/
861+
private function invokeModelMethod(MockObject $adapter, string $method, array $parameters = [])
862+
{
863+
$reflection = new \ReflectionClass($adapter);
864+
$method = $reflection->getMethod($method);
865+
$method->setAccessible(true);
866+
867+
return $method->invokeArgs($adapter, $parameters);
868+
}
796869
}

0 commit comments

Comments
 (0)