Merge pull request #18988 from kamil-tekiela/CentralColumns

Refactor Central columns
This commit is contained in:
Maurício Meneghini Fauth 2024-02-18 19:09:58 -03:00 committed by GitHub
commit 58752f926c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 370 additions and 513 deletions

View File

@ -1411,12 +1411,17 @@ parameters:
path: src/Controllers/Database/CentralColumns/PopulateColumnsController.php
-
message: "#^Parameter \\#1 \\$database of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:deleteColumnsFromList\\(\\) expects string, mixed given\\.$#"
message: "#^Parameter \\#1 \\$colName of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#1 \\$fieldSelect of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:syncUniqueColumns\\(\\) expects array\\<string\\>, array\\<int, mixed\\> given\\.$#"
message: "#^Parameter \\#1 \\$colName of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#1 \\$database of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:deleteColumnsFromList\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
@ -1431,12 +1436,22 @@ parameters:
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#10 \\$colDefault of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:updateOneColumn\\(\\) expects string, mixed given\\.$#"
count: 2
message: "#^Parameter \\#10 \\$collation of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#2 \\$origColName of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:updateOneColumn\\(\\) expects string, mixed given\\.$#"
message: "#^Parameter \\#2 \\$colDefault of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#2 \\$fieldSelect of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:syncUniqueColumns\\(\\) expects array\\<string\\>, array\\<int, mixed\\> given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#2 \\$origColName of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
@ -1461,38 +1476,78 @@ parameters:
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#3 \\$colName of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:updateOneColumn\\(\\) expects string, mixed given\\.$#"
count: 2
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#3 \\$table of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:syncUniqueColumns\\(\\) expects string\\|null, mixed given\\.$#"
message: "#^Parameter \\#3 \\$colDefault of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#4 \\$colType of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:updateOneColumn\\(\\) expects string, mixed given\\.$#"
count: 2
message: "#^Parameter \\#3 \\$colDefaultSel of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#5 \\$colAttribute of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:updateOneColumn\\(\\) expects string, mixed given\\.$#"
count: 2
message: "#^Parameter \\#4 \\$colDefaultSel of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#6 \\$colLength of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:updateOneColumn\\(\\) expects string, mixed given\\.$#"
count: 2
message: "#^Parameter \\#4 \\$colExtra of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string\\|null, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#8 \\$collation of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:updateOneColumn\\(\\) expects string, mixed given\\.$#"
count: 2
message: "#^Parameter \\#4 \\$containingTable of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:syncUniqueColumns\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#9 \\$colExtra of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:updateOneColumn\\(\\) expects string, mixed given\\.$#"
count: 2
message: "#^Parameter \\#5 \\$colExtra of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string\\|null, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#5 \\$colIsNull of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string\\|null, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#6 \\$colIsNull of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string\\|null, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#6 \\$colLength of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#7 \\$colAttribute of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#7 \\$colLength of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#8 \\$colAttribute of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#8 \\$colType of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#9 \\$colType of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#9 \\$collation of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
@ -5055,6 +5110,11 @@ parameters:
count: 1
path: src/Controllers/Table/Structure/CentralColumnsAddController.php
-
message: "#^Parameter \\#4 \\$containingTable of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:syncUniqueColumns\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Table/Structure/CentralColumnsAddController.php
-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
@ -6035,44 +6095,24 @@ parameters:
count: 1
path: src/CreateAddField.php
-
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
count: 4
path: src/Database/CentralColumns.php
-
message: "#^Cannot access offset 'col_attribute' on mixed\\.$#"
count: 6
count: 5
path: src/Database/CentralColumns.php
-
message: "#^Cannot access offset 'col_default' on mixed\\.$#"
count: 2
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Cannot access offset 'col_extra' on mixed\\.$#"
count: 3
path: src/Database/CentralColumns.php
-
message: "#^Cannot access offset 'col_isNull' on mixed\\.$#"
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Cannot access offset 'col_length' on mixed\\.$#"
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Cannot access offset 'col_name' on mixed\\.$#"
count: 2
path: src/Database/CentralColumns.php
-
message: "#^Cannot access offset 'col_type' on mixed\\.$#"
count: 2
count: 1
path: src/Database/CentralColumns.php
-
@ -6087,16 +6127,16 @@ parameters:
-
message: "#^Cannot cast mixed to string\\.$#"
count: 4
path: src/Database/CentralColumns.php
-
message: "#^Foreach overwrites \\$table with its value variable\\.$#"
count: 2
path: src/Database/CentralColumns.php
-
message: "#^Method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:findExistingColNames\\(\\) should return array but returns mixed\\.$#"
message: "#^Method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:findExistingColNames\\(\\) should return array\\<string\\> but returns array\\.$#"
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:findExistingColumns\\(\\) should return array\\<array\\<string\\|null\\>\\> but returns mixed\\.$#"
count: 1
path: src/Database/CentralColumns.php
@ -6110,11 +6150,6 @@ parameters:
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:getParams\\(\\) should return array\\<string\\>\\|false but returns mixed\\.$#"
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Only booleans are allowed in a negated boolean, PhpMyAdmin\\\\Dbal\\\\ResultInterface\\|false given\\.$#"
count: 3
@ -6126,55 +6161,25 @@ parameters:
path: src/Database/CentralColumns.php
-
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#"
count: 3
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#1 \\$bitDefaultValue of static method PhpMyAdmin\\\\Util\\:\\:convertBitDefaultValue\\(\\) expects string\\|null, mixed given\\.$#"
count: 2
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#1 \\$database of method PhpMyAdmin\\\\DatabaseInterface\\:\\:getColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#1 \\$database of method PhpMyAdmin\\\\DatabaseInterface\\:\\:getColumns\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#1 \\$db of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:findExistingColNames\\(\\) expects string, mixed given\\.$#"
count: 2
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#1 \\$db of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:updateOneColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#1 \\$dbname of method PhpMyAdmin\\\\DatabaseInterface\\:\\:selectDb\\(\\) expects PhpMyAdmin\\\\Identifiers\\\\DatabaseName\\|string, mixed given\\.$#"
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#1 \\$def of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:getInsertQuery\\(\\) expects PhpMyAdmin\\\\ColumnFull, PhpMyAdmin\\\\ColumnFull\\|null given\\.$#"
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#1 \\$identifier of static method PhpMyAdmin\\\\Util\\:\\:backquote\\(\\) expects string\\|Stringable\\|null, mixed given\\.$#"
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#1 \\$row of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:getHtmlForEditTableRow\\(\\) expects array, mixed given\\.$#"
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#1 \\$str of method PhpMyAdmin\\\\DatabaseInterface\\:\\:quoteString\\(\\) expects string, mixed given\\.$#"
count: 1
@ -6182,7 +6187,7 @@ parameters:
-
message: "#^Parameter \\#1 \\$string of function bin2hex expects string, mixed given\\.$#"
count: 2
count: 1
path: src/Database/CentralColumns.php
-
@ -6200,16 +6205,6 @@ parameters:
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#2 \\$cols of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:findExistingColNames\\(\\) expects array\\<string\\>, array\\<int\\<0, max\\>, mixed\\> given\\.$#"
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#2 \\$db of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:getInsertQuery\\(\\) expects string, mixed given\\.$#"
count: 2
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#2 \\$origColName of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:updateOneColumn\\(\\) expects string, mixed given\\.$#"
count: 1
@ -6220,18 +6215,13 @@ parameters:
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#2 \\$table of method PhpMyAdmin\\\\DatabaseInterface\\:\\:getColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#3 \\$colName of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:updateOneColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Database/CentralColumns.php
-
message: "#^Parameter \\#3 \\$column of method PhpMyAdmin\\\\ConfigStorage\\\\Relation\\:\\:checkChildForeignReferences\\(\\) expects string, mixed given\\.$#"
message: "#^Parameter \\#3 \\$column of method PhpMyAdmin\\\\ConfigStorage\\\\Relation\\:\\:checkChildForeignReferences\\(\\) expects string, string\\|null given\\.$#"
count: 1
path: src/Database/CentralColumns.php
@ -15785,11 +15775,6 @@ parameters:
count: 1
path: tests/classes/Database/CentralColumnsTest.php
-
message: "#^Cannot access offset 0 on mixed\\.$#"
count: 1
path: tests/classes/Database/CentralColumnsTest.php
-
message: "#^Parameter \\#1 \\$needle of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\) expects string, mixed given\\.$#"
count: 1

View File

@ -896,37 +896,39 @@
<code>Config::getInstance()</code>
</DeprecatedMethod>
<MixedArgument>
<code>$columnDefault</code>
<code>$columnDefault</code>
<code><![CDATA[$params['col_attribute']]]></code>
<code><![CDATA[$params['col_attribute']]]></code>
<code><![CDATA[$params['col_extra'] ?? '']]></code>
<code><![CDATA[$params['col_extra'] ?? '']]></code>
<code><![CDATA[$params['col_length']]]></code>
<code><![CDATA[$params['col_length']]]></code>
<code><![CDATA[$params['col_name']]]></code>
<code><![CDATA[$params['col_name']]]></code>
<code><![CDATA[$params['col_name']]]></code>
<code><![CDATA[$params['col_type']]]></code>
<code><![CDATA[$params['col_type']]]></code>
<code><![CDATA[$params['collation']]]></code>
<code><![CDATA[$params['collation']]]></code>
<code><![CDATA[$params['db']]]></code>
<code><![CDATA[$params['db']]]></code>
<code><![CDATA[$params['orig_col_name']]]></code>
<code><![CDATA[$params['table-select']]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_attribute')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_attribute')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_default')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_default')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_default_sel')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_default_sel')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_extra')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_extra')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_isNull')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_isNull')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_length')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_length')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_name')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_name')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_type')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_type')]]></code>
<code><![CDATA[$request->getParsedBodyParam('collation')]]></code>
<code><![CDATA[$request->getParsedBodyParam('collation')]]></code>
<code><![CDATA[$request->getParsedBodyParam('cur_table', '')]]></code>
<code><![CDATA[$request->getParsedBodyParam('orig_col_name')]]></code>
<code><![CDATA[$request->getParsedBodyParam('pos', '')]]></code>
<code><![CDATA[$request->getParsedBodyParam('table-select')]]></code>
<code><![CDATA[$request->getParsedBodyParam('total_rows', '')]]></code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code>$variables</code>
<code><![CDATA[[$params['column-select']]]]></code>
<code><![CDATA[[$request->getParsedBodyParam('column-select')]]]></code>
</MixedArgumentTypeCoercion>
<MixedAssignment>
<code><![CDATA[$GLOBALS['message']]]></code>
<code>$columnDefault</code>
<code>$columnDefault</code>
</MixedAssignment>
<PossiblyUnusedMethod>
<code>__construct</code>
@ -3709,6 +3711,9 @@
</UnusedParam>
</file>
<file src="src/Controllers/Table/Structure/CentralColumnsAddController.php">
<MixedArgument>
<code><![CDATA[$request->getParsedBodyParam('table')]]></code>
</MixedArgument>
<PossiblyUnusedMethod>
<code>__construct</code>
</PossiblyUnusedMethod>
@ -4397,11 +4402,7 @@
<MixedArgument>
<code>$columnDefault[$i]</code>
<code>$columnExtra[$i]</code>
<code><![CDATA[$column['col_name']]]></code>
<code><![CDATA[$column['col_name']]]></code>
<code><![CDATA[$extractedColumnSpec['attribute']]]></code>
<code><![CDATA[$meta['DefaultValue']]]></code>
<code><![CDATA[$meta['DefaultValue']]]></code>
<code><![CDATA[$params['db']]]></code>
<code><![CDATA[$params['field_attribute'][$i]]]></code>
<code><![CDATA[$params['field_collation'][$i]]]></code>
@ -4410,30 +4411,15 @@
<code><![CDATA[$params['field_type'][$i]]]></code>
<code><![CDATA[$params['orig_col_name']]]></code>
<code><![CDATA[$params['orig_col_name'][$i]]]></code>
<code>$row</code>
<code><![CDATA[$row['col_extra']]]></code>
<code><![CDATA[$rowsMeta[$rowNum]['DefaultValue']]]></code>
<code><![CDATA[$rowsMeta[$rowNum]['DefaultValue']]]></code>
<code>$type</code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code>$cols</code>
</MixedArgumentTypeCoercion>
<MixedArrayAccess>
<code>$columnDefault[$i]</code>
<code>$columnDefault[$i]</code>
<code>$columnDefault[$i]</code>
<code><![CDATA[$column['col_attribute']]]></code>
<code><![CDATA[$column['col_default']]]></code>
<code><![CDATA[$column['col_default']]]></code>
<code><![CDATA[$column['col_default']]]></code>
<code><![CDATA[$column['col_extra']]]></code>
<code><![CDATA[$column['col_isNull']]]></code>
<code><![CDATA[$column['col_length']]]></code>
<code><![CDATA[$column['col_length']]]></code>
<code><![CDATA[$column['col_name']]]></code>
<code><![CDATA[$column['col_name']]]></code>
<code><![CDATA[$column['col_type']]]></code>
<code><![CDATA[$params['field_attribute'][$i]]]></code>
<code><![CDATA[$params['field_collation'][$i]]]></code>
<code><![CDATA[$params['field_default_value'][$i]]]></code>
@ -4455,59 +4441,39 @@
<code><![CDATA[$row['col_extra']]]></code>
</MixedArrayAssignment>
<MixedAssignment>
<code>$cols[]</code>
<code>$column</code>
<code>$columnDefault</code>
<code>$columnDefault[$i]</code>
<code>$columnExtra[$i]</code>
<code>$defaultValue</code>
<code>$defaultValues[$rowNum]</code>
<code>$field</code>
<code>$length</code>
<code><![CDATA[$meta['DefaultValue']]]></code>
<code>$row</code>
<code>$row</code>
<code>$row</code>
<code><![CDATA[$rowsMeta[$rowNum]['DefaultType']]]></code>
<code><![CDATA[$rowsMeta[$rowNum]['DefaultValue']]]></code>
<code>$type</code>
</MixedAssignment>
<MixedInferredReturnType>
<code>string[]|false</code>
</MixedInferredReturnType>
<MixedOperand>
<code><![CDATA[$column['col_attribute']]]></code>
<code><![CDATA[$column['col_default']]]></code>
<code><![CDATA[$column['col_extra']]]></code>
<code><![CDATA[$column['col_length']]]></code>
<code><![CDATA[$column['col_type']]]></code>
</MixedOperand>
<MixedReturnStatement>
<code>$cfgCentralColumns</code>
</MixedReturnStatement>
<MixedReturnTypeCoercion>
<code>$hasList</code>
<code><![CDATA[$this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser)]]></code>
<code>(string|null)[][]</code>
<code>string[]</code>
</MixedReturnTypeCoercion>
<PossiblyInvalidArgument>
<code>$db</code>
<code>$db</code>
<code>$db</code>
<code>$db</code>
<code>$db</code>
<code>$db</code>
<code>$db</code>
<code>$table</code>
<code>$tnPageNow</code>
</PossiblyInvalidArgument>
<PossiblyInvalidCast>
<code>$db</code>
<code>$db</code>
<code>$db</code>
<code>$db</code>
<code>$db</code>
<code>$db</code>
<code>$table</code>
</PossiblyInvalidCast>
<PossiblyNullArgument>
<code><![CDATA[$column['col_name']]]></code>
<code>$field</code>
</PossiblyNullArgument>
<PossiblyNullOperand>
<code><![CDATA[$column['col_attribute']]]></code>
<code><![CDATA[$column['col_extra']]]></code>
<code><![CDATA[$column['col_type']]]></code>
</PossiblyNullOperand>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$column['col_default']]]></code>
<code><![CDATA[$column['col_isNull']]]></code>
<code><![CDATA[$column['col_length']]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Database/Designer.php">
<DeprecatedMethod>
@ -13294,15 +13260,9 @@
$this->centralColumns,
CentralColumns::class,
'getHtmlForEditTableRow',
[$listDetailCols[0], 0],
[$this->modifiedColumnData[0], 0],
)]]></code>
</MixedArgument>
<MixedArrayAccess>
<code>$listDetailCols[0]</code>
</MixedArrayAccess>
<MixedAssignment>
<code>$listDetailCols</code>
</MixedAssignment>
<RedundantCondition>
<code>assertIsArray</code>
</RedundantCondition>

View File

@ -40,34 +40,36 @@ class CentralColumnsController extends AbstractController
$db = DatabaseName::from($request->getParam('db'));
if ($request->hasBodyParam('edit_save')) {
$this->response->addHTML((string) $this->editSave([
'col_name' => $request->getParsedBodyParam('col_name'),
'orig_col_name' => $request->getParsedBodyParam('orig_col_name'),
'col_default' => $request->getParsedBodyParam('col_default'),
'col_default_sel' => $request->getParsedBodyParam('col_default_sel'),
'col_extra' => $request->getParsedBodyParam('col_extra'),
'col_isNull' => $request->getParsedBodyParam('col_isNull'),
'col_length' => $request->getParsedBodyParam('col_length'),
'col_attribute' => $request->getParsedBodyParam('col_attribute'),
'col_type' => $request->getParsedBodyParam('col_type'),
'collation' => $request->getParsedBodyParam('collation'),
], $db));
$this->response->addHTML((string) $this->editSave(
$request->getParsedBodyParam('col_name'),
$request->getParsedBodyParam('orig_col_name'),
$request->getParsedBodyParam('col_default'),
$request->getParsedBodyParam('col_default_sel'),
$request->getParsedBodyParam('col_extra'),
$request->getParsedBodyParam('col_isNull'),
$request->getParsedBodyParam('col_length'),
$request->getParsedBodyParam('col_attribute'),
$request->getParsedBodyParam('col_type'),
$request->getParsedBodyParam('collation'),
$db,
));
return;
}
if ($request->hasBodyParam('add_new_column')) {
$tmpMsg = $this->addNewColumn([
'col_name' => $request->getParsedBodyParam('col_name'),
'col_default' => $request->getParsedBodyParam('col_default'),
'col_default_sel' => $request->getParsedBodyParam('col_default_sel'),
'col_extra' => $request->getParsedBodyParam('col_extra'),
'col_isNull' => $request->getParsedBodyParam('col_isNull'),
'col_length' => $request->getParsedBodyParam('col_length'),
'col_attribute' => $request->getParsedBodyParam('col_attribute'),
'col_type' => $request->getParsedBodyParam('col_type'),
'collation' => $request->getParsedBodyParam('collation'),
], $db);
$tmpMsg = $this->addNewColumn(
$request->getParsedBodyParam('col_name'),
$request->getParsedBodyParam('col_default'),
$request->getParsedBodyParam('col_default_sel'),
$request->getParsedBodyParam('col_extra'),
$request->getParsedBodyParam('col_isNull'),
$request->getParsedBodyParam('col_length'),
$request->getParsedBodyParam('col_attribute'),
$request->getParsedBodyParam('col_type'),
$request->getParsedBodyParam('collation'),
$db,
);
}
if ($request->hasBodyParam('getColumnList')) {
@ -80,10 +82,12 @@ class CentralColumnsController extends AbstractController
}
if ($request->hasBodyParam('add_column')) {
$tmpMsg = $this->addColumn([
'table-select' => $request->getParsedBodyParam('table-select'),
'column-select' => $request->getParsedBodyParam('column-select'),
]);
$tmpMsg = $this->centralColumns->syncUniqueColumns(
DatabaseName::from($request->getParsedBodyParam('db')),
[$request->getParsedBodyParam('column-select')],
false,
$request->getParsedBodyParam('table-select'),
);
}
$this->addScriptFiles([
@ -102,7 +106,7 @@ class CentralColumnsController extends AbstractController
}
if ($request->hasBodyParam('multi_edit_central_column_save')) {
$GLOBALS['message'] = $this->updateMultipleColumn([
$GLOBALS['message'] = $this->centralColumns->updateMultipleColumn([
'db' => $request->getParsedBodyParam('db'),
'orig_col_name' => $request->getParsedBodyParam('orig_col_name'),
'field_name' => $request->getParsedBodyParam('field_name'),
@ -177,72 +181,71 @@ class CentralColumnsController extends AbstractController
$this->render('database/central_columns/main', $variables);
}
/**
* @param mixed[] $params Request parameters
*
* @return true|Message
*/
public function editSave(array $params, DatabaseName $db): bool|Message
{
$columnDefault = $params['col_default'];
if ($columnDefault === 'NONE' && $params['col_default_sel'] !== 'USER_DEFINED') {
/** @return true|Message */
public function editSave(
string $colName,
string $origColName,
string $colDefault,
string $colDefaultSel,
string|null $colExtra,
string|null $colIsNull,
string $colLength,
string $colAttribute,
string $colType,
string $collation,
DatabaseName $db,
): bool|Message {
$columnDefault = $colDefault;
if ($columnDefault === 'NONE' && $colDefaultSel !== 'USER_DEFINED') {
$columnDefault = '';
}
return $this->centralColumns->updateOneColumn(
$db->getName(),
$params['orig_col_name'],
$params['col_name'],
$params['col_type'],
$params['col_attribute'],
$params['col_length'],
isset($params['col_isNull']),
$params['collation'],
$params['col_extra'] ?? '',
$origColName,
$colName,
$colType,
$colAttribute,
$colLength,
$colIsNull !== null,
$collation,
$colExtra ?? '',
$columnDefault,
);
}
/**
* @param mixed[] $params Request parameters
*
* @return true|Message
*/
public function addNewColumn(array $params, DatabaseName $db): bool|Message
{
$columnDefault = $params['col_default'];
if ($columnDefault === 'NONE' && $params['col_default_sel'] !== 'USER_DEFINED') {
/** @return true|Message */
public function addNewColumn(
string $colName,
string $colDefault,
string $colDefaultSel,
string|null $colExtra,
string|null $colIsNull,
string $colLength,
string $colAttribute,
string $colType,
string $collation,
DatabaseName $db,
): bool|Message {
$columnDefault = $colDefault;
if ($columnDefault === 'NONE' && $colDefaultSel !== 'USER_DEFINED') {
$columnDefault = '';
}
return $this->centralColumns->updateOneColumn(
$db->getName(),
'',
$params['col_name'],
$params['col_type'],
$params['col_attribute'],
$params['col_length'],
isset($params['col_isNull']),
$params['collation'],
$params['col_extra'] ?? '',
$colName,
$colType,
$colAttribute,
$colLength,
$colIsNull !== null,
$collation,
$colExtra ?? '',
$columnDefault,
);
}
/**
* @param mixed[] $params Request parameters
*
* @return true|Message
*/
public function addColumn(array $params): bool|Message
{
return $this->centralColumns->syncUniqueColumns(
[$params['column-select']],
false,
$params['table-select'],
);
}
/** @param mixed[] $params Request parameters */
public function editPage(array $params): void
{
@ -253,16 +256,6 @@ class CentralColumnsController extends AbstractController
$this->render('database/central_columns/edit', ['rows' => $rows]);
}
/**
* @param mixed[] $params Request parameters
*
* @return true|Message
*/
public function updateMultipleColumn(array $params): bool|Message
{
return $this->centralColumns->updateMultipleColumn($params);
}
/**
* @param mixed[] $params Request parameters
*

View File

@ -9,6 +9,7 @@ use PhpMyAdmin\Controllers\Database\StructureController;
use PhpMyAdmin\Database\CentralColumns;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
@ -44,7 +45,7 @@ final class AddController extends AbstractController
Assert::allString($selected);
$centralColumns = new CentralColumns($this->dbi);
$error = $centralColumns->syncUniqueColumns($selected);
$error = $centralColumns->syncUniqueColumns(DatabaseName::from($request->getParsedBodyParam('db')), $selected);
$GLOBALS['message'] = $error instanceof Message ? $error : Message::success(__('Success!'));

View File

@ -8,6 +8,7 @@ use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\Controllers\Table\StructureController;
use PhpMyAdmin\Database\CentralColumns;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
@ -42,7 +43,12 @@ final class CentralColumnsAddController extends AbstractController
Assert::allString($selected);
$centralColsError = $this->centralColumns->syncUniqueColumns($selected, false);
$centralColsError = $this->centralColumns->syncUniqueColumns(
DatabaseName::from($request->getParsedBodyParam('db')),
$selected,
false,
$request->getParsedBodyParam('table'),
);
if ($centralColsError instanceof Message) {
$GLOBALS['message'] = $centralColsError;

View File

@ -176,7 +176,10 @@ class StructureController extends AbstractController
}
$centralColumns = new CentralColumns($this->dbi);
$centralList = $centralColumns->getFromTable(Current::$database, Current::$table);
$centralList = $centralColumns->findExistingColNames(
Current::$database,
$this->dbi->getColumnNames(Current::$database, Current::$table),
);
/**
* Displays Space usage and row statistics

View File

@ -10,6 +10,7 @@ use PhpMyAdmin\Config;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Message;
use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
@ -18,6 +19,7 @@ use function __;
use function array_column;
use function array_diff;
use function array_map;
use function array_merge;
use function array_unique;
use function array_values;
use function bin2hex;
@ -72,32 +74,22 @@ class CentralColumns
}
/**
* Defines the central_columns parameters for the current user
* Returns the configuration storage settings for central columns or false if no storage is available
*
* @return string[]|false the central_columns parameters for the current user
* @return array{user:string, db: string, table:string}|false
*/
public function getParams(): array|bool
public function getParams(): array|false
{
static $cfgCentralColumns = null;
if ($cfgCentralColumns !== null) {
return $cfgCentralColumns;
}
$centralColumnsFeature = $this->relation->getRelationParameters()->centralColumnsFeature;
if ($centralColumnsFeature === null) {
$cfgCentralColumns = false;
return false;
}
$cfgCentralColumns = [
return [
'user' => $this->user,
'db' => $centralColumnsFeature->database->getName(),
'table' => $centralColumnsFeature->centralColumns->getName(),
];
return $cfgCentralColumns;
}
/**
@ -119,14 +111,13 @@ class CentralColumns
}
$pmadb = $cfgCentralColumns['db'];
$this->dbi->selectDb($pmadb, ConnectionType::ControlUser);
$centralListTable = $cfgCentralColumns['table'];
//get current values of $db from central column list
if ($num == 0) {
$query = 'SELECT * FROM ' . Util::backquote($centralListTable) . ' '
if ($num === 0) {
$query = 'SELECT * FROM ' . Util::backquote($pmadb) . '.' . Util::backquote($centralListTable) . ' '
. 'WHERE db_name = ' . $this->dbi->quoteString($db, ConnectionType::ControlUser) . ';';
} else {
$query = 'SELECT * FROM ' . Util::backquote($centralListTable) . ' '
$query = 'SELECT * FROM ' . Util::backquote($pmadb) . '.' . Util::backquote($centralListTable) . ' '
. 'WHERE db_name = ' . $this->dbi->quoteString($db, ConnectionType::ControlUser) . ' '
. 'LIMIT ' . $from . ', ' . $num . ';';
}
@ -152,10 +143,9 @@ class CentralColumns
}
$pmadb = $cfgCentralColumns['db'];
$this->dbi->selectDb($pmadb, ConnectionType::ControlUser);
$centralListTable = $cfgCentralColumns['table'];
$query = 'SELECT count(db_name) FROM '
. Util::backquote($centralListTable) . ' '
. Util::backquote($pmadb) . '.' . Util::backquote($centralListTable) . ' '
. 'WHERE db_name = ' . $this->dbi->quoteString($db, ConnectionType::ControlUser) . ';';
$res = $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser);
if (isset($res[0])) {
@ -168,17 +158,14 @@ class CentralColumns
/**
* return the existing columns in central list among the given list of columns
*
* @param string $db the selected database
* @param string[] $cols list of given columns
* @param bool $allFields set if need all the fields of existing columns,
* otherwise only column_name is returned
* @param string $db the selected database
* @param string[] $cols list of given columns
*
* @return mixed[] list of columns in central columns among given set of columns
* @return string[] list of columns in central columns among given set of columns
*/
private function findExistingColNames(
public function findExistingColNames(
string $db,
array $cols,
bool $allFields = false,
): array {
$cfgCentralColumns = $this->getParams();
if (! is_array($cfgCentralColumns)) {
@ -188,20 +175,41 @@ class CentralColumns
$cols = $this->getWhereInColumns($cols);
$pmadb = $cfgCentralColumns['db'];
$this->dbi->selectDb($pmadb, ConnectionType::ControlUser);
$centralListTable = $cfgCentralColumns['table'];
if ($allFields) {
$query = 'SELECT * FROM ' . Util::backquote($centralListTable) . ' WHERE db_name = '
. $this->dbi->quoteString($db, ConnectionType::ControlUser) . ' AND col_name IN (' . $cols . ');';
$hasList = $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser);
$this->handleColumnExtra($hasList);
} else {
$query = 'SELECT col_name FROM '
. Util::backquote($centralListTable) . ' WHERE db_name = '
. $this->dbi->quoteString($db, ConnectionType::ControlUser) . ' AND col_name IN (' . $cols . ');';
$hasList = $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser);
$query = 'SELECT col_name FROM '
. Util::backquote($pmadb) . '.' . Util::backquote($centralListTable) . ' WHERE db_name = '
. $this->dbi->quoteString($db, ConnectionType::ControlUser) . ' AND col_name IN (' . $cols . ');';
return $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser);
}
/**
* return the existing columns in central list among the given list of columns
*
* @param string $db the selected database
* @param string[] $cols list of given columns
*
* @return (string|null)[][] list of columns in central columns among given set of columns
*/
private function findExistingColumns(
string $db,
array $cols,
): array {
$cfgCentralColumns = $this->getParams();
if (! is_array($cfgCentralColumns)) {
return [];
}
$cols = $this->getWhereInColumns($cols);
$pmadb = $cfgCentralColumns['db'];
$centralListTable = $cfgCentralColumns['table'];
$query = 'SELECT * FROM '
. Util::backquote($pmadb) . '.' . Util::backquote($centralListTable) . ' WHERE db_name = '
. $this->dbi->quoteString($db, ConnectionType::ControlUser) . ' AND col_name IN (' . $cols . ');';
$hasList = $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser);
$this->handleColumnExtra($hasList);
return $hasList;
}
@ -219,6 +227,7 @@ class CentralColumns
private function getInsertQuery(
ColumnFull $def,
string $db,
string $centralListDb,
string $centralListTable,
): string {
$extractedColumnSpec = Util::extractColumnSpec($def->type);
@ -232,7 +241,7 @@ class CentralColumns
$default = $def->default ?? '';
return 'INSERT INTO '
. Util::backquote($centralListTable) . ' '
. Util::backquote($centralListDb) . '.' . Util::backquote($centralListTable) . ' '
. 'VALUES ( ' . $this->dbi->quoteString($db, ConnectionType::ControlUser) . ' ,'
. $this->dbi->quoteString($def->field, ConnectionType::ControlUser) . ','
. $this->dbi->quoteString($type, ConnectionType::ControlUser) . ','
@ -248,70 +257,69 @@ class CentralColumns
* are added to central list otherwise the $field_select is considered as
* list of columns and these columns are added to central list if not already added
*
* @param string[] $fieldSelect if $isTable is true selected tables list otherwise selected columns list
* @param bool $isTable if passed array is of tables or columns
* @param string|null $table if $isTable is false, then table name to which columns belong
* @param string[] $fieldSelect if $isTable is true selected tables list otherwise selected columns list
* @param bool $isTable if passed array is of tables or columns
* @param string $containingTable if $isTable is false, then table name to which columns belong
*
* @return true|Message
*/
public function syncUniqueColumns(
DatabaseName $databaseName,
array $fieldSelect,
bool $isTable = true,
string|null $table = null,
string $containingTable = '',
): bool|Message {
$cfgCentralColumns = $this->getParams();
if (! is_array($cfgCentralColumns)) {
return Message::error(
__('The configuration storage is not ready for the central list of columns feature.'),
);
return $this->getStorageNotReadyMessage();
}
$db = $_POST['db'];
$pmadb = $cfgCentralColumns['db'];
$centralListTable = $cfgCentralColumns['table'];
$this->dbi->selectDb($db);
$existingCols = [];
$cols = [];
$insQuery = [];
$fields = [];
$message = true;
if ($isTable) {
$cols = [];
$fields = [];
foreach ($fieldSelect as $table) {
$fields[$table] = $this->dbi->getColumns($db, $table, true);
foreach (array_column($fields[$table], 'Field') as $field) {
$cols[] = $field;
}
$fields[$table] = $this->dbi->getColumns($databaseName->getName(), $table, true);
$cols = array_merge($cols, array_column($fields[$table], 'field'));
}
$hasList = $this->findExistingColNames($db, $cols);
$hasList = $this->findExistingColNames($databaseName->getName(), $cols);
foreach ($fieldSelect as $table) {
foreach ($fields[$table] as $def) {
$field = $def->field;
if (! in_array($field, $hasList)) {
if (! in_array($field, $hasList, true)) {
$hasList[] = $field;
$insQuery[] = $this->getInsertQuery($def, $db, $centralListTable);
$insQuery[] = $this->getInsertQuery(
$def,
$databaseName->getName(),
$cfgCentralColumns['db'],
$cfgCentralColumns['table'],
);
} else {
$existingCols[] = "'" . $field . "'";
}
}
}
} else {
if ($table === null) {
$table = $_POST['table'];
}
$hasList = $this->findExistingColNames($db, $fieldSelect);
$hasList = $this->findExistingColNames($databaseName->getName(), $fieldSelect);
foreach ($fieldSelect as $column) {
if (! in_array($column, $hasList)) {
if (! in_array($column, $hasList, true)) {
$hasList[] = $column;
$field = $this->dbi->getColumn($db, $table, $column, true);
$insQuery[] = $this->getInsertQuery($field, $db, $centralListTable);
$field = $this->dbi->getColumn($databaseName->getName(), $containingTable, $column, true);
$insQuery[] = $this->getInsertQuery(
$field,
$databaseName->getName(),
$cfgCentralColumns['db'],
$cfgCentralColumns['table'],
);
} else {
$existingCols[] = "'" . $column . "'";
}
}
}
$message = true;
if ($existingCols !== []) {
$existingCols = implode(',', array_unique($existingCols));
$message = Message::notice(
@ -329,14 +337,14 @@ class CentralColumns
);
}
$this->dbi->selectDb($pmadb, ConnectionType::ControlUser);
foreach ($insQuery as $query) {
if (! $this->dbi->tryQuery($query, ConnectionType::ControlUser)) {
$message = Message::error(__('Could not add columns!'));
$message->addMessage(
Message::rawError($this->dbi->getError(ConnectionType::ControlUser)),
);
break;
return $message;
}
}
@ -362,30 +370,24 @@ class CentralColumns
): bool|Message {
$cfgCentralColumns = $this->getParams();
if (! is_array($cfgCentralColumns)) {
return Message::error(
__('The configuration storage is not ready for the central list of columns feature.'),
);
return $this->getStorageNotReadyMessage();
}
$pmadb = $cfgCentralColumns['db'];
$centralListTable = $cfgCentralColumns['table'];
$this->dbi->selectDb($database);
$message = true;
$colNotExist = [];
$fields = [];
if ($isTable) {
$fields = [];
$cols = [];
foreach ($fieldSelect as $table) {
$fields[$table] = $this->dbi->getColumnNames($database, $table);
foreach ($fields[$table] as $colSelect) {
$cols[] = $colSelect;
}
$cols = array_merge($cols, $fields[$table]);
}
$hasList = $this->findExistingColNames($database, $cols);
foreach ($fieldSelect as $table) {
foreach ($fields[$table] as $column) {
if (in_array($column, $hasList)) {
if (in_array($column, $hasList, true)) {
continue;
}
@ -396,7 +398,7 @@ class CentralColumns
$cols = $fieldSelect;
$hasList = $this->findExistingColNames($database, $cols);
foreach ($fieldSelect as $column) {
if (in_array($column, $hasList)) {
if (in_array($column, $hasList, true)) {
continue;
}
@ -404,6 +406,7 @@ class CentralColumns
}
}
$message = true;
if ($colNotExist !== []) {
$colNotExist = implode(',', array_unique($colNotExist));
$message = Message::notice(
@ -416,10 +419,9 @@ class CentralColumns
);
}
$this->dbi->selectDb($pmadb, ConnectionType::ControlUser);
$cols = $this->getWhereInColumns($cols);
$query = 'DELETE FROM ' . Util::backquote($centralListTable) . ' WHERE db_name = '
$query = 'DELETE FROM '
. Util::backquote($pmadb) . '.' . Util::backquote($centralListTable) . ' WHERE db_name = '
. $this->dbi->quoteString($database, ConnectionType::ControlUser) . ' AND col_name IN (' . $cols . ');';
if (! $this->dbi->tryQuery($query, ConnectionType::ControlUser)) {
@ -447,10 +449,10 @@ class CentralColumns
array $selectedTables,
): bool|Message {
$message = true;
$this->dbi->selectDb($db);
foreach ($selectedTables as $table) {
$query = 'ALTER TABLE ' . Util::backquote($table);
$hasList = $this->getFromTable($db, $table, true);
$this->dbi->selectDb($db);
$hasList = $this->findExistingColumns($db, $this->dbi->getColumnNames($db, $table));
foreach ($hasList as $column) {
$columnStatus = $this->relation->checkChildForeignReferences($db, $table, $column['col_name']);
//column definition can only be changed if
@ -459,8 +461,7 @@ class CentralColumns
continue;
}
$query .= ' MODIFY ' . Util::backquote($column['col_name']) . ' '
. $column['col_type'];
$query .= ' MODIFY ' . Util::backquote($column['col_name']) . ' ' . $column['col_type'];
if ($column['col_length']) {
$query .= '(' . $column['col_length'] . ')';
}
@ -479,7 +480,7 @@ class CentralColumns
&& $column['col_default'] !== 'current_timestamp()'
) {
$query .= ' DEFAULT ' . $this->dbi->quoteString(
(string) $column['col_default'],
$column['col_default'],
ConnectionType::ControlUser,
);
} else {
@ -505,33 +506,6 @@ class CentralColumns
return $message;
}
/**
* return the columns present in central list of columns for a given
* table of a given database
*
* @param string $db given database
* @param string $table given table
* @param bool $allFields set if need all the fields of existing columns,
* otherwise only column_name is returned
*
* @return mixed[] columns present in central list from given table of given db.
*/
public function getFromTable(
string $db,
string $table,
bool $allFields = false,
): array {
$cfgCentralColumns = $this->getParams();
if ($cfgCentralColumns === false || $cfgCentralColumns === []) {
return [];
}
$this->dbi->selectDb($db);
$fields = $this->dbi->getColumnNames($db, $table);
return $this->findExistingColNames($db, $fields, $allFields);
}
/**
* update a column in central columns list if a edit is requested
*
@ -562,14 +536,12 @@ class CentralColumns
): bool|Message {
$cfgCentralColumns = $this->getParams();
if (! is_array($cfgCentralColumns)) {
return Message::error(
__('The configuration storage is not ready for the central list of columns feature.'),
);
return $this->getStorageNotReadyMessage();
}
$centralListDb = $cfgCentralColumns['db'];
$centralTable = $cfgCentralColumns['table'];
$this->dbi->selectDb($cfgCentralColumns['db'], ConnectionType::ControlUser);
if ($origColName == '') {
if ($origColName === '') {
$def = new ColumnFull(
$colName,
$colType . ($colLength !== '' ? '(' . $colLength . ')' : ''),
@ -581,9 +553,9 @@ class CentralColumns
'',
'',
);
$query = $this->getInsertQuery($def, $db, $centralTable);
$query = $this->getInsertQuery($def, $db, $centralListDb, $centralTable);
} else {
$query = 'UPDATE ' . Util::backquote($centralTable)
$query = 'UPDATE ' . Util::backquote($centralListDb) . '.' . Util::backquote($centralTable)
. ' SET col_type = ' . $this->dbi->quoteString($colType, ConnectionType::ControlUser)
. ', col_name = ' . $this->dbi->quoteString($colName, ConnectionType::ControlUser)
. ', col_length = ' . $this->dbi->quoteString($colLength, ConnectionType::ControlUser)
@ -649,9 +621,8 @@ class CentralColumns
/**
* build html for editing a row in central columns table
*
* @param mixed[] $row array contains complete information of a
* particular row of central list table
* @param int $rowNum position the row in the table
* @param (string|null)[] $row array contains complete information of a particular row of central list table
* @param int $rowNum position the row in the table
*
* @return string html of a particular row in the central columns table.
*/
@ -678,7 +649,7 @@ class CentralColumns
if ($typeUpper === 'BIT') {
$defaultValue = Util::convertBitDefaultValue($meta['DefaultValue']);
} elseif ($typeUpper == 'BINARY' || $typeUpper == 'VARBINARY') {
} elseif ($typeUpper === 'BINARY' || $typeUpper === 'VARBINARY') {
$defaultValue = bin2hex($meta['DefaultValue']);
}
}
@ -706,8 +677,7 @@ class CentralColumns
* @param string $db selected database
* @param string $table current table name
*
* @return mixed[] encoded list of columns present in central list for the given
* database
* @return mixed[] encoded list of columns present in central list for the given database
*/
public function getListRaw(string $db, string $table): array
{
@ -716,14 +686,14 @@ class CentralColumns
return [];
}
$pmadb = $cfgCentralColumns['db'];
$centralTable = $cfgCentralColumns['table'];
if ($table === '') {
$query = 'SELECT * FROM ' . Util::backquote($centralTable) . ' '
$query = 'SELECT * FROM ' . Util::backquote($pmadb) . '.' . Util::backquote($centralTable) . ' '
. 'WHERE db_name = ' . $this->dbi->quoteString($db, ConnectionType::ControlUser) . ';';
} else {
$this->dbi->selectDb($db);
$columns = $this->dbi->getColumnNames($db, $table);
$query = 'SELECT * FROM ' . Util::backquote($centralTable) . ' '
$query = 'SELECT * FROM ' . Util::backquote($pmadb) . '.' . Util::backquote($centralTable) . ' '
. 'WHERE db_name = ' . $this->dbi->quoteString($db, ConnectionType::ControlUser);
if ($columns !== []) {
$query .= ' AND col_name NOT IN (' . $this->getWhereInColumns($columns) . ')';
@ -732,7 +702,6 @@ class CentralColumns
$query .= ';';
}
$this->dbi->selectDb($cfgCentralColumns['db'], ConnectionType::ControlUser);
$columnsList = $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser);
$this->handleColumnExtra($columnsList);
@ -777,7 +746,7 @@ class CentralColumns
public function getHtmlForEditingPage(array $selectedFld, string $selectedDb): string
{
$html = '';
$listDetailCols = $this->findExistingColNames($selectedDb, $selectedFld, true);
$listDetailCols = $this->findExistingColumns($selectedDb, $selectedFld);
$rowNum = 0;
foreach ($listDetailCols as $row) {
$tableHtmlRow = $this->getHtmlForEditTableRow($row, $rowNum);
@ -807,11 +776,10 @@ class CentralColumns
}
$pmadb = $cfgCentralColumns['db'];
$this->dbi->selectDb($pmadb, ConnectionType::ControlUser);
$centralListTable = $cfgCentralColumns['table'];
//get current values of $db from central column list
$query = 'SELECT COUNT(db_name) FROM ' . Util::backquote($centralListTable) . ' '
. 'WHERE db_name = ' . $this->dbi->quoteString($db, ConnectionType::ControlUser)
$query = 'SELECT COUNT(db_name) FROM ' . Util::backquote($pmadb) . '.' . Util::backquote($centralListTable)
. ' WHERE db_name = ' . $this->dbi->quoteString($db, ConnectionType::ControlUser)
. ($num === 0 ? '' : 'LIMIT ' . $from . ', ' . $num) . ';';
$result = $this->dbi->fetchResult($query, null, null, ConnectionType::ControlUser);
@ -825,8 +793,7 @@ class CentralColumns
/** @return string[] */
public function getColumnsNotInCentralList(string $db, string $table): array
{
$existingColumns = $this->getFromTable($db, $table);
$this->dbi->selectDb($db);
$existingColumns = $this->findExistingColNames($db, $this->dbi->getColumnNames($db, $table));
$columnNames = $this->dbi->getColumnNames($db, $table);
// returns a list of column names less the ones from $existingColumns
@ -860,7 +827,6 @@ class CentralColumns
$tnPageNow,
$tnNbTotalPage,
) : '';
$this->dbi->selectDb($db);
$tables = $this->dbi->getTables($db);
$rowsList = $this->getColumnsList($db, $pos, $maxRows);
@ -874,7 +840,7 @@ class CentralColumns
$rowsMeta[$rowNum]['DefaultType'] = 'NONE';
} elseif ($row['col_default'] === 'CURRENT_TIMESTAMP' || $row['col_default'] === 'current_timestamp()') {
$rowsMeta[$rowNum]['DefaultType'] = 'CURRENT_TIMESTAMP';
} elseif ($row['col_default'] == 'NULL') {
} elseif ($row['col_default'] === 'NULL') {
$rowsMeta[$rowNum]['DefaultType'] = $row['col_default'];
} else {
$rowsMeta[$rowNum]['DefaultType'] = 'USER_DEFINED';
@ -941,4 +907,11 @@ class CentralColumns
$columns,
));
}
private function getStorageNotReadyMessage(): Message
{
return Message::error(
__('The configuration storage is not ready for the central list of columns feature.'),
);
}
}

View File

@ -12,6 +12,7 @@ use PhpMyAdmin\Current;
use PhpMyAdmin\Database\CentralColumns;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\DummyResult;
use PhpMyAdmin\Types;
@ -37,26 +38,26 @@ class CentralColumnsTest extends AbstractTestCase
[
'col_name' => 'id',
'col_type' => 'integer',
'col_length' => 0,
'col_isNull' => 0,
'col_length' => '0',
'col_isNull' => '0',
'col_extra' => 'UNSIGNED,auto_increment',
'col_default' => 1,
'col_default' => '1',
'col_collation' => '',
],
[
'col_name' => 'col1',
'col_type' => 'varchar',
'col_length' => 100,
'col_isNull' => 1,
'col_length' => '100',
'col_isNull' => '1',
'col_extra' => 'BINARY',
'col_default' => 1,
'col_default' => '1',
'col_collation' => '',
],
[
'col_name' => 'col2',
'col_type' => 'DATETIME',
'col_length' => 0,
'col_isNull' => 1,
'col_length' => '0',
'col_isNull' => '1',
'col_extra' => 'on update CURRENT_TIMESTAMP',
'col_default' => 'CURRENT_TIMESTAMP',
'col_collation' => '',
@ -68,28 +69,28 @@ class CentralColumnsTest extends AbstractTestCase
[
'col_name' => 'id',
'col_type' => 'integer',
'col_length' => 0,
'col_isNull' => 0,
'col_length' => '0',
'col_isNull' => '0',
'col_extra' => 'auto_increment',
'col_default' => 1,
'col_default' => '1',
'col_collation' => '',
'col_attribute' => 'UNSIGNED',
],
[
'col_name' => 'col1',
'col_type' => 'varchar',
'col_length' => 100,
'col_isNull' => 1,
'col_length' => '100',
'col_isNull' => '1',
'col_extra' => '',
'col_default' => 1,
'col_default' => '1',
'col_collation' => '',
'col_attribute' => 'BINARY',
],
[
'col_name' => 'col2',
'col_type' => 'DATETIME',
'col_length' => 0,
'col_isNull' => 1,
'col_length' => '0',
'col_isNull' => '1',
'col_extra' => '',
'col_default' => 'CURRENT_TIMESTAMP',
'col_collation' => '',
@ -200,7 +201,7 @@ class CentralColumnsTest extends AbstractTestCase
$this->dbi->expects(self::once())
->method('fetchResult')
->with(
'SELECT count(db_name) FROM `pma_central_columns` WHERE db_name = \'phpmyadmin\';',
'SELECT count(db_name) FROM `phpmyadmin`.`pma_central_columns` WHERE db_name = \'phpmyadmin\';',
null,
null,
ConnectionType::ControlUser,
@ -218,11 +219,9 @@ class CentralColumnsTest extends AbstractTestCase
*/
public function testSyncUniqueColumns(): void
{
$_POST['db'] = 'PMA_db';
$_POST['table'] = 'PMA_table';
self::assertTrue(
$this->centralColumns->syncUniqueColumns(
DatabaseName::from('PMA_db'),
['PMA_table'],
),
);
@ -247,61 +246,6 @@ class CentralColumnsTest extends AbstractTestCase
);
}
/**
* Test for getFromTable
*/
public function testGetFromTable(): void
{
$db = 'PMA_db';
$table = 'PMA_table';
$this->dbi->expects(self::once())
->method('fetchResult')
->with(
'SELECT col_name FROM `pma_central_columns` '
. "WHERE db_name = 'PMA_db' AND col_name IN ('id','col1','col2');",
null,
null,
ConnectionType::ControlUser,
)
->willReturn(['id', 'col1']);
self::assertSame(
['id', 'col1'],
$this->centralColumns->getFromTable(
$db,
$table,
),
);
}
/**
* Test for getFromTable with $allFields = true
*/
public function testGetFromTableWithAllFields(): void
{
$db = 'PMA_db';
$table = 'PMA_table';
$this->dbi->expects(self::once())
->method('fetchResult')
->with(
'SELECT * FROM `pma_central_columns` '
. "WHERE db_name = 'PMA_db' AND col_name IN ('id','col1','col2');",
null,
null,
ConnectionType::ControlUser,
)
->willReturn(array_slice($this->columnData, 0, 2));
self::assertSame(
array_slice($this->modifiedColumnData, 0, 2),
$this->centralColumns->getFromTable(
$db,
$table,
true,
),
);
}
/**
* Test for updateOneColumn
*/
@ -365,7 +309,7 @@ class CentralColumnsTest extends AbstractTestCase
$this->dbi->expects(self::any())
->method('fetchResult')
->with(
'SELECT * FROM `pma_central_columns` '
'SELECT * FROM `phpmyadmin`.`pma_central_columns` '
. "WHERE db_name = 'phpmyadmin' AND col_name IN ('col1','col2');",
null,
null,
@ -376,18 +320,13 @@ class CentralColumnsTest extends AbstractTestCase
['col1', 'col2'],
'phpmyadmin',
);
$listDetailCols = $this->callFunction(
$this->centralColumns,
CentralColumns::class,
'findExistingColNames',
['phpmyadmin', ['col1', 'col2'], true],
);
self::assertStringContainsString(
$this->callFunction(
$this->centralColumns,
CentralColumns::class,
'getHtmlForEditTableRow',
[$listDetailCols[0], 0],
[$this->modifiedColumnData[0], 0],
),
$result,
);
@ -401,7 +340,7 @@ class CentralColumnsTest extends AbstractTestCase
$this->dbi->expects(self::once())
->method('fetchResult')
->with(
'SELECT * FROM `pma_central_columns` WHERE db_name = \'phpmyadmin\';',
'SELECT * FROM `phpmyadmin`.`pma_central_columns` WHERE db_name = \'phpmyadmin\';',
null,
null,
ConnectionType::ControlUser,
@ -424,7 +363,7 @@ class CentralColumnsTest extends AbstractTestCase
$this->dbi->expects(self::once())
->method('fetchResult')
->with(
'SELECT * FROM `pma_central_columns` '
'SELECT * FROM `phpmyadmin`.`pma_central_columns` '
. "WHERE db_name = 'phpmyadmin' AND col_name "
. "NOT IN ('id','col1','col2');",
null,
@ -442,26 +381,23 @@ class CentralColumnsTest extends AbstractTestCase
}
/**
* Test for findExistingColNames
* Test for findExistingColumns
*/
public function testFindExistingColNames(): void
{
$expectedQuery = 'SELECT * FROM `phpmyadmin`.`pma_central_columns`'
. ' WHERE db_name = \'phpmyadmin\' AND col_name IN (\'col1\');';
$this->dbi->expects(self::once())
->method('fetchResult')
->with(
'SELECT * FROM `pma_central_columns` WHERE db_name = \'phpmyadmin\' AND col_name IN (\'col1\');',
null,
null,
ConnectionType::ControlUser,
)
->with($expectedQuery, null, null, ConnectionType::ControlUser)
->willReturn(array_slice($this->columnData, 1, 1));
self::assertSame(
array_slice($this->modifiedColumnData, 1, 1),
$this->callFunction(
$this->centralColumns,
CentralColumns::class,
'findExistingColNames',
['phpmyadmin', ['col1'], true],
'findExistingColumns',
['phpmyadmin', ['col1']],
),
);
}