diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 8eee7a5cf8..818767892a 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -45,7 +45,6 @@ use function stripcslashes; use function stripslashes; use function strlen; use function substr; -use function time; use function trim; use const ENT_COMPAT; @@ -306,6 +305,7 @@ class InsertEdit * @param ColumnFull $tableColumn description of column in given table * @param string[] $commentsMap comments for every column that has a comment * @param int $columnLength length of the current column taken from field metadata + * @param bool $insertMode whether insert mode * * @return mixed[] description of column in given table */ @@ -313,6 +313,7 @@ class InsertEdit ColumnFull $tableColumn, array $commentsMap, int $columnLength, + bool $insertMode, ): array { $column = [ 'Field' => $tableColumn->field, @@ -362,6 +363,15 @@ class InsertEdit // can only occur once per table $column['first_timestamp'] = $column['True_Type'] === 'timestamp'; + if ( + $tableColumn->type === 'datetime' + && ! $tableColumn->isNull + && $tableColumn->default === null + && $insertMode + ) { + $column['Default'] = date('Y-m-d H:i:s'); + } + return $column; } @@ -1725,7 +1735,7 @@ class InsertEdit array $columnMime, string $whereClause, ): string { - $column = $this->analyzeTableColumnsArray($tableColumn, $commentsMap, $columnLength); + $column = $this->analyzeTableColumnsArray($tableColumn, $commentsMap, $columnLength, $insertMode); $asIs = false; /** @var string $fieldHashMd5 */ @@ -1747,10 +1757,6 @@ class InsertEdit // in the name attribute (see bug #1746964 ) $columnNameAppendix = $vkey . '[' . $fieldHashMd5 . ']'; - if ($column['Type'] === 'datetime' && $column['Null'] !== 'YES' && ! isset($column['Default']) && $insertMode) { - $column['Default'] = date('Y-m-d H:i:s', time()); - } - // Get a list of GIS data types. $gisDataTypes = Gis::getDataTypes(); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 49f5aa5383..35b37c3005 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4577,7 +4577,7 @@ parameters: - message: "#^Cannot cast mixed to string\\.$#" - count: 2 + count: 3 path: libraries/classes/InsertEdit.php - @@ -4620,6 +4620,11 @@ parameters: count: 1 path: libraries/classes/InsertEdit.php + - + message: "#^Parameter \\#1 \\$defaultValue of method PhpMyAdmin\\\\InsertEdit\\:\\:getSpecialCharsForInsertingMode\\(\\) expects string\\|null, mixed given\\.$#" + count: 1 + path: libraries/classes/InsertEdit.php + - message: "#^Parameter \\#1 \\$haystack of function mb_strstr expects string, mixed given\\.$#" count: 2 diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index cc98022bc9..1b0a211b31 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -420,7 +420,7 @@ class InsertEditTest extends AbstractTestCase $this->insertEdit, InsertEdit::class, 'analyzeTableColumnsArray', - [$column, [], -1], + [$column, [], -1, false], ); $this->assertEquals($result['Field_md5'], '4342210df36bf2ff2c4e2a997a6d4089');