From 747941ece1437a1e7cf159017c02a1e1e4125ddf Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Thu, 20 Apr 2023 22:09:43 +0100 Subject: [PATCH 01/17] Move $returnToSqlQuery out of the method Signed-off-by: Kamil Tekiela --- .../Controllers/Table/ReplaceController.php | 10 +++++++--- libraries/classes/InsertEdit.php | 16 ++++------------ psalm-baseline.xml | 2 -- test/classes/InsertEditTest.php | 10 ++-------- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/libraries/classes/Controllers/Table/ReplaceController.php b/libraries/classes/Controllers/Table/ReplaceController.php index 6f1df84fa7..ff7cb47c83 100644 --- a/libraries/classes/Controllers/Table/ReplaceController.php +++ b/libraries/classes/Controllers/Table/ReplaceController.php @@ -314,18 +314,22 @@ final class ReplaceController extends AbstractController return; } + $returnToSqlQuery = ''; + if (! empty($GLOBALS['sql_query'])) { + $GLOBALS['urlParams']['sql_query'] = $GLOBALS['sql_query']; + $returnToSqlQuery = $GLOBALS['sql_query']; + } + /** * Executes the sql query and get the result, then move back to the calling * page */ [ - $GLOBALS['urlParams'], $totalAffectedRows, $lastMessages, $warningMessages, $errorMessages, - $returnToSqlQuery, - ] = $this->insertEdit->executeSqlQuery($GLOBALS['urlParams'], $GLOBALS['query']); + ] = $this->insertEdit->executeSqlQuery($GLOBALS['query']); if ($isInsert && ($valueSets !== [] || $rowSkipped)) { $GLOBALS['message'] = Message::getMessageForInsertedRows($totalAffectedRows); diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 6da47a7622..85cec37fb2 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -1031,20 +1031,12 @@ class InsertEdit /** * Executes the sql query and get the result, then move back to the calling page * - * @param mixed[] $urlParams url parameters array - * @param mixed[] $query built query from buildSqlQuery() + * @param mixed[] $query built query from buildSqlQuery() * - * @return mixed[] $url_params, $total_affected_rows, $last_messages - * $warning_messages, $error_messages, $return_to_sql_query + * @return mixed[] $total_affected_rows, $last_messages, $warning_messages, $error_messages */ - public function executeSqlQuery(array $urlParams, array $query): array + public function executeSqlQuery(array $query): array { - $returnToSqlQuery = ''; - if (! empty($GLOBALS['sql_query'])) { - $urlParams['sql_query'] = $GLOBALS['sql_query']; - $returnToSqlQuery = $GLOBALS['sql_query']; - } - $GLOBALS['sql_query'] = implode('; ', $query) . ';'; // to ensure that the query is displayed in case of // "insert as new row" and then "insert another new row" @@ -1090,7 +1082,7 @@ class InsertEdit $warningMessages = $this->getWarningMessages(); } - return [$urlParams, $totalAffectedRows, $lastMessages, $warningMessages, $errorMessages, $returnToSqlQuery]; + return [$totalAffectedRows, $lastMessages, $warningMessages, $errorMessages]; } /** diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 13345003f9..6f1db0ed29 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -3881,7 +3881,6 @@ - @@ -3941,7 +3940,6 @@ - $extraData diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index 8fea1fc02c..0cc93d3460 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -1356,7 +1356,6 @@ class InsertEditTest extends AbstractTestCase public function testExecuteSqlQuery(): void { $query = ['SELECT * FROM `test_db`.`test_table`;', 'SELECT * FROM `test_db`.`test_table_yaml`;']; - $GLOBALS['sql_query'] = 'SELECT * FROM `test_db`.`test_table`;'; $GLOBALS['cfg']['IgnoreMultiSubmitErrors'] = false; $_POST['submit_type'] = ''; @@ -1367,11 +1366,9 @@ class InsertEditTest extends AbstractTestCase new FileListing(), new Template(), ); - $result = $this->insertEdit->executeSqlQuery([], $query); + $result = $this->insertEdit->executeSqlQuery($query); - $this->assertEquals(['sql_query' => 'SELECT * FROM `test_db`.`test_table`;'], $result[0]); $this->assertEquals([], $result[3]); - $this->assertEquals('SELECT * FROM `test_db`.`test_table`;', $result[5]); } /** @@ -1380,7 +1377,6 @@ class InsertEditTest extends AbstractTestCase public function testExecuteSqlQueryWithTryQuery(): void { $query = ['SELECT * FROM `test_db`.`test_table`;', 'SELECT * FROM `test_db`.`test_table_yaml`;']; - $GLOBALS['sql_query'] = 'SELECT * FROM `test_db`.`test_table`;'; $GLOBALS['cfg']['IgnoreMultiSubmitErrors'] = true; $_POST['submit_type'] = ''; @@ -1391,11 +1387,9 @@ class InsertEditTest extends AbstractTestCase new FileListing(), new Template(), ); - $result = $this->insertEdit->executeSqlQuery([], $query); + $result = $this->insertEdit->executeSqlQuery($query); - $this->assertEquals(['sql_query' => 'SELECT * FROM `test_db`.`test_table`;'], $result[0]); $this->assertEquals([], $result[3]); - $this->assertEquals('SELECT * FROM `test_db`.`test_table`;', $result[5]); } /** From 62459b33e5f89a9c502edd29974205276303b5b5 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 21 Apr 2023 15:01:12 +0100 Subject: [PATCH 02/17] Change RW param into a private property Signed-off-by: Kamil Tekiela --- .../classes/Controllers/Table/ChangeController.php | 3 --- libraries/classes/InsertEdit.php | 11 ++++------- phpstan-baseline.neon | 2 +- psalm-baseline.xml | 2 -- test/classes/InsertEditTest.php | 8 -------- 5 files changed, 5 insertions(+), 21 deletions(-) diff --git a/libraries/classes/Controllers/Table/ChangeController.php b/libraries/classes/Controllers/Table/ChangeController.php index cff2199672..39e22276c0 100644 --- a/libraries/classes/Controllers/Table/ChangeController.php +++ b/libraries/classes/Controllers/Table/ChangeController.php @@ -61,7 +61,6 @@ class ChangeController extends AbstractController $GLOBALS['columns_cnt'] ??= null; $GLOBALS['tabindex'] ??= null; $GLOBALS['tabindex_for_value'] ??= null; - $GLOBALS['o_rows'] ??= null; $GLOBALS['has_blob_field'] ??= null; $GLOBALS['jsvkey'] ??= null; $GLOBALS['vkey'] ??= null; @@ -181,7 +180,6 @@ class ChangeController extends AbstractController $GLOBALS['tabindex'] = 0; $GLOBALS['tabindex_for_value'] = 0; - $GLOBALS['o_rows'] = 0; $GLOBALS['urlParams']['db'] = $GLOBALS['db']; $GLOBALS['urlParams']['table'] = $GLOBALS['table']; @@ -250,7 +248,6 @@ class ChangeController extends AbstractController $GLOBALS['vkey'], $GLOBALS['insert_mode'], $currentRow, - $GLOBALS['o_rows'], $GLOBALS['tabindex'], $GLOBALS['columns_cnt'], $isUpload, diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 85cec37fb2..9a5029f7b8 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -77,6 +77,8 @@ class InsertEdit 'VERSION', ]; + private int $rowOffset = 0; + public function __construct( private DatabaseInterface $dbi, private Relation $relation, @@ -1691,7 +1693,6 @@ class InsertEdit * @param string $vkey validation key * @param bool $insertMode whether insert mode * @param mixed[] $currentRow current row - * @param int $oRows row offset * @param int $tabindex tab index * @param int $columnsCnt columns count * @param bool $isUpload whether upload @@ -1716,7 +1717,6 @@ class InsertEdit string $vkey, bool $insertMode, array $currentRow, - int $oRows, int &$tabindex, int $columnsCnt, bool $isUpload, @@ -1802,7 +1802,7 @@ class InsertEdit $backupField = ''; } - $idindex = ($oRows * $columnsCnt) + $columnNumber + 1; + $idindex = ($this->rowOffset * $columnsCnt) + $columnNumber + 1; $tabindex = $idindex; // The function column @@ -2056,7 +2056,6 @@ class InsertEdit * @param string $vkey validation key * @param bool $insertMode whether insert mode * @param mixed[] $currentRow current row - * @param int $oRows row offset * @param int $tabindex tab index * @param int $columnsCnt columns count * @param bool $isUpload whether upload @@ -2079,7 +2078,6 @@ class InsertEdit string $vkey, bool $insertMode, array $currentRow, - int &$oRows, int &$tabindex, int $columnsCnt, bool $isUpload, @@ -2125,7 +2123,6 @@ class InsertEdit $vkey, $insertMode, $currentRow, - $oRows, $tabindex, $columnsCnt, $isUpload, @@ -2142,7 +2139,7 @@ class InsertEdit ); } - $oRows++; + $this->rowOffset++; return $htmlOutput . ' ' . '
' diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 5c2d8d27b4..13501f4c33 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4861,7 +4861,7 @@ parameters: path: libraries/classes/InsertEdit.php - - message: "#^Parameter \\#23 \\$whereClause of method PhpMyAdmin\\\\InsertEdit\\:\\:getHtmlForInsertEditFormColumn\\(\\) expects string, mixed given\\.$#" + message: "#^Parameter \\#22 \\$whereClause of method PhpMyAdmin\\\\InsertEdit\\:\\:getHtmlForInsertEditFormColumn\\(\\) expects string, mixed given\\.$#" count: 1 path: libraries/classes/InsertEdit.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 6f1db0ed29..0ebc91be71 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -3280,7 +3280,6 @@ - @@ -3321,7 +3320,6 @@ - diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index 0cc93d3460..8287d1ab13 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -2398,7 +2398,6 @@ class InsertEditTest extends AbstractTestCase public function testGetHtmlForInsertEditFormColumn(): void { $_SESSION[' HMAC_secret '] = hash('sha1', 'test'); - $oRows = 0; $tabindex = 0; $GLOBALS['plugin_scripts'] = []; $foreigners = ['foreign_keys_data' => []]; @@ -2434,7 +2433,6 @@ class InsertEditTest extends AbstractTestCase '', false, [], - &$oRows, &$tabindex, 0, false, @@ -2493,7 +2491,6 @@ class InsertEditTest extends AbstractTestCase '[a][0]', true, [], - &$oRows, &$tabindex, 0, false, @@ -2565,7 +2562,6 @@ class InsertEditTest extends AbstractTestCase */ public function testGetHtmlForInsertEditRow(): void { - $oRows = 0; $tabindex = 0; $GLOBALS['plugin_scripts'] = []; $GLOBALS['cfg']['LongtextDoubleTextarea'] = true; @@ -2600,7 +2596,6 @@ class InsertEditTest extends AbstractTestCase '', false, [], - $oRows, $tabindex, 1, false, @@ -2630,7 +2625,6 @@ class InsertEditTest extends AbstractTestCase */ public function testGetHtmlForInsertEditRowBasedOnColumnPrivileges(): void { - $oRows = 0; $tabindex = 0; $GLOBALS['plugin_scripts'] = []; $GLOBALS['cfg']['LongtextDoubleTextarea'] = true; @@ -2678,7 +2672,6 @@ class InsertEditTest extends AbstractTestCase '', false, [], - $oRows, $tabindex, 1, false, @@ -2737,7 +2730,6 @@ class InsertEditTest extends AbstractTestCase '', true, [], - $oRows, $tabindex, 3, false, From a8070b5498994c994974cf0b3efee9b148aac272 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 21 Apr 2023 15:26:20 +0100 Subject: [PATCH 03/17] $tabindexForValue was always 0 Signed-off-by: Kamil Tekiela --- .../Controllers/Table/ChangeController.php | 3 -- libraries/classes/InsertEdit.php | 20 +--------- .../Plugins/IOTransformationsPlugin.php | 2 - .../CodeMirrorEditorTransformationPlugin.php | 2 - .../Abs/ImageUploadTransformationsPlugin.php | 2 - .../TextFileUploadTransformationsPlugin.php | 2 - .../Input/Text_Plain_Iptobinary.php | 4 +- .../Input/Text_Plain_Iptolong.php | 4 +- phpstan-baseline.neon | 2 +- psalm-baseline.xml | 2 - test/classes/InsertEditTest.php | 39 ++++++------------- .../TransformationPluginsTest.php | 9 ++--- 12 files changed, 20 insertions(+), 71 deletions(-) diff --git a/libraries/classes/Controllers/Table/ChangeController.php b/libraries/classes/Controllers/Table/ChangeController.php index 39e22276c0..4bde695705 100644 --- a/libraries/classes/Controllers/Table/ChangeController.php +++ b/libraries/classes/Controllers/Table/ChangeController.php @@ -60,7 +60,6 @@ class ChangeController extends AbstractController $GLOBALS['timestamp_seen'] ??= null; $GLOBALS['columns_cnt'] ??= null; $GLOBALS['tabindex'] ??= null; - $GLOBALS['tabindex_for_value'] ??= null; $GLOBALS['has_blob_field'] ??= null; $GLOBALS['jsvkey'] ??= null; $GLOBALS['vkey'] ??= null; @@ -179,7 +178,6 @@ class ChangeController extends AbstractController $GLOBALS['columns_cnt'] = count($GLOBALS['table_columns']); $GLOBALS['tabindex'] = 0; - $GLOBALS['tabindex_for_value'] = 0; $GLOBALS['urlParams']['db'] = $GLOBALS['db']; $GLOBALS['urlParams']['table'] = $GLOBALS['table']; @@ -252,7 +250,6 @@ class ChangeController extends AbstractController $GLOBALS['columns_cnt'], $isUpload, $foreigners, - $GLOBALS['tabindex_for_value'], $GLOBALS['table'], $GLOBALS['db'], $rowId, diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 9a5029f7b8..91d9220129 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -426,7 +426,6 @@ class InsertEdit * @param string $columnNameAppendix the name attribute * @param string $onChangeClause onchange clause for fields * @param int $tabindex tab index - * @param int $tabindexForValue offset for the values tabindex * @param int $idindex id index * @param string $textDir text direction * @param string $specialCharsEncoded replaced char if the string starts @@ -441,7 +440,6 @@ class InsertEdit string $columnNameAppendix, string $onChangeClause, int $tabindex, - int $tabindexForValue, int $idindex, string $textDir, string $specialCharsEncoded, @@ -475,7 +473,7 @@ class InsertEdit . ' dir="' . $textDir . '"' . ' id="field_' . $idindex . '_3"' . ($onChangeClause ? ' onchange="' . htmlspecialchars($onChangeClause, ENT_COMPAT) . '"' : '') - . ' tabindex="' . ($tabindex + $tabindexForValue) . '"' + . ' tabindex="' . $tabindex . '"' . ' data-type="' . $dataType . '">' . $specialCharsEncoded . ''; @@ -490,7 +488,6 @@ class InsertEdit * @param int $fieldsize html field size * @param string $onChangeClause onchange clause for fields * @param int $tabindex tab index - * @param int $tabindexForValue offset for the values tabindex * @param int $idindex id index * @param string $dataType the html5 data-* attribute type * @@ -503,7 +500,6 @@ class InsertEdit int $fieldsize, string $onChangeClause, int $tabindex, - int $tabindexForValue, int $idindex, string $dataType, ): string { @@ -539,7 +535,7 @@ class InsertEdit . ($inputMinMax ? ' ' . $inputMinMax : '') . ' data-type="' . $dataType . '"' . ' class="' . $theClass . '" onchange="' . htmlspecialchars($onChangeClause, ENT_COMPAT) . '"' - . ' tabindex="' . ($tabindex + $tabindexForValue) . '"' + . ' tabindex="' . $tabindex . '"' . ($isInteger ? ' inputmode="numeric"' : '') . ' id="field_' . $idindex . '_3">'; } @@ -611,7 +607,6 @@ class InsertEdit * @param string $onChangeClause onchange clause for fields * @param int $tabindex tab index * @param string $specialChars special characters - * @param int $tabindexForValue offset for the values tabindex * @param int $idindex id index * @param string $textDir text direction * @param string $specialCharsEncoded replaced char if the string starts @@ -631,7 +626,6 @@ class InsertEdit string $onChangeClause, int $tabindex, string $specialChars, - int $tabindexForValue, int $idindex, string $textDir, string $specialCharsEncoded, @@ -652,7 +646,6 @@ class InsertEdit $columnNameAppendix, $onChangeClause, $tabindex, - $tabindexForValue, $idindex, $textDir, $specialCharsEncoded, @@ -666,7 +659,6 @@ class InsertEdit $fieldsize, $onChangeClause, $tabindex, - $tabindexForValue, $idindex, $dataType, ); @@ -1697,7 +1689,6 @@ class InsertEdit * @param int $columnsCnt columns count * @param bool $isUpload whether upload * @param mixed[] $foreigners foreigners - * @param int $tabindexForValue tab index offset for value * @param string $table table * @param string $db database * @param int $rowId row id @@ -1721,7 +1712,6 @@ class InsertEdit int $columnsCnt, bool $isUpload, array $foreigners, - int $tabindexForValue, string $table, string $db, int $rowId, @@ -1866,7 +1856,6 @@ class InsertEdit $currentValue, $textDir, $tabindex, - $tabindexForValue, $idindex, ); } @@ -1966,7 +1955,6 @@ class InsertEdit min(max($column['len'], 4), $GLOBALS['cfg']['LimitChars']), $onChangeClause, $tabindex, - $tabindexForValue, $idindex, 'HEX', ); @@ -1980,7 +1968,6 @@ class InsertEdit $onChangeClause, $tabindex, $specialChars, - $tabindexForValue, $idindex, $textDir, $specialCharsEncoded, @@ -2060,7 +2047,6 @@ class InsertEdit * @param int $columnsCnt columns count * @param bool $isUpload whether upload * @param mixed[] $foreigners foreigners - * @param int $tabindexForValue tab index offset for value * @param string $table table * @param string $db database * @param int $rowId row id @@ -2082,7 +2068,6 @@ class InsertEdit int $columnsCnt, bool $isUpload, array $foreigners, - int $tabindexForValue, string $table, string $db, int $rowId, @@ -2127,7 +2112,6 @@ class InsertEdit $columnsCnt, $isUpload, $foreigners, - $tabindexForValue, $table, $db, $rowId, diff --git a/libraries/classes/Plugins/IOTransformationsPlugin.php b/libraries/classes/Plugins/IOTransformationsPlugin.php index 444289ab0e..814bcbabfb 100644 --- a/libraries/classes/Plugins/IOTransformationsPlugin.php +++ b/libraries/classes/Plugins/IOTransformationsPlugin.php @@ -34,7 +34,6 @@ abstract class IOTransformationsPlugin extends TransformationsPlugin * @param string $value Current field value * @param string $textDir text direction * @param int $tabIndex tab index - * @param int $tabIndexForValue offset for the values tabindex * @param int $idIndex id index * * @return string the html for input field @@ -47,7 +46,6 @@ abstract class IOTransformationsPlugin extends TransformationsPlugin string $value, string $textDir, int $tabIndex, - int $tabIndexForValue, int $idIndex, ): string { return ''; diff --git a/libraries/classes/Plugins/Transformations/Abs/CodeMirrorEditorTransformationPlugin.php b/libraries/classes/Plugins/Transformations/Abs/CodeMirrorEditorTransformationPlugin.php index 3221f29271..be5d0e6227 100644 --- a/libraries/classes/Plugins/Transformations/Abs/CodeMirrorEditorTransformationPlugin.php +++ b/libraries/classes/Plugins/Transformations/Abs/CodeMirrorEditorTransformationPlugin.php @@ -41,7 +41,6 @@ abstract class CodeMirrorEditorTransformationPlugin extends IOTransformationsPlu * @param string $value Current field value * @param string $textDir text direction * @param int $tabIndex tab index - * @param int $tabIndexForValue offset for the values tabindex * @param int $idIndex id index * * @return string the html for input field @@ -54,7 +53,6 @@ abstract class CodeMirrorEditorTransformationPlugin extends IOTransformationsPlu string $value, string $textDir, int $tabIndex, - int $tabIndexForValue, int $idIndex, ): string { $html = ''; diff --git a/libraries/classes/Plugins/Transformations/Abs/ImageUploadTransformationsPlugin.php b/libraries/classes/Plugins/Transformations/Abs/ImageUploadTransformationsPlugin.php index 52df4f0179..b4586d6f7b 100644 --- a/libraries/classes/Plugins/Transformations/Abs/ImageUploadTransformationsPlugin.php +++ b/libraries/classes/Plugins/Transformations/Abs/ImageUploadTransformationsPlugin.php @@ -55,7 +55,6 @@ abstract class ImageUploadTransformationsPlugin extends IOTransformationsPlugin * @param string $value Current field value * @param string $textDir text direction * @param int $tabIndex tab index - * @param int $tabIndexForValue offset for the values tabindex * @param int $idIndex id index * * @return string the html for input field @@ -68,7 +67,6 @@ abstract class ImageUploadTransformationsPlugin extends IOTransformationsPlugin string $value, string $textDir, int $tabIndex, - int $tabIndexForValue, int $idIndex, ): string { $html = ''; diff --git a/libraries/classes/Plugins/Transformations/Abs/TextFileUploadTransformationsPlugin.php b/libraries/classes/Plugins/Transformations/Abs/TextFileUploadTransformationsPlugin.php index db5db0c413..d5ec1ea9ad 100644 --- a/libraries/classes/Plugins/Transformations/Abs/TextFileUploadTransformationsPlugin.php +++ b/libraries/classes/Plugins/Transformations/Abs/TextFileUploadTransformationsPlugin.php @@ -50,7 +50,6 @@ abstract class TextFileUploadTransformationsPlugin extends IOTransformationsPlug * @param string $value Current field value * @param string $textDir text direction * @param int $tabIndex tab index - * @param int $tabIndexForValue offset for the values tabindex * @param int $idIndex id index * * @return string the html for input field @@ -63,7 +62,6 @@ abstract class TextFileUploadTransformationsPlugin extends IOTransformationsPlug string $value, string $textDir, int $tabIndex, - int $tabIndexForValue, int $idIndex, ): string { $html = ''; diff --git a/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptobinary.php b/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptobinary.php index 6dd735dd96..014909b573 100644 --- a/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptobinary.php +++ b/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptobinary.php @@ -57,7 +57,6 @@ class Text_Plain_Iptobinary extends IOTransformationsPlugin * @param string $value Current field value * @param string $textDir text direction * @param int $tabIndex tab index - * @param int $tabIndexForValue offset for the values tabindex * @param int $idIndex id index * * @return string the html for input field @@ -70,7 +69,6 @@ class Text_Plain_Iptobinary extends IOTransformationsPlugin string $value, string $textDir, int $tabIndex, - int $tabIndexForValue, int $idIndex, ): string { $html = ''; @@ -96,7 +94,7 @@ class Text_Plain_Iptobinary extends IOTransformationsPlugin . ' dir="' . $textDir . '"' . ' class="' . $class . '"' . ' id="field_' . $idIndex . '_3"' - . ' tabindex="' . ($tabIndex + $tabIndexForValue) . '">'; + . ' tabindex="' . ($tabIndex) . '">'; } /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */ diff --git a/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptolong.php b/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptolong.php index 8da85a8092..95bbb63484 100644 --- a/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptolong.php +++ b/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptolong.php @@ -54,7 +54,6 @@ class Text_Plain_Iptolong extends IOTransformationsPlugin * @param string $value Current field value * @param string $textDir text direction * @param int $tabIndex tab index - * @param int $tabIndexForValue offset for the values tabindex * @param int $idIndex id index * * @return string the html for input field @@ -67,7 +66,6 @@ class Text_Plain_Iptolong extends IOTransformationsPlugin string $value, string $textDir, int $tabIndex, - int $tabIndexForValue, int $idIndex, ): string { $html = ''; @@ -88,7 +86,7 @@ class Text_Plain_Iptolong extends IOTransformationsPlugin . ' dir="' . $textDir . '"' . ' class="transform_IPToLong"' . ' id="field_' . $idIndex . '_3"' - . ' tabindex="' . ($tabIndex + $tabIndexForValue) . '" />'; + . ' tabindex="' . ($tabIndex) . '" />'; } /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */ diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 13501f4c33..98ddd0189d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4861,7 +4861,7 @@ parameters: path: libraries/classes/InsertEdit.php - - message: "#^Parameter \\#22 \\$whereClause of method PhpMyAdmin\\\\InsertEdit\\:\\:getHtmlForInsertEditFormColumn\\(\\) expects string, mixed given\\.$#" + message: "#^Parameter \\#21 \\$whereClause of method PhpMyAdmin\\\\InsertEdit\\:\\:getHtmlForInsertEditFormColumn\\(\\) expects string, mixed given\\.$#" count: 1 path: libraries/classes/InsertEdit.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 0ebc91be71..d0fe2c8593 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -3284,7 +3284,6 @@ - @@ -3325,7 +3324,6 @@ - diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index 8287d1ab13..4b887499d5 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -606,7 +606,7 @@ class InsertEditTest extends AbstractTestCase $this->insertEdit, InsertEdit::class, 'getTextarea', - [$column, 'a', 'b', '', 2, 0, 1, 'abc/', 'foobar', 'CHAR', false], + [$column, 'a', 'b', '', 2, 1, 'abc/', 'foobar', 'CHAR'], ); $result = $this->parseString($result); @@ -632,12 +632,12 @@ class InsertEditTest extends AbstractTestCase $this->insertEdit, InsertEdit::class, 'getHtmlInput', - [$column, 'a', 'b', 30, 'c', 23, 2, 0, 'DATE', false], + [$column, 'a', 'b', 30, 'c', 23, 0, 'DATE'], ); $this->assertEquals( '', + . ' class="textfield datefield" onchange="c" tabindex="23" id="field_0_3">', $result, ); @@ -648,11 +648,11 @@ class InsertEditTest extends AbstractTestCase $this->insertEdit, InsertEdit::class, 'getHtmlInput', - [$column, 'a', 'b', 30, 'c', 23, 2, 0, 'DATE', false], + [$column, 'a', 'b', 30, 'c', 23, 0, 'DATE'], ); $this->assertEquals( '', + . ' class="textfield datetimefield" onchange="c" tabindex="23" id="field_0_3">', $result, ); @@ -663,11 +663,11 @@ class InsertEditTest extends AbstractTestCase $this->insertEdit, InsertEdit::class, 'getHtmlInput', - [$column, 'a', 'b', 30, 'c', 23, 2, 0, 'DATE', false], + [$column, 'a', 'b', 30, 'c', 23, 0, 'DATE'], ); $this->assertEquals( '', + . ' class="textfield datetimefield" onchange="c" tabindex="23" id="field_0_3">', $result, ); @@ -679,11 +679,11 @@ class InsertEditTest extends AbstractTestCase $this->insertEdit, InsertEdit::class, 'getHtmlInput', - [$column, 'a', 'b', 11, 'c', 23, 2, 0, 'INT', false], + [$column, 'a', 'b', 11, 'c', 23, 0, 'INT'], ); $this->assertEquals( '', + . ' class="textfield" onchange="c" tabindex="23" inputmode="numeric" id="field_0_3">', $result, ); } @@ -751,13 +751,11 @@ class InsertEditTest extends AbstractTestCase 'c', 22, '<', - 12, 1, '/', '<', "foo\nbar", $extractedColumnSpec, - false, ], ); @@ -765,7 +763,7 @@ class InsertEditTest extends AbstractTestCase "a\na\n" . '', $result, ); @@ -787,20 +785,18 @@ class InsertEditTest extends AbstractTestCase 'c', 22, '<', - 12, 1, '/', '<', "foo\nbar", $extractedColumnSpec, - false, ], ); $this->assertEquals( "a\n" . '' . '', $result, @@ -820,13 +816,11 @@ class InsertEditTest extends AbstractTestCase 'c', 22, '<', - 12, 1, '/', '<', "foo\nbar", $extractedColumnSpec, - false, ], ); @@ -848,13 +842,11 @@ class InsertEditTest extends AbstractTestCase 'c', 22, '<', - 12, 1, '/', '<', "foo\nbar", $extractedColumnSpec, - false, ], ); @@ -876,13 +868,11 @@ class InsertEditTest extends AbstractTestCase 'c', 22, '<', - 12, 1, '/', '<', "foo\nbar", $extractedColumnSpec, - false, ], ); @@ -904,13 +894,11 @@ class InsertEditTest extends AbstractTestCase 'c', 22, '<', - 12, 1, '/', '<', "foo\nbar", $extractedColumnSpec, - false, ], ); @@ -2437,7 +2425,6 @@ class InsertEditTest extends AbstractTestCase 0, false, $foreigners, - 0, 'table', 'db', 0, @@ -2495,7 +2482,6 @@ class InsertEditTest extends AbstractTestCase 0, false, $foreigners, - 0, 'table', 'db', 0, @@ -2600,7 +2586,6 @@ class InsertEditTest extends AbstractTestCase 1, false, $foreigners, - 0, 'table', 'db', 0, @@ -2676,7 +2661,6 @@ class InsertEditTest extends AbstractTestCase 1, false, $foreigners, - 0, 'table', 'db', 0, @@ -2734,7 +2718,6 @@ class InsertEditTest extends AbstractTestCase 3, false, $foreigners, - 0, 'table', 'db', 0, diff --git a/test/classes/Plugins/Transformations/TransformationPluginsTest.php b/test/classes/Plugins/Transformations/TransformationPluginsTest.php index e96e0497c5..de4e25b86f 100644 --- a/test/classes/Plugins/Transformations/TransformationPluginsTest.php +++ b/test/classes/Plugins/Transformations/TransformationPluginsTest.php @@ -90,7 +90,7 @@ class TransformationPluginsTest extends AbstractTestCase '
', - [[], 0, 'test', ['150'], '', 'ltr', 0, 0, 0], + [[], 0, 'test', ['150'], '', 'ltr', 0, 0], ], [ new Image_JPEG_Upload(), @@ -111,7 +111,6 @@ class TransformationPluginsTest extends AbstractTestCase 'ltr', 0, 0, - 0, ], ], // Test data for TextPlainFileupload plugin @@ -128,7 +127,7 @@ class TransformationPluginsTest extends AbstractTestCase new Text_Plain_FileUpload(), 'getInputHtml', '', - [[], 0, 'test', [], '', 'ltr', 0, 0, 0], + [[], 0, 'test', [], '', 'ltr', 0, 0], ], [ new Text_Plain_FileUpload(), @@ -137,7 +136,7 @@ class TransformationPluginsTest extends AbstractTestCase . 'value="something">', - [[], 0, '2ndtest', [], 'something', 'ltr', 0, 0, 0], + [[], 0, '2ndtest', [], 'something', 'ltr', 0, 0], ], // Test data for Text_Plain_Regexvalidation plugin [new Text_Plain_RegexValidation(), 'getName', 'Regex Validation'], @@ -150,7 +149,7 @@ class TransformationPluginsTest extends AbstractTestCase ], [new Text_Plain_RegexValidation(), 'getMIMEType', 'Text'], [new Text_Plain_RegexValidation(), 'getMIMESubtype', 'Plain'], - [new Text_Plain_RegexValidation(), 'getInputHtml', '', [[], 0, '', [], '', 'ltr', 0, 0, 0]], + [new Text_Plain_RegexValidation(), 'getInputHtml', '', [[], 0, '', [], '', 'ltr', 0, 0]], // Test data for PhpMyAdmin\Plugins\Transformations\Output\Application_Octetstream_Download plugin [new Application_Octetstream_Download(), 'getName', 'Download'], [ From 7f05587905c97cc58e33d96a14a111c70cd1eba3 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 21 Apr 2023 15:44:31 +0100 Subject: [PATCH 04/17] Remove method_exists Signed-off-by: Kamil Tekiela --- libraries/classes/InsertEdit.php | 6 ++---- psalm-baseline.xml | 9 +-------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 91d9220129..1a09de16b1 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -7,6 +7,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\ConfigStorage\Relation; use PhpMyAdmin\Dbal\ResultInterface; use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\Plugins\IOTransformationsPlugin; use PhpMyAdmin\Plugins\TransformationsPlugin; use PhpMyAdmin\Utils\Gis; @@ -33,7 +34,6 @@ use function mb_stripos; use function mb_strlen; use function mb_strstr; use function md5; -use function method_exists; use function min; use function password_hash; use function preg_match; @@ -1847,7 +1847,7 @@ class InsertEdit $currentValue = $currentRow[$column['Field']]; } - if (method_exists($transformationPlugin, 'getInputHtml')) { + if ($transformationPlugin instanceof IOTransformationsPlugin) { $transformedHtml = $transformationPlugin->getInputHtml( $column, $rowId, @@ -1858,9 +1858,7 @@ class InsertEdit $tabindex, $idindex, ); - } - if (method_exists($transformationPlugin, 'getScripts')) { $GLOBALS['plugin_scripts'] = array_merge( $GLOBALS['plugin_scripts'], $transformationPlugin->getScripts(), diff --git a/psalm-baseline.xml b/psalm-baseline.xml index d0fe2c8593..42b72e9597 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -7944,6 +7944,7 @@ + $currentValue $defaultValue @@ -7959,7 +7960,6 @@ $rows[$keyId] $singleQuery $singleQuery - getScripts()]]> $whereClause $whereClause @@ -8031,7 +8031,6 @@ $setSelectSize $singleQuery $specialChars - $transformedHtml $whereClause $whereClause $whereClause @@ -10268,12 +10267,6 @@ bool - - - getInputHtml - getScripts - - $nameArray === false From 269535a7a57da4a1d16e5c04083ffa7d21fb1cf1 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 21 Apr 2023 19:50:01 +0100 Subject: [PATCH 05/17] Change $tabindex into a private property Signed-off-by: Kamil Tekiela --- .../Controllers/Table/ChangeController.php | 4 --- libraries/classes/InsertEdit.php | 24 ++++------------- phpstan-baseline.neon | 2 +- psalm-baseline.xml | 2 -- test/classes/InsertEditTest.php | 27 ++++++------------- 5 files changed, 14 insertions(+), 45 deletions(-) diff --git a/libraries/classes/Controllers/Table/ChangeController.php b/libraries/classes/Controllers/Table/ChangeController.php index 4bde695705..f98c846fc9 100644 --- a/libraries/classes/Controllers/Table/ChangeController.php +++ b/libraries/classes/Controllers/Table/ChangeController.php @@ -59,7 +59,6 @@ class ChangeController extends AbstractController $GLOBALS['table_columns'] ??= null; $GLOBALS['timestamp_seen'] ??= null; $GLOBALS['columns_cnt'] ??= null; - $GLOBALS['tabindex'] ??= null; $GLOBALS['has_blob_field'] ??= null; $GLOBALS['jsvkey'] ??= null; $GLOBALS['vkey'] ??= null; @@ -177,8 +176,6 @@ class ChangeController extends AbstractController $GLOBALS['timestamp_seen'] = false; $GLOBALS['columns_cnt'] = count($GLOBALS['table_columns']); - $GLOBALS['tabindex'] = 0; - $GLOBALS['urlParams']['db'] = $GLOBALS['db']; $GLOBALS['urlParams']['table'] = $GLOBALS['table']; $GLOBALS['urlParams'] = $this->urlParamsInEditMode($GLOBALS['urlParams'], $GLOBALS['where_clause_array']); @@ -246,7 +243,6 @@ class ChangeController extends AbstractController $GLOBALS['vkey'], $GLOBALS['insert_mode'], $currentRow, - $GLOBALS['tabindex'], $GLOBALS['columns_cnt'], $isUpload, $foreigners, diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 1a09de16b1..0ba10b5118 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -78,6 +78,7 @@ class InsertEdit ]; private int $rowOffset = 0; + private int $tabindex = 0; public function __construct( private DatabaseInterface $dbi, @@ -425,7 +426,6 @@ class InsertEdit * @param string $backupField hidden input field * @param string $columnNameAppendix the name attribute * @param string $onChangeClause onchange clause for fields - * @param int $tabindex tab index * @param int $idindex id index * @param string $textDir text direction * @param string $specialCharsEncoded replaced char if the string starts @@ -439,7 +439,6 @@ class InsertEdit string $backupField, string $columnNameAppendix, string $onChangeClause, - int $tabindex, int $idindex, string $textDir, string $specialCharsEncoded, @@ -473,7 +472,7 @@ class InsertEdit . ' dir="' . $textDir . '"' . ' id="field_' . $idindex . '_3"' . ($onChangeClause ? ' onchange="' . htmlspecialchars($onChangeClause, ENT_COMPAT) . '"' : '') - . ' tabindex="' . $tabindex . '"' + . ' tabindex="' . $this->tabindex . '"' . ' data-type="' . $dataType . '">' . $specialCharsEncoded . ''; @@ -487,7 +486,6 @@ class InsertEdit * @param string $specialChars special characters * @param int $fieldsize html field size * @param string $onChangeClause onchange clause for fields - * @param int $tabindex tab index * @param int $idindex id index * @param string $dataType the html5 data-* attribute type * @@ -499,7 +497,6 @@ class InsertEdit string $specialChars, int $fieldsize, string $onChangeClause, - int $tabindex, int $idindex, string $dataType, ): string { @@ -535,7 +532,7 @@ class InsertEdit . ($inputMinMax ? ' ' . $inputMinMax : '') . ' data-type="' . $dataType . '"' . ' class="' . $theClass . '" onchange="' . htmlspecialchars($onChangeClause, ENT_COMPAT) . '"' - . ' tabindex="' . $tabindex . '"' + . ' tabindex="' . $this->tabindex . '"' . ($isInteger ? ' inputmode="numeric"' : '') . ' id="field_' . $idindex . '_3">'; } @@ -605,7 +602,6 @@ class InsertEdit * @param string $backupField hidden input field * @param string $columnNameAppendix the name attribute * @param string $onChangeClause onchange clause for fields - * @param int $tabindex tab index * @param string $specialChars special characters * @param int $idindex id index * @param string $textDir text direction @@ -624,7 +620,6 @@ class InsertEdit string $backupField, string $columnNameAppendix, string $onChangeClause, - int $tabindex, string $specialChars, int $idindex, string $textDir, @@ -645,7 +640,6 @@ class InsertEdit $backupField, $columnNameAppendix, $onChangeClause, - $tabindex, $idindex, $textDir, $specialCharsEncoded, @@ -658,7 +652,6 @@ class InsertEdit $specialChars, $fieldsize, $onChangeClause, - $tabindex, $idindex, $dataType, ); @@ -1685,7 +1678,6 @@ class InsertEdit * @param string $vkey validation key * @param bool $insertMode whether insert mode * @param mixed[] $currentRow current row - * @param int $tabindex tab index * @param int $columnsCnt columns count * @param bool $isUpload whether upload * @param mixed[] $foreigners foreigners @@ -1708,7 +1700,6 @@ class InsertEdit string $vkey, bool $insertMode, array $currentRow, - int &$tabindex, int $columnsCnt, bool $isUpload, array $foreigners, @@ -1793,7 +1784,7 @@ class InsertEdit } $idindex = ($this->rowOffset * $columnsCnt) + $columnNumber + 1; - $tabindex = $idindex; + $this->tabindex = $idindex; // The function column // ------------------- @@ -1855,7 +1846,7 @@ class InsertEdit $transformationOptions, $currentValue, $textDir, - $tabindex, + $this->tabindex, $idindex, ); @@ -1952,7 +1943,6 @@ class InsertEdit $specialChars, min(max($column['len'], 4), $GLOBALS['cfg']['LimitChars']), $onChangeClause, - $tabindex, $idindex, 'HEX', ); @@ -1964,7 +1954,6 @@ class InsertEdit $backupField, $columnNameAppendix, $onChangeClause, - $tabindex, $specialChars, $idindex, $textDir, @@ -2041,7 +2030,6 @@ class InsertEdit * @param string $vkey validation key * @param bool $insertMode whether insert mode * @param mixed[] $currentRow current row - * @param int $tabindex tab index * @param int $columnsCnt columns count * @param bool $isUpload whether upload * @param mixed[] $foreigners foreigners @@ -2062,7 +2050,6 @@ class InsertEdit string $vkey, bool $insertMode, array $currentRow, - int &$tabindex, int $columnsCnt, bool $isUpload, array $foreigners, @@ -2106,7 +2093,6 @@ class InsertEdit $vkey, $insertMode, $currentRow, - $tabindex, $columnsCnt, $isUpload, $foreigners, diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 98ddd0189d..6c3e6a4987 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4861,7 +4861,7 @@ parameters: path: libraries/classes/InsertEdit.php - - message: "#^Parameter \\#21 \\$whereClause of method PhpMyAdmin\\\\InsertEdit\\:\\:getHtmlForInsertEditFormColumn\\(\\) expects string, mixed given\\.$#" + message: "#^Parameter \\#20 \\$whereClause of method PhpMyAdmin\\\\InsertEdit\\:\\:getHtmlForInsertEditFormColumn\\(\\) expects string, mixed given\\.$#" count: 1 path: libraries/classes/InsertEdit.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 42b72e9597..99a52f4053 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -3283,7 +3283,6 @@ - @@ -3323,7 +3322,6 @@ - diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index 4b887499d5..06639686f2 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -602,11 +602,12 @@ class InsertEditTest extends AbstractTestCase $column['is_char'] = true; $column['Type'] = 'char(10)'; $column['True_Type'] = 'char'; + (new ReflectionProperty(InsertEdit::class, 'tabindex'))->setValue($this->insertEdit, 2); $result = $this->callFunction( $this->insertEdit, InsertEdit::class, 'getTextarea', - [$column, 'a', 'b', '', 2, 1, 'abc/', 'foobar', 'CHAR'], + [$column, 'a', 'b', '', 1, 'abc/', 'foobar', 'CHAR'], ); $result = $this->parseString($result); @@ -628,11 +629,12 @@ class InsertEditTest extends AbstractTestCase $column = []; $column['pma_type'] = 'date'; $column['True_Type'] = 'date'; + (new ReflectionProperty(InsertEdit::class, 'tabindex'))->setValue($this->insertEdit, 23); $result = $this->callFunction( $this->insertEdit, InsertEdit::class, 'getHtmlInput', - [$column, 'a', 'b', 30, 'c', 23, 0, 'DATE'], + [$column, 'a', 'b', 30, 'c', 0, 'DATE'], ); $this->assertEquals( @@ -648,7 +650,7 @@ class InsertEditTest extends AbstractTestCase $this->insertEdit, InsertEdit::class, 'getHtmlInput', - [$column, 'a', 'b', 30, 'c', 23, 0, 'DATE'], + [$column, 'a', 'b', 30, 'c', 0, 'DATE'], ); $this->assertEquals( 'insertEdit, InsertEdit::class, 'getHtmlInput', - [$column, 'a', 'b', 30, 'c', 23, 0, 'DATE'], + [$column, 'a', 'b', 30, 'c', 0, 'DATE'], ); $this->assertEquals( 'insertEdit, InsertEdit::class, 'getHtmlInput', - [$column, 'a', 'b', 11, 'c', 23, 0, 'INT'], + [$column, 'a', 'b', 11, 'c', 0, 'INT'], ); $this->assertEquals( 'setValue($this->insertEdit, 22); $result = $this->callFunction( $this->insertEdit, InsertEdit::class, @@ -749,7 +752,6 @@ class InsertEditTest extends AbstractTestCase 'a', 'b', 'c', - 22, '<', 1, '/', @@ -783,7 +785,6 @@ class InsertEditTest extends AbstractTestCase 'a', 'b', 'c', - 22, '<', 1, '/', @@ -814,7 +815,6 @@ class InsertEditTest extends AbstractTestCase 'a', 'b', 'c', - 22, '<', 1, '/', @@ -840,7 +840,6 @@ class InsertEditTest extends AbstractTestCase 'a', 'b', 'c', - 22, '<', 1, '/', @@ -866,7 +865,6 @@ class InsertEditTest extends AbstractTestCase 'a', 'b', 'c', - 22, '<', 1, '/', @@ -892,7 +890,6 @@ class InsertEditTest extends AbstractTestCase 'a', 'b', 'c', - 22, '<', 1, '/', @@ -2386,7 +2383,6 @@ class InsertEditTest extends AbstractTestCase public function testGetHtmlForInsertEditFormColumn(): void { $_SESSION[' HMAC_secret '] = hash('sha1', 'test'); - $tabindex = 0; $GLOBALS['plugin_scripts'] = []; $foreigners = ['foreign_keys_data' => []]; $tableColumn = [ @@ -2421,7 +2417,6 @@ class InsertEditTest extends AbstractTestCase '', false, [], - &$tabindex, 0, false, $foreigners, @@ -2478,7 +2473,6 @@ class InsertEditTest extends AbstractTestCase '[a][0]', true, [], - &$tabindex, 0, false, $foreigners, @@ -2548,7 +2542,6 @@ class InsertEditTest extends AbstractTestCase */ public function testGetHtmlForInsertEditRow(): void { - $tabindex = 0; $GLOBALS['plugin_scripts'] = []; $GLOBALS['cfg']['LongtextDoubleTextarea'] = true; $GLOBALS['cfg']['CharEditing'] = 'input'; @@ -2582,7 +2575,6 @@ class InsertEditTest extends AbstractTestCase '', false, [], - $tabindex, 1, false, $foreigners, @@ -2610,7 +2602,6 @@ class InsertEditTest extends AbstractTestCase */ public function testGetHtmlForInsertEditRowBasedOnColumnPrivileges(): void { - $tabindex = 0; $GLOBALS['plugin_scripts'] = []; $GLOBALS['cfg']['LongtextDoubleTextarea'] = true; $GLOBALS['cfg']['CharEditing'] = 'input'; @@ -2657,7 +2648,6 @@ class InsertEditTest extends AbstractTestCase '', false, [], - $tabindex, 1, false, $foreigners, @@ -2714,7 +2704,6 @@ class InsertEditTest extends AbstractTestCase '', true, [], - $tabindex, 3, false, $foreigners, From 0032b489f359b6107cd85b22f3de928807c4dc4c Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 21 Apr 2023 20:19:14 +0100 Subject: [PATCH 06/17] Merge $tabindex and $idindex into $fieldIndex Signed-off-by: Kamil Tekiela --- libraries/classes/InsertEdit.php | 28 +++++---------- .../Plugins/IOTransformationsPlugin.php | 6 ++-- .../CodeMirrorEditorTransformationPlugin.php | 6 ++-- .../Abs/ImageUploadTransformationsPlugin.php | 6 ++-- .../TextFileUploadTransformationsPlugin.php | 6 ++-- .../Input/Text_Plain_Iptobinary.php | 10 +++--- .../Input/Text_Plain_Iptolong.php | 10 +++--- test/classes/InsertEditTest.php | 36 ++++++++----------- 8 files changed, 39 insertions(+), 69 deletions(-) diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 0ba10b5118..87e65d52d1 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -78,7 +78,7 @@ class InsertEdit ]; private int $rowOffset = 0; - private int $tabindex = 0; + private int $fieldIndex = 0; public function __construct( private DatabaseInterface $dbi, @@ -426,7 +426,6 @@ class InsertEdit * @param string $backupField hidden input field * @param string $columnNameAppendix the name attribute * @param string $onChangeClause onchange clause for fields - * @param int $idindex id index * @param string $textDir text direction * @param string $specialCharsEncoded replaced char if the string starts * with a \r\n pair (0x0d0a) add an extra \n @@ -439,7 +438,6 @@ class InsertEdit string $backupField, string $columnNameAppendix, string $onChangeClause, - int $idindex, string $textDir, string $specialCharsEncoded, string $dataType, @@ -470,9 +468,9 @@ class InsertEdit . ' rows="' . $textAreaRows . '"' . ' cols="' . $textareaCols . '"' . ' dir="' . $textDir . '"' - . ' id="field_' . $idindex . '_3"' + . ' id="field_' . $this->fieldIndex . '_3"' . ($onChangeClause ? ' onchange="' . htmlspecialchars($onChangeClause, ENT_COMPAT) . '"' : '') - . ' tabindex="' . $this->tabindex . '"' + . ' tabindex="' . $this->fieldIndex . '"' . ' data-type="' . $dataType . '">' . $specialCharsEncoded . ''; @@ -486,7 +484,6 @@ class InsertEdit * @param string $specialChars special characters * @param int $fieldsize html field size * @param string $onChangeClause onchange clause for fields - * @param int $idindex id index * @param string $dataType the html5 data-* attribute type * * @return string an html snippet @@ -497,7 +494,6 @@ class InsertEdit string $specialChars, int $fieldsize, string $onChangeClause, - int $idindex, string $dataType, ): string { $theClass = 'textfield'; @@ -532,9 +528,9 @@ class InsertEdit . ($inputMinMax ? ' ' . $inputMinMax : '') . ' data-type="' . $dataType . '"' . ' class="' . $theClass . '" onchange="' . htmlspecialchars($onChangeClause, ENT_COMPAT) . '"' - . ' tabindex="' . $this->tabindex . '"' + . ' tabindex="' . $this->fieldIndex . '"' . ($isInteger ? ' inputmode="numeric"' : '') - . ' id="field_' . $idindex . '_3">'; + . ' id="field_' . $this->fieldIndex . '_3">'; } /** @@ -603,7 +599,6 @@ class InsertEdit * @param string $columnNameAppendix the name attribute * @param string $onChangeClause onchange clause for fields * @param string $specialChars special characters - * @param int $idindex id index * @param string $textDir text direction * @param string $specialCharsEncoded replaced char if the string starts * with a \r\n pair (0x0d0a) add an extra \n @@ -621,7 +616,6 @@ class InsertEdit string $columnNameAppendix, string $onChangeClause, string $specialChars, - int $idindex, string $textDir, string $specialCharsEncoded, string $data, @@ -640,7 +634,6 @@ class InsertEdit $backupField, $columnNameAppendix, $onChangeClause, - $idindex, $textDir, $specialCharsEncoded, $dataType, @@ -652,7 +645,6 @@ class InsertEdit $specialChars, $fieldsize, $onChangeClause, - $idindex, $dataType, ); } @@ -1783,8 +1775,7 @@ class InsertEdit $backupField = ''; } - $idindex = ($this->rowOffset * $columnsCnt) + $columnNumber + 1; - $this->tabindex = $idindex; + $this->fieldIndex = ($this->rowOffset * $columnsCnt) + $columnNumber + 1; // The function column // ------------------- @@ -1846,8 +1837,7 @@ class InsertEdit $transformationOptions, $currentValue, $textDir, - $this->tabindex, - $idindex, + $this->fieldIndex, ); $GLOBALS['plugin_scripts'] = array_merge( @@ -1943,7 +1933,6 @@ class InsertEdit $specialChars, min(max($column['len'], 4), $GLOBALS['cfg']['LimitChars']), $onChangeClause, - $idindex, 'HEX', ); } @@ -1955,7 +1944,6 @@ class InsertEdit $columnNameAppendix, $onChangeClause, $specialChars, - $idindex, $textDir, $specialCharsEncoded, $data, @@ -1975,7 +1963,7 @@ class InsertEdit 'function_options' => $functionOptions, 'nullify_code' => $nullifyCode, 'real_null_value' => $realNullValue, - 'id_index' => $idindex, + 'id_index' => $this->fieldIndex, 'type' => $type, 'decimals' => $noDecimals, 'special_chars' => $specialChars, diff --git a/libraries/classes/Plugins/IOTransformationsPlugin.php b/libraries/classes/Plugins/IOTransformationsPlugin.php index 814bcbabfb..bc17f4aeed 100644 --- a/libraries/classes/Plugins/IOTransformationsPlugin.php +++ b/libraries/classes/Plugins/IOTransformationsPlugin.php @@ -33,8 +33,7 @@ abstract class IOTransformationsPlugin extends TransformationsPlugin * @param mixed[] $options transformation options * @param string $value Current field value * @param string $textDir text direction - * @param int $tabIndex tab index - * @param int $idIndex id index + * @param int $fieldIndex field index * * @return string the html for input field */ @@ -45,8 +44,7 @@ abstract class IOTransformationsPlugin extends TransformationsPlugin array $options, string $value, string $textDir, - int $tabIndex, - int $idIndex, + int $fieldIndex, ): string { return ''; } diff --git a/libraries/classes/Plugins/Transformations/Abs/CodeMirrorEditorTransformationPlugin.php b/libraries/classes/Plugins/Transformations/Abs/CodeMirrorEditorTransformationPlugin.php index be5d0e6227..d0200c56cc 100644 --- a/libraries/classes/Plugins/Transformations/Abs/CodeMirrorEditorTransformationPlugin.php +++ b/libraries/classes/Plugins/Transformations/Abs/CodeMirrorEditorTransformationPlugin.php @@ -40,8 +40,7 @@ abstract class CodeMirrorEditorTransformationPlugin extends IOTransformationsPlu * @param mixed[] $options transformation options * @param string $value Current field value * @param string $textDir text direction - * @param int $tabIndex tab index - * @param int $idIndex id index + * @param int $fieldIndex field index * * @return string the html for input field */ @@ -52,8 +51,7 @@ abstract class CodeMirrorEditorTransformationPlugin extends IOTransformationsPlu array $options, string $value, string $textDir, - int $tabIndex, - int $idIndex, + int $fieldIndex, ): string { $html = ''; if (! empty($value)) { diff --git a/libraries/classes/Plugins/Transformations/Abs/ImageUploadTransformationsPlugin.php b/libraries/classes/Plugins/Transformations/Abs/ImageUploadTransformationsPlugin.php index b4586d6f7b..4b98b88aff 100644 --- a/libraries/classes/Plugins/Transformations/Abs/ImageUploadTransformationsPlugin.php +++ b/libraries/classes/Plugins/Transformations/Abs/ImageUploadTransformationsPlugin.php @@ -54,8 +54,7 @@ abstract class ImageUploadTransformationsPlugin extends IOTransformationsPlugin * @param mixed[] $options transformation options * @param string $value Current field value * @param string $textDir text direction - * @param int $tabIndex tab index - * @param int $idIndex id index + * @param int $fieldIndex field index * * @return string the html for input field */ @@ -66,8 +65,7 @@ abstract class ImageUploadTransformationsPlugin extends IOTransformationsPlugin array $options, string $value, string $textDir, - int $tabIndex, - int $idIndex, + int $fieldIndex, ): string { $html = ''; $src = ''; diff --git a/libraries/classes/Plugins/Transformations/Abs/TextFileUploadTransformationsPlugin.php b/libraries/classes/Plugins/Transformations/Abs/TextFileUploadTransformationsPlugin.php index d5ec1ea9ad..ace2274a99 100644 --- a/libraries/classes/Plugins/Transformations/Abs/TextFileUploadTransformationsPlugin.php +++ b/libraries/classes/Plugins/Transformations/Abs/TextFileUploadTransformationsPlugin.php @@ -49,8 +49,7 @@ abstract class TextFileUploadTransformationsPlugin extends IOTransformationsPlug * @param mixed[] $options transformation options * @param string $value Current field value * @param string $textDir text direction - * @param int $tabIndex tab index - * @param int $idIndex id index + * @param int $fieldIndex field index * * @return string the html for input field */ @@ -61,8 +60,7 @@ abstract class TextFileUploadTransformationsPlugin extends IOTransformationsPlug array $options, string $value, string $textDir, - int $tabIndex, - int $idIndex, + int $fieldIndex, ): string { $html = ''; if (! empty($value)) { diff --git a/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptobinary.php b/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptobinary.php index 014909b573..30d41faab4 100644 --- a/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptobinary.php +++ b/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptobinary.php @@ -56,8 +56,7 @@ class Text_Plain_Iptobinary extends IOTransformationsPlugin * @param mixed[] $options transformation options * @param string $value Current field value * @param string $textDir text direction - * @param int $tabIndex tab index - * @param int $idIndex id index + * @param int $fieldIndex field index * * @return string the html for input field */ @@ -68,8 +67,7 @@ class Text_Plain_Iptobinary extends IOTransformationsPlugin array $options, string $value, string $textDir, - int $tabIndex, - int $idIndex, + int $fieldIndex, ): string { $html = ''; $val = ''; @@ -93,8 +91,8 @@ class Text_Plain_Iptobinary extends IOTransformationsPlugin . ' size="40"' . ' dir="' . $textDir . '"' . ' class="' . $class . '"' - . ' id="field_' . $idIndex . '_3"' - . ' tabindex="' . ($tabIndex) . '">'; + . ' id="field_' . $fieldIndex . '_3"' + . ' tabindex="' . $fieldIndex . '">'; } /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */ diff --git a/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptolong.php b/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptolong.php index 95bbb63484..d16ce8aac5 100644 --- a/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptolong.php +++ b/libraries/classes/Plugins/Transformations/Input/Text_Plain_Iptolong.php @@ -53,8 +53,7 @@ class Text_Plain_Iptolong extends IOTransformationsPlugin * @param mixed[] $options transformation options * @param string $value Current field value * @param string $textDir text direction - * @param int $tabIndex tab index - * @param int $idIndex id index + * @param int $fieldIndex field index * * @return string the html for input field */ @@ -65,8 +64,7 @@ class Text_Plain_Iptolong extends IOTransformationsPlugin array $options, string $value, string $textDir, - int $tabIndex, - int $idIndex, + int $fieldIndex, ): string { $html = ''; $val = ''; @@ -85,8 +83,8 @@ class Text_Plain_Iptolong extends IOTransformationsPlugin . ' size="40"' . ' dir="' . $textDir . '"' . ' class="transform_IPToLong"' - . ' id="field_' . $idIndex . '_3"' - . ' tabindex="' . ($tabIndex) . '" />'; + . ' id="field_' . $fieldIndex . '_3"' + . ' tabindex="' . $fieldIndex . '" />'; } /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */ diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index 06639686f2..089380a34d 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -602,12 +602,12 @@ class InsertEditTest extends AbstractTestCase $column['is_char'] = true; $column['Type'] = 'char(10)'; $column['True_Type'] = 'char'; - (new ReflectionProperty(InsertEdit::class, 'tabindex'))->setValue($this->insertEdit, 2); + (new ReflectionProperty(InsertEdit::class, 'fieldIndex'))->setValue($this->insertEdit, 2); $result = $this->callFunction( $this->insertEdit, InsertEdit::class, 'getTextarea', - [$column, 'a', 'b', '', 1, 'abc/', 'foobar', 'CHAR'], + [$column, 'a', 'b', '', 'abc/', 'foobar', 'CHAR'], ); $result = $this->parseString($result); @@ -615,7 +615,7 @@ class InsertEditTest extends AbstractTestCase $this->assertStringContainsString( '', $result, ); @@ -786,7 +785,6 @@ class InsertEditTest extends AbstractTestCase 'b', 'c', '<', - 1, '/', '<', "foo\nbar", @@ -797,7 +795,7 @@ class InsertEditTest extends AbstractTestCase $this->assertEquals( "a\n" . '' . '', $result, @@ -816,7 +814,6 @@ class InsertEditTest extends AbstractTestCase 'b', 'c', '<', - 1, '/', '<', "foo\nbar", @@ -841,7 +838,6 @@ class InsertEditTest extends AbstractTestCase 'b', 'c', '<', - 1, '/', '<', "foo\nbar", @@ -866,7 +862,6 @@ class InsertEditTest extends AbstractTestCase 'b', 'c', '<', - 1, '/', '<', "foo\nbar", @@ -891,7 +886,6 @@ class InsertEditTest extends AbstractTestCase 'b', 'c', '<', - 1, '/', '<', "foo\nbar", From 1e14d588a7a62093387ee47397a4c10fb911c537 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 21 Apr 2023 20:30:07 +0100 Subject: [PATCH 07/17] Replace ternary with boolean condition Signed-off-by: Kamil Tekiela --- libraries/classes/InsertEdit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 87e65d52d1..0c6b2e2e73 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -342,7 +342,7 @@ class InsertEdit }; // can only occur once per table - $column['first_timestamp'] = $column['True_Type'] === 'timestamp' ? ! $timestampSeen : false; + $column['first_timestamp'] = $column['True_Type'] === 'timestamp' && ! $timestampSeen; return $column; } From b2357568a1aead75f59909e4af25d1e1db773f36 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 21 Apr 2023 20:32:21 +0100 Subject: [PATCH 08/17] Use str_ends_with and str_starts_with Signed-off-by: Kamil Tekiela --- .../classes/Controllers/Table/ChangeController.php | 4 ++-- libraries/classes/InsertEdit.php | 10 ++++++---- phpstan-baseline.neon | 10 +++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libraries/classes/Controllers/Table/ChangeController.php b/libraries/classes/Controllers/Table/ChangeController.php index f98c846fc9..c749040b23 100644 --- a/libraries/classes/Controllers/Table/ChangeController.php +++ b/libraries/classes/Controllers/Table/ChangeController.php @@ -22,8 +22,8 @@ use function count; use function is_array; use function is_string; use function str_contains; +use function str_starts_with; use function strlen; -use function strpos; use function trim; /** @@ -118,7 +118,7 @@ class ChangeController extends AbstractController $sqlQuery = $request->getParsedBodyParam('sql_query'); $GLOBALS['urlParams'] = ['db' => $GLOBALS['db'], 'sql_query' => is_string($sqlQuery) ? $sqlQuery : '']; - if (strpos($GLOBALS['goto'] ?? '', 'index.php?route=/table') === 0) { + if (str_starts_with($GLOBALS['goto'] ?? '', 'index.php?route=/table')) { $GLOBALS['urlParams']['table'] = $GLOBALS['table']; } diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 0c6b2e2e73..fac812e3c4 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -39,7 +39,9 @@ use function password_hash; use function preg_match; use function preg_replace; use function str_contains; +use function str_ends_with; use function str_replace; +use function str_starts_with; use function stripcslashes; use function stripslashes; use function strlen; @@ -816,7 +818,7 @@ class InsertEdit (int) $extractedColumnspec['spec_in_brackets'], ); } elseif ( - (substr($column['True_Type'], 0, 9) === 'timestamp' + (str_starts_with($column['True_Type'], 'timestamp') || $column['True_Type'] === 'datetime' || $column['True_Type'] === 'time') && (str_contains($currentRow[$column['Field']], '.')) @@ -883,11 +885,11 @@ class InsertEdit if ($trueType === 'bit') { $specialChars = Util::convertBitDefaultValue($defaultValue); - } elseif (substr($trueType, 0, 9) === 'timestamp' || $trueType === 'datetime' || $trueType === 'time') { + } elseif (str_starts_with($trueType, 'timestamp') || $trueType === 'datetime' || $trueType === 'time') { $specialChars = Util::addMicroseconds($defaultValue); } elseif ($trueType === 'binary' || $trueType === 'varbinary') { $specialChars = bin2hex($defaultValue); - } elseif (substr($trueType, -4) === 'text') { + } elseif (str_ends_with($trueType, 'text')) { $textDefault = substr($defaultValue, 1, -1); $specialChars = stripcslashes($textDefault !== '' ? $textDefault : $defaultValue); } else { @@ -1419,7 +1421,7 @@ class InsertEdit } if ($editField->type === 'hex') { - if (substr($editField->value, 0, 2) != '0x') { + if (! str_starts_with($editField->value, '0x')) { return '0x' . $editField->value; } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6c3e6a4987..50393e3e2b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4785,6 +4785,11 @@ parameters: count: 1 path: libraries/classes/InsertEdit.php + - + message: "#^Parameter \\#1 \\$haystack of function str_starts_with expects string, mixed given\\.$#" + count: 1 + path: libraries/classes/InsertEdit.php + - message: "#^Parameter \\#1 \\$optionString of method PhpMyAdmin\\\\Transformations\\:\\:getOptions\\(\\) expects string, mixed given\\.$#" count: 1 @@ -4815,11 +4820,6 @@ parameters: count: 1 path: libraries/classes/InsertEdit.php - - - message: "#^Parameter \\#1 \\$string of function substr expects string, mixed given\\.$#" - count: 1 - path: libraries/classes/InsertEdit.php - - message: "#^Parameter \\#1 \\$string of function trim expects string, mixed given\\.$#" count: 1 From bfe1f4facf526f0baef23151c5f9526f82a4ab48 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 21 Apr 2023 20:33:13 +0100 Subject: [PATCH 09/17] Remove redundant argument Signed-off-by: Kamil Tekiela --- libraries/classes/Controllers/Table/ChangeController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/classes/Controllers/Table/ChangeController.php b/libraries/classes/Controllers/Table/ChangeController.php index c749040b23..7bb9cfd911 100644 --- a/libraries/classes/Controllers/Table/ChangeController.php +++ b/libraries/classes/Controllers/Table/ChangeController.php @@ -148,7 +148,7 @@ class ChangeController extends AbstractController * $disp_message come from /table/replace */ if (! empty($GLOBALS['disp_message'])) { - $this->response->addHTML(Generator::getMessage($GLOBALS['disp_message'], null)); + $this->response->addHTML(Generator::getMessage($GLOBALS['disp_message'])); } $GLOBALS['table_columns'] = $this->insertEdit->getTableColumns($GLOBALS['db'], $GLOBALS['table']); From 9a8fec903f8d8995269a2801f0a651dcfdd89a8a Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 21 Apr 2023 20:50:19 +0100 Subject: [PATCH 10/17] Replace escapeString with quoteString Signed-off-by: Kamil Tekiela --- libraries/classes/InsertEdit.php | 3 +-- psalm-baseline.xml | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index fac812e3c4..16c8c82874 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -1272,8 +1272,7 @@ class InsertEdit || in_array($editField->function, $this->getGisFromWKBFunctions()) ) { preg_match('/^(\'?)(.*?)\1(?:,(\d+))?$/', $editField->value, $matches); - $escapedParams = "'" . $this->dbi->escapeString($matches[2]) - . (isset($matches[3]) ? "'," . $matches[3] : "'"); + $escapedParams = $this->dbi->quoteString($matches[2]) . (isset($matches[3]) ? ',' . $matches[3] : ''); return $editField->function . '(' . $escapedParams . ')'; } diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 99a52f4053..d1bd79a7db 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -7876,9 +7876,6 @@ - - escapeString - $urlParams From c3701e3fea6d48e5383b71582c8eda93a10f92d1 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 21 Apr 2023 20:54:14 +0100 Subject: [PATCH 11/17] Remove no longer needed @psalm-suppress Signed-off-by: Kamil Tekiela --- libraries/classes/InsertEdit.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 16c8c82874..2e84d2bc1a 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -1250,11 +1250,6 @@ class InsertEdit EditField $editField, ): string { if ($editField->function === 'PHP_PASSWORD_HASH') { - /** - * @see https://github.com/vimeo/psalm/issues/3350 - * - * @psalm-suppress InvalidArgument - */ $hash = password_hash($editField->value, PASSWORD_DEFAULT); return $this->dbi->quoteString($hash); From 39035f91f974b3980f0f25c75129f1657c7f6905 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sat, 22 Apr 2023 14:56:20 +0100 Subject: [PATCH 12/17] Remove strlen Signed-off-by: Kamil Tekiela --- libraries/classes/InsertEdit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 2e84d2bc1a..4af0410098 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -1104,7 +1104,7 @@ class InsertEdit $displayField = $this->relation->getDisplayField($foreigner['foreign_db'], $foreigner['foreign_table']); // Field to display from the foreign table? - if (is_string($displayField) && strlen($displayField) > 0) { + if (is_string($displayField) && $displayField !== '') { $dispsql = 'SELECT ' . Util::backquote($displayField) . ' FROM ' . Util::backquote($foreigner['foreign_db']) . '.' . Util::backquote($foreigner['foreign_table']) From 9124c19539e448a2f9c212516178e97cc16f5d57 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sat, 22 Apr 2023 15:04:28 +0100 Subject: [PATCH 13/17] Remove $GLOBALS['columns_cnt'] Signed-off-by: Kamil Tekiela --- .../classes/Controllers/Table/ChangeController.php | 10 +++------- libraries/classes/InsertEdit.php | 7 +++---- psalm-baseline.xml | 4 ---- test/classes/InsertEditTest.php | 5 +---- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/libraries/classes/Controllers/Table/ChangeController.php b/libraries/classes/Controllers/Table/ChangeController.php index 7bb9cfd911..bfba96a8f3 100644 --- a/libraries/classes/Controllers/Table/ChangeController.php +++ b/libraries/classes/Controllers/Table/ChangeController.php @@ -56,9 +56,7 @@ class ChangeController extends AbstractController $GLOBALS['found_unique_key'] ??= null; $GLOBALS['after_insert'] ??= null; $GLOBALS['comments_map'] ??= null; - $GLOBALS['table_columns'] ??= null; $GLOBALS['timestamp_seen'] ??= null; - $GLOBALS['columns_cnt'] ??= null; $GLOBALS['has_blob_field'] ??= null; $GLOBALS['jsvkey'] ??= null; $GLOBALS['vkey'] ??= null; @@ -151,7 +149,7 @@ class ChangeController extends AbstractController $this->response->addHTML(Generator::getMessage($GLOBALS['disp_message'])); } - $GLOBALS['table_columns'] = $this->insertEdit->getTableColumns($GLOBALS['db'], $GLOBALS['table']); + $tableColumns = $this->insertEdit->getTableColumns($GLOBALS['db'], $GLOBALS['table']); // retrieve keys into foreign fields, if any $foreigners = $this->relation->getForeigners($GLOBALS['db'], $GLOBALS['table']); @@ -174,14 +172,13 @@ class ChangeController extends AbstractController $htmlOutput = ''; // Set if we passed the first timestamp field $GLOBALS['timestamp_seen'] = false; - $GLOBALS['columns_cnt'] = count($GLOBALS['table_columns']); $GLOBALS['urlParams']['db'] = $GLOBALS['db']; $GLOBALS['urlParams']['table'] = $GLOBALS['table']; $GLOBALS['urlParams'] = $this->urlParamsInEditMode($GLOBALS['urlParams'], $GLOBALS['where_clause_array']); $GLOBALS['has_blob_field'] = false; - foreach ($GLOBALS['table_columns'] as $column) { + foreach ($tableColumns as $column) { if ($this->insertEdit->isColumn($column, ['blob', 'tinyblob', 'mediumblob', 'longblob'])) { $GLOBALS['has_blob_field'] = true; break; @@ -235,7 +232,7 @@ class ChangeController extends AbstractController $htmlOutput .= $this->insertEdit->getHtmlForInsertEditRow( $GLOBALS['urlParams'], - $GLOBALS['table_columns'], + $tableColumns, $GLOBALS['comments_map'], $GLOBALS['timestamp_seen'], $GLOBALS['current_result'], @@ -243,7 +240,6 @@ class ChangeController extends AbstractController $GLOBALS['vkey'], $GLOBALS['insert_mode'], $currentRow, - $GLOBALS['columns_cnt'], $isUpload, $foreigners, $GLOBALS['table'], diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 4af0410098..a5a8a42d0f 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -2014,7 +2014,6 @@ class InsertEdit * @param string $vkey validation key * @param bool $insertMode whether insert mode * @param mixed[] $currentRow current row - * @param int $columnsCnt columns count * @param bool $isUpload whether upload * @param mixed[] $foreigners foreigners * @param string $table table @@ -2034,7 +2033,6 @@ class InsertEdit string $vkey, bool $insertMode, array $currentRow, - int $columnsCnt, bool $isUpload, array $foreigners, string $table, @@ -2055,7 +2053,8 @@ class InsertEdit $whereClause = $whereClauseArray[$rowId]; } - for ($columnNumber = 0; $columnNumber < $columnsCnt; $columnNumber++) { + $columnCount = count($tableColumns); + for ($columnNumber = 0; $columnNumber < $columnCount; $columnNumber++) { $tableColumn = $tableColumns[$columnNumber]; $columnMime = []; if (isset($mimeMap[$tableColumn['Field']])) { @@ -2077,7 +2076,7 @@ class InsertEdit $vkey, $insertMode, $currentRow, - $columnsCnt, + $columnCount, $isUpload, $foreigners, $table, diff --git a/psalm-baseline.xml b/psalm-baseline.xml index d1bd79a7db..159a46dd73 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -3271,7 +3271,6 @@ - @@ -3283,7 +3282,6 @@ - @@ -3309,7 +3307,6 @@ - @@ -3322,7 +3319,6 @@ - diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index 089380a34d..65de5ba894 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -2569,7 +2569,6 @@ class InsertEditTest extends AbstractTestCase '', false, [], - 1, false, $foreigners, 'table', @@ -2642,7 +2641,6 @@ class InsertEditTest extends AbstractTestCase '', false, [], - 1, false, $foreigners, 'table', @@ -2653,7 +2651,7 @@ class InsertEditTest extends AbstractTestCase ['wc'], ); $this->assertStringContainsString('foo', $actual); - $this->assertStringNotContainsString('bar', $actual); + $this->assertStringContainsString('bar', $actual); // insert $tableColumns = [ @@ -2698,7 +2696,6 @@ class InsertEditTest extends AbstractTestCase '', true, [], - 3, false, $foreigners, 'table', From fbb185e7a912774319ae22a54dad6fe83f1b41bc Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sat, 22 Apr 2023 15:10:26 +0100 Subject: [PATCH 14/17] Remove globals Signed-off-by: Kamil Tekiela --- .../Controllers/Table/ChangeController.php | 91 ++++++++----------- phpstan-baseline.neon | 20 +++- psalm-baseline.xml | 30 +----- 3 files changed, 54 insertions(+), 87 deletions(-) diff --git a/libraries/classes/Controllers/Table/ChangeController.php b/libraries/classes/Controllers/Table/ChangeController.php index bfba96a8f3..beb8ec92da 100644 --- a/libraries/classes/Controllers/Table/ChangeController.php +++ b/libraries/classes/Controllers/Table/ChangeController.php @@ -48,21 +48,8 @@ class ChangeController extends AbstractController $GLOBALS['errorUrl'] ??= null; $GLOBALS['where_clause'] ??= null; $GLOBALS['unsaved_values'] ??= null; - $GLOBALS['insert_mode'] ??= null; - $GLOBALS['where_clause_array'] ??= null; - $GLOBALS['where_clauses'] ??= null; $GLOBALS['result'] ??= null; - $GLOBALS['rows'] ??= null; - $GLOBALS['found_unique_key'] ??= null; - $GLOBALS['after_insert'] ??= null; - $GLOBALS['comments_map'] ??= null; - $GLOBALS['timestamp_seen'] ??= null; - $GLOBALS['has_blob_field'] ??= null; - $GLOBALS['jsvkey'] ??= null; - $GLOBALS['vkey'] ??= null; $GLOBALS['current_result'] ??= null; - $GLOBALS['repopulate'] ??= null; - $GLOBALS['checked'] ??= null; $pageSettings = new PageSettings('Edit'); $this->response->addHTML($pageSettings->getErrorHTML()); @@ -81,22 +68,22 @@ class ChangeController extends AbstractController * Determine whether Insert or Edit and set global variables */ [ - $GLOBALS['insert_mode'], + $insertMode, $GLOBALS['where_clause'], - $GLOBALS['where_clause_array'], - $GLOBALS['where_clauses'], + $whereClauseArray, + $whereClauses, $GLOBALS['result'], - $GLOBALS['rows'], - $GLOBALS['found_unique_key'], - $GLOBALS['after_insert'], + $rows, + $foundUniqueIndex, + $afterInsert, ] = $this->insertEdit->determineInsertOrEdit( $GLOBALS['where_clause'] ?? null, $GLOBALS['db'], $GLOBALS['table'], ); // Increase number of rows if unsaved rows are more - if (! empty($GLOBALS['unsaved_values']) && count($GLOBALS['rows']) < count($GLOBALS['unsaved_values'])) { - $GLOBALS['rows'] = array_fill(0, count($GLOBALS['unsaved_values']), false); + if (! empty($GLOBALS['unsaved_values']) && count($rows) < count($GLOBALS['unsaved_values'])) { + $rows = array_fill(0, count($GLOBALS['unsaved_values']), false); } /** @@ -126,7 +113,7 @@ class ChangeController extends AbstractController ); unset($GLOBALS['urlParams']); - $GLOBALS['comments_map'] = $this->insertEdit->getCommentsMap($GLOBALS['db'], $GLOBALS['table']); + $commentsMap = $this->insertEdit->getCommentsMap($GLOBALS['db'], $GLOBALS['table']); /** * START REGULAR OUTPUT @@ -158,8 +145,8 @@ class ChangeController extends AbstractController $formParams = $this->insertEdit->getFormParametersForInsertForm( $GLOBALS['db'], $GLOBALS['table'], - $GLOBALS['where_clauses'], - $GLOBALS['where_clause_array'], + $whereClauses, + $whereClauseArray, $GLOBALS['errorUrl'], ); @@ -171,16 +158,16 @@ class ChangeController extends AbstractController $htmlOutput = ''; // Set if we passed the first timestamp field - $GLOBALS['timestamp_seen'] = false; + $timestampSeen = false; $GLOBALS['urlParams']['db'] = $GLOBALS['db']; $GLOBALS['urlParams']['table'] = $GLOBALS['table']; - $GLOBALS['urlParams'] = $this->urlParamsInEditMode($GLOBALS['urlParams'], $GLOBALS['where_clause_array']); + $GLOBALS['urlParams'] = $this->urlParamsInEditMode($GLOBALS['urlParams'], $whereClauseArray); - $GLOBALS['has_blob_field'] = false; + $hasBlobField = false; foreach ($tableColumns as $column) { if ($this->insertEdit->isColumn($column, ['blob', 'tinyblob', 'mediumblob', 'longblob'])) { - $GLOBALS['has_blob_field'] = true; + $hasBlobField = true; break; } } @@ -188,7 +175,7 @@ class ChangeController extends AbstractController //Insert/Edit form //If table has blob fields we have to disable ajax. $isUpload = $GLOBALS['config']->get('enable_upload'); - $htmlOutput .= $this->insertEdit->getHtmlForInsertEditFormHeader($GLOBALS['has_blob_field'], $isUpload); + $htmlOutput .= $this->insertEdit->getHtmlForInsertEditFormHeader($hasBlobField, $isUpload); $htmlOutput .= Url::getHiddenInputs($formParams); @@ -207,38 +194,38 @@ class ChangeController extends AbstractController } $GLOBALS['plugin_scripts'] = []; - foreach ($GLOBALS['rows'] as $rowId => $currentRow) { + foreach ($rows as $rowId => $currentRow) { if (empty($currentRow)) { $currentRow = []; } - $GLOBALS['jsvkey'] = (string) $rowId; - $GLOBALS['vkey'] = '[multi_edit][' . $GLOBALS['jsvkey'] . ']'; + $jsvkey = (string) $rowId; + $vkey = '[multi_edit][' . $jsvkey . ']'; $GLOBALS['current_result'] = (isset($GLOBALS['result']) && is_array($GLOBALS['result']) && isset($GLOBALS['result'][$rowId]) ? $GLOBALS['result'][$rowId] : $GLOBALS['result']); - $GLOBALS['repopulate'] = []; - $GLOBALS['checked'] = true; + $repopulate = []; + $checked = true; if (isset($GLOBALS['unsaved_values'][$rowId])) { - $GLOBALS['repopulate'] = $GLOBALS['unsaved_values'][$rowId]; - $GLOBALS['checked'] = false; + $repopulate = $GLOBALS['unsaved_values'][$rowId]; + $checked = false; } - if ($GLOBALS['insert_mode'] && $rowId > 0) { - $htmlOutput .= $this->insertEdit->getHtmlForIgnoreOption($rowId, $GLOBALS['checked']); + if ($insertMode && $rowId > 0) { + $htmlOutput .= $this->insertEdit->getHtmlForIgnoreOption($rowId, $checked); } $htmlOutput .= $this->insertEdit->getHtmlForInsertEditRow( $GLOBALS['urlParams'], $tableColumns, - $GLOBALS['comments_map'], - $GLOBALS['timestamp_seen'], + $commentsMap, + $timestampSeen, $GLOBALS['current_result'], - $GLOBALS['jsvkey'], - $GLOBALS['vkey'], - $GLOBALS['insert_mode'], + $jsvkey, + $vkey, + $insertMode, $currentRow, $isUpload, $foreigners, @@ -246,24 +233,20 @@ class ChangeController extends AbstractController $GLOBALS['db'], $rowId, $GLOBALS['text_dir'], - $GLOBALS['repopulate'], - $GLOBALS['where_clause_array'], + $repopulate, + $whereClauseArray, ); } $this->addScriptFiles($GLOBALS['plugin_scripts']); - unset($GLOBALS['unsaved_values'], $GLOBALS['checked'], $GLOBALS['repopulate'], $GLOBALS['plugin_scripts']); - - if (! isset($GLOBALS['after_insert'])) { - $GLOBALS['after_insert'] = 'back'; - } + unset($GLOBALS['unsaved_values'], $GLOBALS['plugin_scripts']); $isNumeric = InsertEdit::isWhereClauseNumeric($GLOBALS['where_clause']); $htmlOutput .= $this->template->render('table/insert/actions_panel', [ 'where_clause' => $GLOBALS['where_clause'], - 'after_insert' => $GLOBALS['after_insert'], - 'found_unique_key' => $GLOBALS['found_unique_key'], + 'after_insert' => $afterInsert ?? 'back', + 'found_unique_key' => $foundUniqueIndex, 'is_numeric' => $isNumeric, ]); @@ -272,12 +255,12 @@ class ChangeController extends AbstractController $htmlOutput .= $this->insertEdit->getHtmlForGisEditor(); // end Insert/Edit form - if ($GLOBALS['insert_mode']) { + if ($insertMode) { //Continue insertion form $htmlOutput .= $this->insertEdit->getContinueInsertionForm( $GLOBALS['table'], $GLOBALS['db'], - $GLOBALS['where_clause_array'], + $whereClauseArray, $GLOBALS['errorUrl'], ); } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 50393e3e2b..7f98021322 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2080,6 +2080,11 @@ parameters: count: 1 path: libraries/classes/Controllers/Table/AddFieldController.php + - + message: "#^Parameter \\#1 \\$rowId of method PhpMyAdmin\\\\InsertEdit\\:\\:getHtmlForIgnoreOption\\(\\) expects int, \\(int\\<1, max\\>\\|string\\) given\\.$#" + count: 1 + path: libraries/classes/Controllers/Table/ChangeController.php + - message: "#^Parameter \\#1 \\$sqlQuery of static method PhpMyAdmin\\\\Core\\:\\:checkSqlQuerySignature\\(\\) expects string, mixed given\\.$#" count: 1 @@ -2090,6 +2095,11 @@ parameters: count: 1 path: libraries/classes/Controllers/Table/ChangeController.php + - + message: "#^Parameter \\#11 \\$rowId of method PhpMyAdmin\\\\InsertEdit\\:\\:getHtmlForInsertEditRow\\(\\) expects int, \\(int\\|string\\) given\\.$#" + count: 1 + path: libraries/classes/Controllers/Table/ChangeController.php + - message: "#^Parameter \\#2 \\$signature of static method PhpMyAdmin\\\\Core\\:\\:checkSqlQuerySignature\\(\\) expects string, mixed given\\.$#" count: 1 @@ -4845,6 +4855,11 @@ parameters: count: 1 path: libraries/classes/InsertEdit.php + - + message: "#^Parameter \\#17 \\$whereClause of method PhpMyAdmin\\\\InsertEdit\\:\\:getHtmlForInsertEditFormColumn\\(\\) expects string, mixed given\\.$#" + count: 1 + path: libraries/classes/InsertEdit.php + - message: "#^Parameter \\#2 \\$column of method PhpMyAdmin\\\\ConfigStorage\\\\Relation\\:\\:searchColumnInForeigners\\(\\) expects string, mixed given\\.$#" count: 1 @@ -4860,11 +4875,6 @@ parameters: count: 1 path: libraries/classes/InsertEdit.php - - - message: "#^Parameter \\#20 \\$whereClause of method PhpMyAdmin\\\\InsertEdit\\:\\:getHtmlForInsertEditFormColumn\\(\\) expects string, mixed given\\.$#" - count: 1 - path: libraries/classes/InsertEdit.php - - message: "#^Parameter \\#3 \\$row of static method PhpMyAdmin\\\\Util\\:\\:getUniqueCondition\\(\\) expects array\\, mixed given\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 159a46dd73..0ca294baf2 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -3269,33 +3269,20 @@ - - - - - - - - - - - - - - $isUpload + $repopulate getQueryParam('where_clause_signature')]]> $whereClause $whereClause @@ -3305,27 +3292,14 @@ $rowId - - - - - - - - - - - - - - $isUpload + $repopulate $whereClause $whereClause From ae5b5a1a865d7d6f77806bc85cde46cdebdf93df Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 23 Apr 2023 00:47:32 +0100 Subject: [PATCH 15/17] Remove $jsvkey and $vkey Signed-off-by: Kamil Tekiela --- .../classes/Controllers/Table/ChangeController.php | 5 ----- libraries/classes/InsertEdit.php | 13 ++----------- test/classes/InsertEditTest.php | 14 ++------------ 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/libraries/classes/Controllers/Table/ChangeController.php b/libraries/classes/Controllers/Table/ChangeController.php index beb8ec92da..51316ff3de 100644 --- a/libraries/classes/Controllers/Table/ChangeController.php +++ b/libraries/classes/Controllers/Table/ChangeController.php @@ -199,9 +199,6 @@ class ChangeController extends AbstractController $currentRow = []; } - $jsvkey = (string) $rowId; - $vkey = '[multi_edit][' . $jsvkey . ']'; - $GLOBALS['current_result'] = (isset($GLOBALS['result']) && is_array($GLOBALS['result']) && isset($GLOBALS['result'][$rowId]) ? $GLOBALS['result'][$rowId] @@ -223,8 +220,6 @@ class ChangeController extends AbstractController $commentsMap, $timestampSeen, $GLOBALS['current_result'], - $jsvkey, - $vkey, $insertMode, $currentRow, $isUpload, diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index a5a8a42d0f..33e3bed433 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -1662,8 +1662,6 @@ class InsertEdit * @param mixed[] $commentsMap comments map * @param bool $timestampSeen whether timestamp seen * @param ResultInterface $currentResult current result - * @param string $jsvkey javascript validation key - * @param string $vkey validation key * @param bool $insertMode whether insert mode * @param mixed[] $currentRow current row * @param int $columnsCnt columns count @@ -1684,8 +1682,6 @@ class InsertEdit array $commentsMap, bool $timestampSeen, ResultInterface $currentResult, - string $jsvkey, - string $vkey, bool $insertMode, array $currentRow, int $columnsCnt, @@ -1726,8 +1722,9 @@ class InsertEdit //Call validation when the form submitted... $onChangeClause = 'return verificationsAfterFieldChange(' . json_encode($fieldHashMd5) . ', ' - . json_encode($jsvkey) . ',' . json_encode($column['pma_type']) . ')'; + . json_encode((string) $rowId) . ',' . json_encode($column['pma_type']) . ')'; + $vkey = '[multi_edit][' . $rowId . ']'; // Use an MD5 as an array index to avoid having special characters // in the name attribute (see bug #1746964 ) $columnNameAppendix = $vkey . '[' . $fieldHashMd5 . ']'; @@ -2010,8 +2007,6 @@ class InsertEdit * @param mixed[] $commentsMap comments map * @param bool $timestampSeen whether timestamp seen * @param ResultInterface $currentResult current result - * @param string $jsvkey javascript validation key - * @param string $vkey validation key * @param bool $insertMode whether insert mode * @param mixed[] $currentRow current row * @param bool $isUpload whether upload @@ -2029,8 +2024,6 @@ class InsertEdit array $commentsMap, bool $timestampSeen, ResultInterface $currentResult, - string $jsvkey, - string $vkey, bool $insertMode, array $currentRow, bool $isUpload, @@ -2072,8 +2065,6 @@ class InsertEdit $commentsMap, $timestampSeen, $currentResult, - $jsvkey, - $vkey, $insertMode, $currentRow, $columnCount, diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index 65de5ba894..8d4812f380 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -2407,8 +2407,6 @@ class InsertEditTest extends AbstractTestCase [], false, $resultStub, - '', - '', false, [], 0, @@ -2435,7 +2433,7 @@ class InsertEditTest extends AbstractTestCase $this->assertStringContainsString('Image preview here', $actual); $this->assertStringContainsString( '', @@ -2463,8 +2461,6 @@ class InsertEditTest extends AbstractTestCase [], false, $resultStub, - '', - '[a][0]', true, [], 0, @@ -2487,7 +2483,7 @@ class InsertEditTest extends AbstractTestCase $this->assertStringContainsString('', $actual); $this->assertStringContainsString('datetime', $actual); $this->assertStringContainsString( - ' Date: Sun, 23 Apr 2023 00:50:17 +0100 Subject: [PATCH 16/17] Change if into its short form Signed-off-by: Kamil Tekiela --- libraries/classes/Controllers/Table/ChangeController.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libraries/classes/Controllers/Table/ChangeController.php b/libraries/classes/Controllers/Table/ChangeController.php index 51316ff3de..1141307e34 100644 --- a/libraries/classes/Controllers/Table/ChangeController.php +++ b/libraries/classes/Controllers/Table/ChangeController.php @@ -195,10 +195,6 @@ class ChangeController extends AbstractController $GLOBALS['plugin_scripts'] = []; foreach ($rows as $rowId => $currentRow) { - if (empty($currentRow)) { - $currentRow = []; - } - $GLOBALS['current_result'] = (isset($GLOBALS['result']) && is_array($GLOBALS['result']) && isset($GLOBALS['result'][$rowId]) ? $GLOBALS['result'][$rowId] @@ -221,7 +217,7 @@ class ChangeController extends AbstractController $timestampSeen, $GLOBALS['current_result'], $insertMode, - $currentRow, + $currentRow ?: [], $isUpload, $foreigners, $GLOBALS['table'], From a01eefc4c2103811b99e9ce0ca80031e5ea653a7 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 23 Apr 2023 00:56:53 +0100 Subject: [PATCH 17/17] Remove $timestampSeen which was always false Signed-off-by: Kamil Tekiela --- .../Controllers/Table/ChangeController.php | 3 --- libraries/classes/InsertEdit.php | 15 ++++----------- test/classes/InsertEditTest.php | 7 +------ 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/libraries/classes/Controllers/Table/ChangeController.php b/libraries/classes/Controllers/Table/ChangeController.php index 1141307e34..5d49e387aa 100644 --- a/libraries/classes/Controllers/Table/ChangeController.php +++ b/libraries/classes/Controllers/Table/ChangeController.php @@ -157,8 +157,6 @@ class ChangeController extends AbstractController // some browsers send wrongly this form to the http server. $htmlOutput = ''; - // Set if we passed the first timestamp field - $timestampSeen = false; $GLOBALS['urlParams']['db'] = $GLOBALS['db']; $GLOBALS['urlParams']['table'] = $GLOBALS['table']; @@ -214,7 +212,6 @@ class ChangeController extends AbstractController $GLOBALS['urlParams'], $tableColumns, $commentsMap, - $timestampSeen, $GLOBALS['current_result'], $insertMode, $currentRow ?: [], diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 33e3bed433..d86c1d40c9 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -304,16 +304,14 @@ class InsertEdit /** * Analyze the table column array * - * @param mixed[] $column description of column in given table - * @param mixed[] $commentsMap comments for every column that has a comment - * @param bool $timestampSeen whether a timestamp has been seen + * @param mixed[] $column description of column in given table + * @param mixed[] $commentsMap comments for every column that has a comment * * @return mixed[] description of column in given table */ private function analyzeTableColumnsArray( array $column, array $commentsMap, - bool $timestampSeen, ): array { $column['Field_md5'] = md5($column['Field']); // True_Type contains only the type (stops at first bracket) @@ -344,7 +342,7 @@ class InsertEdit }; // can only occur once per table - $column['first_timestamp'] = $column['True_Type'] === 'timestamp' && ! $timestampSeen; + $column['first_timestamp'] = $column['True_Type'] === 'timestamp'; return $column; } @@ -1660,7 +1658,6 @@ class InsertEdit * @param mixed[] $column column * @param int $columnNumber column index in table_columns * @param mixed[] $commentsMap comments map - * @param bool $timestampSeen whether timestamp seen * @param ResultInterface $currentResult current result * @param bool $insertMode whether insert mode * @param mixed[] $currentRow current row @@ -1680,7 +1677,6 @@ class InsertEdit array $column, int $columnNumber, array $commentsMap, - bool $timestampSeen, ResultInterface $currentResult, bool $insertMode, array $currentRow, @@ -1697,7 +1693,7 @@ class InsertEdit string $whereClause, ): string { if (! isset($column['processed'])) { - $column = $this->analyzeTableColumnsArray($column, $commentsMap, $timestampSeen); + $column = $this->analyzeTableColumnsArray($column, $commentsMap); } $asIs = false; @@ -2005,7 +2001,6 @@ class InsertEdit * @param mixed[] $urlParams url parameters * @param mixed[][] $tableColumns table columns * @param mixed[] $commentsMap comments map - * @param bool $timestampSeen whether timestamp seen * @param ResultInterface $currentResult current result * @param bool $insertMode whether insert mode * @param mixed[] $currentRow current row @@ -2022,7 +2017,6 @@ class InsertEdit array $urlParams, array $tableColumns, array $commentsMap, - bool $timestampSeen, ResultInterface $currentResult, bool $insertMode, array $currentRow, @@ -2063,7 +2057,6 @@ class InsertEdit $tableColumn, $columnNumber, $commentsMap, - $timestampSeen, $currentResult, $insertMode, $currentRow, diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index 8d4812f380..a36373be94 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -419,7 +419,7 @@ class InsertEditTest extends AbstractTestCase $this->insertEdit, InsertEdit::class, 'analyzeTableColumnsArray', - [$column, [], false], + [$column, []], ); $this->assertEquals($result['Field_md5'], '4342210df36bf2ff2c4e2a997a6d4089'); @@ -2405,7 +2405,6 @@ class InsertEditTest extends AbstractTestCase $tableColumn, 0, [], - false, $resultStub, false, [], @@ -2459,7 +2458,6 @@ class InsertEditTest extends AbstractTestCase $tableColumn, 0, [], - false, $resultStub, true, [], @@ -2559,7 +2557,6 @@ class InsertEditTest extends AbstractTestCase [], $tableColumns, [], - false, $resultStub, false, [], @@ -2629,7 +2626,6 @@ class InsertEditTest extends AbstractTestCase [], $tableColumns, [], - false, $resultStub, false, [], @@ -2682,7 +2678,6 @@ class InsertEditTest extends AbstractTestCase [], $tableColumns, [], - false, $resultStub, true, [],