Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Tekiela <tekiela246@gmail.com>2022-11-07 01:48:49 +0300
committerKamil Tekiela <tekiela246@gmail.com>2022-11-08 03:31:47 +0300
commitba41957e5f51efb63c562e94b986cd8f0912d39b (patch)
tree25e6207a37b3ab0a259f0115aa51ff858fc7040a
parent4405b8afa42ad4057189a48b1ab6ca14d04403fc (diff)
Redesign PrimaryController
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
-rw-r--r--libraries/classes/Controllers/Table/Structure/PrimaryController.php49
-rw-r--r--phpstan-baseline.neon15
-rw-r--r--psalm-baseline.xml14
3 files changed, 19 insertions, 59 deletions
diff --git a/libraries/classes/Controllers/Table/Structure/PrimaryController.php b/libraries/classes/Controllers/Table/Structure/PrimaryController.php
index d218e1d94a..79777e0787 100644
--- a/libraries/classes/Controllers/Table/Structure/PrimaryController.php
+++ b/libraries/classes/Controllers/Table/Structure/PrimaryController.php
@@ -17,6 +17,7 @@ use PhpMyAdmin\Util;
use function __;
use function count;
+use function is_array;
final class PrimaryController extends AbstractController
{
@@ -43,26 +44,23 @@ final class PrimaryController extends AbstractController
$GLOBALS['urlParams'] = $GLOBALS['urlParams'] ?? null;
$GLOBALS['errorUrl'] = $GLOBALS['errorUrl'] ?? null;
- $selected = $request->getParsedBodyParam('selected', []);
- $selected_fld = $request->getParsedBodyParam('selected_fld', []);
+ /** @var string[]|null $selected */
+ $selected = $request->getParsedBodyParam('selected_fld', $request->getParsedBodyParam('selected'));
- if (empty($selected) && empty($selected_fld)) {
+ if (! is_array($selected) || $selected === []) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', __('No column selected.'));
return;
}
- $primary = $this->getKeyForTablePrimary();
- if (empty($primary) && ! empty($selected_fld)) {
- // no primary key, so we can safely create new
- $mult_btn = __('Yes');
- $selected = $selected_fld;
- }
+ $this->dbi->selectDb($GLOBALS['db']);
+ $hasPrimary = $this->hasPrimaryKey();
- $mult_btn = $_POST['mult_btn'] ?? $mult_btn ?? '';
+ /** @var string|null $deletionConfirmed */
+ $deletionConfirmed = $request->getParsedBodyParam('mult_btn', null);
- if (! empty($selected_fld) && ! empty($primary)) {
+ if ($hasPrimary && $deletionConfirmed === null) {
$this->checkParameters(['db', 'table']);
$GLOBALS['urlParams'] = ['db' => $GLOBALS['db'], 'table' => $GLOBALS['table']];
@@ -74,15 +72,15 @@ final class PrimaryController extends AbstractController
$this->render('table/structure/primary', [
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
- 'selected' => $selected_fld,
+ 'selected' => $selected,
]);
return;
}
- if ($mult_btn === __('Yes')) {
+ if ($deletionConfirmed === __('Yes') || ! $hasPrimary) {
$GLOBALS['sql_query'] = 'ALTER TABLE ' . Util::backquote($GLOBALS['table']);
- if (! empty($primary)) {
+ if ($hasPrimary) {
$GLOBALS['sql_query'] .= ' DROP PRIMARY KEY,';
}
@@ -110,27 +108,16 @@ final class PrimaryController extends AbstractController
($this->structureController)($request);
}
- /**
- * Gets table primary key
- *
- * @return string
- */
- private function getKeyForTablePrimary()
+ private function hasPrimaryKey(): bool
{
- $this->dbi->selectDb($GLOBALS['db']);
- $result = $this->dbi->query(
- 'SHOW KEYS FROM ' . Util::backquote($GLOBALS['table']) . ';'
- );
- $primary = '';
+ $result = $this->dbi->query('SHOW KEYS FROM ' . Util::backquote($GLOBALS['table']));
+
foreach ($result as $row) {
- // Backups the list of primary keys
- if ($row['Key_name'] !== 'PRIMARY') {
- continue;
+ if ($row['Key_name'] === 'PRIMARY') {
+ return true;
}
-
- $primary .= $row['Column_name'] . ', ';
}
- return $primary;
+ return false;
}
}
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 810b20150f..11394018d2 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -1733,21 +1733,6 @@ parameters:
-
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
count: 1
- path: libraries/classes/Controllers/Table/Structure/PrimaryController.php
-
- -
- message: "#^Parameter \\#1 \\$identifier of static method PhpMyAdmin\\\\Util\\:\\:backquote\\(\\) expects string\\|Stringable\\|null, mixed given\\.$#"
- count: 1
- path: libraries/classes/Controllers/Table/Structure/PrimaryController.php
-
- -
- message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#"
- count: 1
- path: libraries/classes/Controllers/Table/Structure/PrimaryController.php
-
- -
- message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
- count: 1
path: libraries/classes/Controllers/Table/Structure/ReservedWordCheckController.php
-
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index d888ab2316..cf4e514f5a 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -4028,21 +4028,9 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="libraries/classes/Controllers/Table/Structure/PrimaryController.php">
- <MixedArgument occurrences="2">
- <code>$field</code>
- <code>$selected</code>
- </MixedArgument>
- <MixedAssignment occurrences="6">
+ <MixedAssignment occurrences="1">
<code>$GLOBALS['errorUrl']</code>
- <code>$field</code>
- <code>$mult_btn</code>
- <code>$selected</code>
- <code>$selected</code>
- <code>$selected_fld</code>
</MixedAssignment>
- <PossiblyNullOperand occurrences="1">
- <code>$row['Column_name']</code>
- </PossiblyNullOperand>
</file>
<file src="libraries/classes/Controllers/Table/Structure/ReservedWordCheckController.php">
<MixedArgument occurrences="1">