Skip to content

Commit 0c59b60

Browse files
committed
Merge remote-tracking branch 'tier4/ACP2E-2844' into PR_L3_March_24
2 parents 009b6c5 + f719552 commit 0c59b60

File tree

2 files changed

+146
-8
lines changed

2 files changed

+146
-8
lines changed

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,13 +1812,8 @@ private function prepareColumnData(array $ddl): array
18121812
}
18131813
}
18141814

1815-
/**
1816-
* Starting from MariaDB 10.5.1 columns with old temporal formats are marked with a \/* mariadb-5.3 *\/
1817-
* comment in the output of SHOW CREATE TABLE, SHOW COLUMNS, DESCRIBE statements,
1818-
* as well as in the COLUMN_TYPE column of the INFORMATION_SCHEMA.COLUMNS Table.
1819-
*/
18201815
foreach ($ddl as $key => $columnData) {
1821-
$ddl[$key]['DATA_TYPE'] = str_replace(' /* mariadb-5.3 */', '', $columnData['DATA_TYPE']);
1816+
$ddl[$key]['DATA_TYPE'] = $this->sanitizeColumnDataType($columnData['DATA_TYPE']);
18221817
}
18231818

18241819
return $ddl;
@@ -1975,7 +1970,7 @@ public function modifyColumnByDdl($tableName, $columnName, $definition, $flushDa
19751970
protected function _getColumnTypeByDdl($column)
19761971
{
19771972
// phpstan:ignore
1978-
switch ($column['DATA_TYPE']) {
1973+
switch ($this->sanitizeColumnDataType($column['DATA_TYPE'])) {
19791974
case 'bool':
19801975
return Table::TYPE_BOOLEAN;
19811976
case 'tinytext':
@@ -2012,6 +2007,22 @@ protected function _getColumnTypeByDdl($column)
20122007
return null;
20132008
}
20142009

2010+
/**
2011+
* Remove old temporal format comment from column data type
2012+
*
2013+
* @param string $columnType
2014+
* @return string
2015+
*/
2016+
private function sanitizeColumnDataType(string $columnType): string
2017+
{
2018+
/**
2019+
* Starting from MariaDB 10.5.1 columns with old temporal formats are marked with a \/* mariadb-5.3 *\/
2020+
* comment in the output of SHOW CREATE TABLE, SHOW COLUMNS, DESCRIBE statements,
2021+
* as well as in the COLUMN_TYPE column of the INFORMATION_SCHEMA.COLUMNS Table.
2022+
*/
2023+
return str_replace(' /* mariadb-5.3 */', '', $columnType);
2024+
}
2025+
20152026
/**
20162027
* Change table storage engine
20172028
*
@@ -2584,6 +2595,8 @@ protected function _getColumnDefinition($options, $ddlType = null)
25842595
// detect and validate column type
25852596
if ($ddlType === null) {
25862597
$ddlType = $this->_getDdlType($options);
2598+
} else {
2599+
$ddlType = $this->sanitizeColumnDataType($ddlType);
25872600
}
25882601

25892602
if (empty($ddlType) || !isset($this->_ddlColumnTypes[$ddlType])) {
@@ -3225,6 +3238,8 @@ public function prepareColumnValue(array $column, $value)
32253238
return $value;
32263239
}
32273240

3241+
$column['DATA_TYPE'] = $this->sanitizeColumnDataType($column['DATA_TYPE']);
3242+
32283243
// return original value if invalid column describe data
32293244
if (!isset($column['DATA_TYPE'])) {
32303245
return $value;
@@ -3994,7 +4009,7 @@ protected function _getDdlType($options)
39944009
$ddlType = $options['COLUMN_TYPE'];
39954010
}
39964011

3997-
return $ddlType;
4012+
return $this->sanitizeColumnDataType($ddlType);
39984013
}
39994014

40004015
/**

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

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,129 @@ public static function columnDataForTest(): array
852852
];
853853
}
854854

855+
/**
856+
* @param array $actual
857+
* @param int|string|\Zend_Db_Expr $expected
858+
* @dataProvider columnDataAndValueForTest
859+
* @return void
860+
* @throws \ReflectionException
861+
*/
862+
public function testPrepareColumnValue(array $actual, int|string|\Zend_Db_Expr $expected)
863+
{
864+
$adapter = $this->getMysqlPdoAdapterMock([]);
865+
866+
$result = $this->invokeModelMethod($adapter, 'prepareColumnValue', [$actual[0], $actual[1]]);
867+
868+
$this->assertEquals($expected, $result);
869+
}
870+
871+
/**
872+
* Data provider for testPrepareColumnValue
873+
*
874+
* @return array[]
875+
*/
876+
public function columnDataAndValueForTest(): array
877+
{
878+
return [
879+
[
880+
'actual' => [
881+
[
882+
'DATA_TYPE' => 'int',
883+
'DEFAULT' => ''
884+
],
885+
'10'
886+
],
887+
'expected' => 10
888+
],
889+
[
890+
'actual' => [
891+
[
892+
'DATA_TYPE' => 'datetime /* mariadb-5.3 */',
893+
'DEFAULT' => 'CURRENT_TIMESTAMP'
894+
],
895+
'null'
896+
],
897+
'expected' => new \Zend_Db_Expr('NULL')
898+
],
899+
[
900+
'actual' => [
901+
[
902+
'DATA_TYPE' => 'date /* mariadb-5.3 */',
903+
'DEFAULT' => ''
904+
],
905+
'null'
906+
],
907+
'expected' => new \Zend_Db_Expr('NULL')
908+
],
909+
[
910+
'actual' => [
911+
[
912+
'DATA_TYPE' => 'timestamp /* mariadb-5.3 */',
913+
'DEFAULT' => 'CURRENT_TIMESTAMP'
914+
],
915+
'null'
916+
],
917+
'expected' => new \Zend_Db_Expr('NULL')
918+
],
919+
[
920+
'actual' => [
921+
[
922+
'DATA_TYPE' => 'varchar',
923+
'NULLABLE' => false,
924+
'DEFAULT' => ''
925+
],
926+
10
927+
],
928+
'expected' => '10'
929+
]
930+
];
931+
}
932+
933+
/**
934+
* @param string $actual
935+
* @param string $expected
936+
* @dataProvider providerForSanitizeColumnDataType
937+
* @return void
938+
* @throws \ReflectionException
939+
*/
940+
public function testSanitizeColumnDataType(string $actual, string $expected)
941+
{
942+
$adapter = $this->getMysqlPdoAdapterMock([]);
943+
$result = $this->invokeModelMethod($adapter, 'sanitizeColumnDataType', [$actual]);
944+
$this->assertEquals($expected, $result);
945+
}
946+
947+
/**
948+
* Data provider for testSanitizeColumnDataType
949+
*
950+
* @return array[]
951+
*/
952+
public function providerForSanitizeColumnDataType()
953+
{
954+
return [
955+
[
956+
'actual' => 'int',
957+
'expected' => 'int'
958+
],
959+
[
960+
'actual' => 'varchar',
961+
'expected' => 'varchar'
962+
],
963+
[
964+
'actual' => 'datetime /* mariadb-5.3 */',
965+
'expected' => 'datetime'
966+
],
967+
[
968+
'actual' => 'date /* mariadb-5.3 */',
969+
'expected' => 'date'
970+
],
971+
[
972+
'actual' => 'timestamp /* mariadb-5.3 */',
973+
'expected' => 'timestamp'
974+
]
975+
];
976+
}
977+
855978
/**
856979
* @param string $method
857980
* @param array $parameters

0 commit comments

Comments
 (0)