Visitar URL original
Merge pull request #20520 from MauricioFauth/export_item-get-param · phpmyadmin/phpmyadmin@bfa1018 · GitHub
Skip to content

Commit bfa1018

Browse files
Merge pull request #20520 from MauricioFauth/export_item-get-param
Get export_item param from ServerRequest object
2 parents f80ee53 + 3ff024f commit bfa1018

4 files changed

Lines changed: 36 additions & 61 deletions

File tree

‎phpstan-baseline.neon‎

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,13 +1374,13 @@ parameters:
13741374
-
13751375
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
13761376
identifier: empty.notAllowed
1377-
count: 16
1377+
count: 14
13781378
path: src/Controllers/Database/EventsController.php
13791379

13801380
-
13811381
message: '#^Parameter \#1 \$identifier of static method PhpMyAdmin\\Util\:\:backquote\(\) expects string\|Stringable\|null, mixed given\.$#'
13821382
identifier: argument.type
1383-
count: 2
1383+
count: 1
13841384
path: src/Controllers/Database/EventsController.php
13851385

13861386
-
@@ -1401,12 +1401,6 @@ parameters:
14011401
count: 1
14021402
path: src/Controllers/Database/EventsController.php
14031403

1404-
-
1405-
message: '#^Parameter \#3 \$name of static method PhpMyAdmin\\Database\\Events\:\:getDefinition\(\) expects string, mixed given\.$#'
1406-
identifier: argument.type
1407-
count: 1
1408-
path: src/Controllers/Database/EventsController.php
1409-
14101404
-
14111405
message: '#^Cannot access offset ''handler'' on mixed\.$#'
14121406
identifier: offsetAccess.nonOffsetAccessible
@@ -1434,7 +1428,7 @@ parameters:
14341428
-
14351429
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
14361430
identifier: empty.notAllowed
1437-
count: 23
1431+
count: 21
14381432
path: src/Controllers/Database/RoutinesController.php
14391433

14401434
-
@@ -1446,7 +1440,7 @@ parameters:
14461440
-
14471441
message: '#^Parameter \#1 \$identifier of static method PhpMyAdmin\\Util\:\:backquote\(\) expects string\|Stringable\|null, mixed given\.$#'
14481442
identifier: argument.type
1449-
count: 4
1443+
count: 3
14501444
path: src/Controllers/Database/RoutinesController.php
14511445

14521446
-
@@ -1473,18 +1467,6 @@ parameters:
14731467
count: 3
14741468
path: src/Controllers/Database/RoutinesController.php
14751469

1476-
-
1477-
message: '#^Parameter \#3 \$name of static method PhpMyAdmin\\Database\\Routines\:\:getFunctionDefinition\(\) expects string, mixed given\.$#'
1478-
identifier: argument.type
1479-
count: 1
1480-
path: src/Controllers/Database/RoutinesController.php
1481-
1482-
-
1483-
message: '#^Parameter \#3 \$name of static method PhpMyAdmin\\Database\\Routines\:\:getProcedureDefinition\(\) expects string, mixed given\.$#'
1484-
identifier: argument.type
1485-
count: 1
1486-
path: src/Controllers/Database/RoutinesController.php
1487-
14881470
-
14891471
message: '#^Parameter \#4 \$name of static method PhpMyAdmin\\Database\\Routines\:\:getDetails\(\) expects string, mixed given\.$#'
14901472
identifier: argument.type

‎psalm-baseline.xml‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -714,21 +714,16 @@
714714
<code><![CDATA[$_POST['item_name']]]></code>
715715
<code><![CDATA[$_REQUEST['item_name']]]></code>
716716
<code><![CDATA[$_REQUEST['item_name']]]></code>
717-
<code><![CDATA[$itemName]]></code>
718-
<code><![CDATA[$itemName]]></code>
719717
</PossiblyInvalidArgument>
720718
<PossiblyInvalidCast>
721719
<code><![CDATA[$_POST['item_name']]]></code>
722720
<code><![CDATA[$_POST['item_name']]]></code>
723721
<code><![CDATA[$_REQUEST['item_name']]]></code>
724-
<code><![CDATA[$itemName]]></code>
725722
</PossiblyInvalidCast>
726723
<PossiblyUnusedReturnValue>
727724
<code><![CDATA[Response]]></code>
728725
</PossiblyUnusedReturnValue>
729726
<RiskyTruthyFalsyComparison>
730-
<code><![CDATA[empty($_GET['export_item'])]]></code>
731-
<code><![CDATA[empty($_GET['item_name'])]]></code>
732727
<code><![CDATA[empty($_POST['editor_process_add'])]]></code>
733728
<code><![CDATA[empty($_POST['editor_process_add'])]]></code>
734729
<code><![CDATA[empty($_POST['editor_process_edit'])]]></code>
@@ -790,9 +785,6 @@
790785
<code><![CDATA[Current::$database]]></code>
791786
</MixedArgument>
792787
<PossiblyInvalidArgument>
793-
<code><![CDATA[$_GET['item_name']]]></code>
794-
<code><![CDATA[$_GET['item_name']]]></code>
795-
<code><![CDATA[$_GET['item_name']]]></code>
796788
<code><![CDATA[$_GET['item_name']]]></code>
797789
<code><![CDATA[$_GET['item_name']]]></code>
798790
<code><![CDATA[$_GET['item_name']]]></code>
@@ -807,8 +799,6 @@
807799
<code><![CDATA[$_REQUEST['type'] ?? '']]></code>
808800
</PossiblyInvalidArgument>
809801
<PossiblyInvalidCast>
810-
<code><![CDATA[$_GET['item_name']]]></code>
811-
<code><![CDATA[$_GET['item_name']]]></code>
812802
<code><![CDATA[$_GET['item_name']]]></code>
813803
<code><![CDATA[$_GET['item_name']]]></code>
814804
<code><![CDATA[$_GET['item_type']]]></code>
@@ -826,8 +816,6 @@
826816
</PossiblyUnusedReturnValue>
827817
<RiskyTruthyFalsyComparison>
828818
<code><![CDATA[empty($_GET['execute_dialog'])]]></code>
829-
<code><![CDATA[empty($_GET['export_item'])]]></code>
830-
<code><![CDATA[empty($_GET['item_name'])]]></code>
831819
<code><![CDATA[empty($_GET['item_name'])]]></code>
832820
<code><![CDATA[empty($_GET['item_name'])]]></code>
833821
<code><![CDATA[empty($_POST['editor_process_add'])]]></code>

‎src/Controllers/Database/EventsController.php‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
use function __;
2222
use function htmlspecialchars;
23+
use function is_string;
2324
use function mb_strtoupper;
2425
use function sprintf;
2526
use function trim;
@@ -203,18 +204,18 @@ public function __invoke(ServerRequest $request): Response
203204
$this->response->addHTML($message);
204205
}
205206

206-
if (! empty($_GET['export_item']) && ! empty($_GET['item_name'])) {
207-
$itemName = $_GET['item_name'];
208-
$exportData = Events::getDefinition($this->dbi, Current::$database, $itemName);
207+
$eventName = $this->getEventName($request->getQueryParam('item_name'));
208+
if ($request->hasQueryParam('export_item') && $eventName !== '') {
209+
$exportData = Events::getDefinition($this->dbi, Current::$database, $eventName);
209210

210211
if ($exportData === null || $exportData === '') {
211212
$exportData = false;
212213
}
213214

214-
$itemName = Util::backquote($itemName);
215+
$eventName = Util::backquote($eventName);
215216
if ($exportData !== false) {
216217
$exportData = trim($exportData);
217-
$title = sprintf(__('Export of event %s'), $itemName);
218+
$title = sprintf(__('Export of event %s'), $eventName);
218219

219220
if ($request->isAjax()) {
220221
$this->response->addJSON('message', $exportData);
@@ -235,7 +236,7 @@ public function __invoke(ServerRequest $request): Response
235236
} else {
236237
$message = sprintf(
237238
__('Error in processing request: No event with name %1$s found in database %2$s.'),
238-
htmlspecialchars($itemName),
239+
htmlspecialchars($eventName),
239240
htmlspecialchars(Util::backquote(Current::$database)),
240241
);
241242
$message = Message::error($message);
@@ -263,4 +264,9 @@ public function __invoke(ServerRequest $request): Response
263264

264265
return $this->response->response();
265266
}
267+
268+
private function getEventName(mixed $param): string
269+
{
270+
return is_string($param) ? $param : '';
271+
}
266272
}

‎src/Controllers/Database/RoutinesController.php‎

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use function __;
3030
use function htmlspecialchars;
3131
use function in_array;
32+
use function is_string;
3233
use function max;
3334
use function mb_strtoupper;
3435
use function sprintf;
@@ -362,25 +363,13 @@ public function __invoke(ServerRequest $request): Response
362363
}
363364
}
364365

365-
/** @var mixed $routineType */
366-
$routineType = $request->getQueryParam('item_type');
367-
if (
368-
! empty($_GET['export_item'])
369-
&& ! empty($_GET['item_name'])
370-
&& in_array($routineType, ['FUNCTION', 'PROCEDURE'], true)
371-
) {
372-
if ($routineType === 'FUNCTION') {
373-
$routineDefinition = Routines::getFunctionDefinition(
374-
$this->dbi,
375-
Current::$database,
376-
$_GET['item_name'],
377-
);
366+
$routineType = $this->getRoutineType($request->getQueryParam('item_type'));
367+
$routineName = $this->getRoutineName($request->getQueryParam('item_name'));
368+
if ($request->hasQueryParam('export_item') && $routineName !== '' && $routineType !== null) {
369+
if ($routineType === RoutineType::Function) {
370+
$routineDefinition = Routines::getFunctionDefinition($this->dbi, Current::$database, $routineName);
378371
} else {
379-
$routineDefinition = Routines::getProcedureDefinition(
380-
$this->dbi,
381-
Current::$database,
382-
$_GET['item_name'],
383-
);
372+
$routineDefinition = Routines::getProcedureDefinition($this->dbi, Current::$database, $routineName);
384373
}
385374

386375
$exportData = false;
@@ -389,10 +378,10 @@ public function __invoke(ServerRequest $request): Response
389378
$exportData = "DELIMITER $$\n" . $routineDefinition . "$$\nDELIMITER ;\n";
390379
}
391380

392-
$itemName = Util::backquote($_GET['item_name']);
381+
$routineName = Util::backquote($routineName);
393382
if ($exportData !== false) {
394383
$exportData = trim($exportData);
395-
$title = sprintf(__('Export of routine %s'), $itemName);
384+
$title = sprintf(__('Export of routine %s'), $routineName);
396385

397386
if ($request->isAjax()) {
398387
$this->response->addJSON('message', $exportData);
@@ -414,7 +403,7 @@ public function __invoke(ServerRequest $request): Response
414403
'Error in processing request: No routine with name %1$s found in database %2$s.'
415404
. ' You might be lacking the necessary privileges to view/export this routine.',
416405
),
417-
htmlspecialchars($itemName),
406+
htmlspecialchars($routineName),
418407
htmlspecialchars(Util::backquote(Current::$database)),
419408
);
420409
$message = Message::error($message);
@@ -490,4 +479,14 @@ public function __invoke(ServerRequest $request): Response
490479

491480
return $this->response->response();
492481
}
482+
483+
private function getRoutineType(mixed $param): RoutineType|null
484+
{
485+
return is_string($param) ? RoutineType::tryFrom($param) : null;
486+
}
487+
488+
private function getRoutineName(mixed $param): string
489+
{
490+
return is_string($param) ? $param : '';
491+
}
493492
}

0 commit comments

Comments
 (0)