Get post params from ServerRequest class
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
d5388afdc6
commit
bd2ef2b8ee
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace PhpMyAdmin\Controllers;
|
||||
|
||||
use PhpMyAdmin\BrowseForeigners;
|
||||
use PhpMyAdmin\Http\ServerRequest;
|
||||
use PhpMyAdmin\Relation;
|
||||
use PhpMyAdmin\ResponseRenderer;
|
||||
use PhpMyAdmin\Template;
|
||||
@ -32,19 +33,24 @@ class BrowseForeignersController extends AbstractController
|
||||
$this->relation = $relation;
|
||||
}
|
||||
|
||||
public function __invoke(): void
|
||||
public function __invoke(ServerRequest $request): void
|
||||
{
|
||||
$params = [
|
||||
'db' => $_POST['db'] ?? null,
|
||||
'table' => $_POST['table'] ?? null,
|
||||
'field' => $_POST['field'] ?? null,
|
||||
'fieldkey' => $_POST['fieldkey'] ?? null,
|
||||
'data' => $_POST['data'] ?? null,
|
||||
'foreign_showAll' => $_POST['foreign_showAll'] ?? null,
|
||||
'foreign_filter' => $_POST['foreign_filter'] ?? null,
|
||||
];
|
||||
/** @var string|null $database */
|
||||
$database = $request->getParsedBodyParam('db');
|
||||
/** @var string|null $table */
|
||||
$table = $request->getParsedBodyParam('table');
|
||||
/** @var string|null $field */
|
||||
$field = $request->getParsedBodyParam('field');
|
||||
/** @var string $fieldKey */
|
||||
$fieldKey = $request->getParsedBodyParam('fieldkey', '');
|
||||
/** @var string $data */
|
||||
$data = $request->getParsedBodyParam('data', '');
|
||||
/** @var string|null $foreignShowAll */
|
||||
$foreignShowAll = $request->getParsedBodyParam('foreign_showAll');
|
||||
/** @var string $foreignFilter */
|
||||
$foreignFilter = $request->getParsedBodyParam('foreign_filter', '');
|
||||
|
||||
if (! isset($params['db'], $params['table'], $params['field'])) {
|
||||
if (! isset($database, $table, $field)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -54,28 +60,28 @@ class BrowseForeignersController extends AbstractController
|
||||
$header->setBodyId('body_browse_foreigners');
|
||||
|
||||
$foreigners = $this->relation->getForeigners(
|
||||
$params['db'],
|
||||
$params['table']
|
||||
$database,
|
||||
$table
|
||||
);
|
||||
$foreignLimit = $this->browseForeigners->getForeignLimit(
|
||||
$params['foreign_showAll']
|
||||
$foreignShowAll
|
||||
);
|
||||
$foreignData = $this->relation->getForeignData(
|
||||
$foreigners,
|
||||
$params['field'],
|
||||
$field,
|
||||
true,
|
||||
$params['foreign_filter'] ?? '',
|
||||
$foreignLimit ?? null,
|
||||
$foreignFilter,
|
||||
$foreignLimit ?? '',
|
||||
true
|
||||
);
|
||||
|
||||
$this->response->addHTML($this->browseForeigners->getHtmlForRelationalFieldSelection(
|
||||
$params['db'],
|
||||
$params['table'],
|
||||
$params['field'],
|
||||
$database,
|
||||
$table,
|
||||
$field,
|
||||
$foreignData,
|
||||
$params['fieldkey'] ?? '',
|
||||
$params['data'] ?? ''
|
||||
$fieldKey,
|
||||
$data
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Controllers;
|
||||
|
||||
use PhpMyAdmin\Http\ServerRequest;
|
||||
use PhpMyAdmin\Relation;
|
||||
use PhpMyAdmin\ResponseRenderer;
|
||||
use PhpMyAdmin\Template;
|
||||
@ -25,31 +26,32 @@ class CheckRelationsController extends AbstractController
|
||||
$this->relation = $relation;
|
||||
}
|
||||
|
||||
public function __invoke(): void
|
||||
public function __invoke(ServerRequest $request): void
|
||||
{
|
||||
global $db;
|
||||
|
||||
$params = [
|
||||
'create_pmadb' => $_POST['create_pmadb'] ?? null,
|
||||
'fixall_pmadb' => $_POST['fixall_pmadb'] ?? null,
|
||||
'fix_pmadb' => $_POST['fix_pmadb'] ?? null,
|
||||
];
|
||||
/** @var string|null $createPmaDb */
|
||||
$createPmaDb = $request->getParsedBodyParam('create_pmadb');
|
||||
/** @var string|null $fixAllPmaDb */
|
||||
$fixAllPmaDb = $request->getParsedBodyParam('fixall_pmadb');
|
||||
/** @var string|null $fixPmaDb */
|
||||
$fixPmaDb = $request->getParsedBodyParam('fix_pmadb');
|
||||
|
||||
$cfgStorageDbName = $this->relation->getConfigurationStorageDbName();
|
||||
|
||||
// If request for creating the pmadb
|
||||
if (isset($params['create_pmadb']) && $this->relation->createPmaDatabase($cfgStorageDbName)) {
|
||||
if (isset($createPmaDb) && $this->relation->createPmaDatabase($cfgStorageDbName)) {
|
||||
$this->relation->fixPmaTables($cfgStorageDbName);
|
||||
}
|
||||
|
||||
// If request for creating all PMA tables.
|
||||
if (isset($params['fixall_pmadb'])) {
|
||||
if (isset($fixAllPmaDb)) {
|
||||
$this->relation->fixPmaTables($db);
|
||||
}
|
||||
|
||||
$cfgRelation = $this->relation->getRelationsParam();
|
||||
// If request for creating missing PMA tables.
|
||||
if (isset($params['fix_pmadb'])) {
|
||||
if (isset($fixPmaDb)) {
|
||||
$this->relation->fixPmaTables($cfgRelation['db']);
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace PhpMyAdmin\Controllers;
|
||||
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Http\ServerRequest;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\ResponseRenderer;
|
||||
use PhpMyAdmin\Template;
|
||||
@ -24,15 +25,20 @@ final class ColumnController extends AbstractController
|
||||
$this->dbi = $dbi;
|
||||
}
|
||||
|
||||
public function __invoke(): void
|
||||
public function __invoke(ServerRequest $request): void
|
||||
{
|
||||
if (! isset($_POST['db'], $_POST['table'])) {
|
||||
/** @var string|null $db */
|
||||
$db = $request->getParsedBodyParam('db');
|
||||
/** @var string|null $table */
|
||||
$table = $request->getParsedBodyParam('table');
|
||||
|
||||
if (! isset($db, $table)) {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON(['message' => Message::error()]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->response->addJSON(['columns' => $this->dbi->getColumnNames($_POST['db'], $_POST['table'])]);
|
||||
$this->response->addJSON(['columns' => $this->dbi->getColumnNames($db, $table)]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace PhpMyAdmin\Controllers;
|
||||
|
||||
use PhpMyAdmin\Config;
|
||||
use PhpMyAdmin\Http\ServerRequest;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\ResponseRenderer;
|
||||
use PhpMyAdmin\Template;
|
||||
@ -25,28 +26,36 @@ final class ConfigController extends AbstractController
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function get(): void
|
||||
public function get(ServerRequest $request): void
|
||||
{
|
||||
if (! isset($_POST['key'])) {
|
||||
/** @var string|null $key */
|
||||
$key = $request->getParsedBodyParam('key');
|
||||
|
||||
if (! isset($key)) {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON(['message' => Message::error()]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->response->addJSON(['value' => $this->config->get($_POST['key'])]);
|
||||
$this->response->addJSON(['value' => $this->config->get($key)]);
|
||||
}
|
||||
|
||||
public function set(): void
|
||||
public function set(ServerRequest $request): void
|
||||
{
|
||||
if (! isset($_POST['key'], $_POST['value'])) {
|
||||
/** @var string|null $key */
|
||||
$key = $request->getParsedBodyParam('key');
|
||||
/** @var string|null $value */
|
||||
$value = $request->getParsedBodyParam('value');
|
||||
|
||||
if (! isset($key, $value)) {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON(['message' => Message::error()]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$result = $this->config->setUserValue(null, $_POST['key'], json_decode($_POST['value']));
|
||||
$result = $this->config->setUserValue(null, $key, json_decode($value));
|
||||
|
||||
if ($result === true) {
|
||||
return;
|
||||
|
||||
@ -9,6 +9,7 @@ namespace PhpMyAdmin\Controllers;
|
||||
|
||||
use PhpMyAdmin\ErrorHandler;
|
||||
use PhpMyAdmin\ErrorReport;
|
||||
use PhpMyAdmin\Http\ServerRequest;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\ResponseRenderer;
|
||||
use PhpMyAdmin\Template;
|
||||
@ -46,23 +47,27 @@ class ErrorReportController extends AbstractController
|
||||
$this->errorHandler = $errorHandler;
|
||||
}
|
||||
|
||||
public function __invoke(): void
|
||||
public function __invoke(ServerRequest $request): void
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
if (
|
||||
! isset($_POST['exception_type'])
|
||||
|| ! in_array($_POST['exception_type'], ['js', 'php'])
|
||||
) {
|
||||
/** @var string $exceptionType */
|
||||
$exceptionType = $request->getParsedBodyParam('exception_type', '');
|
||||
/** @var string|null $sendErrorReport */
|
||||
$sendErrorReport = $request->getParsedBodyParam('send_error_report');
|
||||
/** @var string|null $automatic */
|
||||
$automatic = $request->getParsedBodyParam('automatic');
|
||||
/** @var string|null $alwaysSend */
|
||||
$alwaysSend = $request->getParsedBodyParam('always_send');
|
||||
/** @var string|null $getSettings */
|
||||
$getSettings = $request->getParsedBodyParam('get_settings');
|
||||
|
||||
if (! in_array($exceptionType, ['js', 'php'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
isset($_POST['send_error_report'])
|
||||
&& ($_POST['send_error_report'] == true
|
||||
|| $_POST['send_error_report'] == '1')
|
||||
) {
|
||||
if ($_POST['exception_type'] === 'php') {
|
||||
if ($sendErrorReport) {
|
||||
if ($exceptionType === 'php') {
|
||||
/**
|
||||
* Prevent infinite error submission.
|
||||
* Happens in case error submissions fails.
|
||||
@ -85,7 +90,7 @@ class ErrorReportController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
$reportData = $this->errorReport->getData($_POST['exception_type']);
|
||||
$reportData = $this->errorReport->getData($exceptionType);
|
||||
// report if and only if there were 'actual' errors.
|
||||
if (count($reportData) > 0) {
|
||||
$server_response = $this->errorReport->send($reportData);
|
||||
@ -99,11 +104,7 @@ class ErrorReportController extends AbstractController
|
||||
|
||||
/* Message to show to the user */
|
||||
if ($success) {
|
||||
if (
|
||||
(isset($_POST['automatic'])
|
||||
&& $_POST['automatic'] === 'true')
|
||||
|| $cfg['SendErrorReports'] === 'always'
|
||||
) {
|
||||
if ($automatic === 'true' || $cfg['SendErrorReports'] === 'always') {
|
||||
$msg = __(
|
||||
'An error has been detected and an error report has been '
|
||||
. 'automatically submitted based on your settings.'
|
||||
@ -134,35 +135,32 @@ class ErrorReportController extends AbstractController
|
||||
|
||||
/* Add message to response */
|
||||
if ($this->response->isAjax()) {
|
||||
if ($_POST['exception_type'] === 'js') {
|
||||
if ($exceptionType === 'js') {
|
||||
$this->response->addJSON('message', $msg);
|
||||
} else {
|
||||
$this->response->addJSON('errSubmitMsg', $msg);
|
||||
}
|
||||
} elseif ($_POST['exception_type'] === 'php') {
|
||||
} elseif ($exceptionType === 'php') {
|
||||
$jsCode = 'Functions.ajaxShowMessage(\'<div class="alert alert-danger" role="alert">'
|
||||
. $msg
|
||||
. '</div>\', false);';
|
||||
$this->response->getFooter()->getScripts()->addCode($jsCode);
|
||||
}
|
||||
|
||||
if ($_POST['exception_type'] === 'php') {
|
||||
if ($exceptionType === 'php') {
|
||||
// clear previous errors & save new ones.
|
||||
$this->errorHandler->savePreviousErrors();
|
||||
}
|
||||
|
||||
/* Persist always send settings */
|
||||
if (
|
||||
isset($_POST['always_send'])
|
||||
&& $_POST['always_send'] === 'true'
|
||||
) {
|
||||
if ($alwaysSend === 'true') {
|
||||
$userPreferences = new UserPreferences();
|
||||
$userPreferences->persistOption('SendErrorReports', 'always', 'ask');
|
||||
}
|
||||
}
|
||||
} elseif (! empty($_POST['get_settings'])) {
|
||||
} elseif ($getSettings) {
|
||||
$this->response->addJSON('report_setting', $cfg['SendErrorReports']);
|
||||
} elseif ($_POST['exception_type'] === 'js') {
|
||||
} elseif ($exceptionType === 'js') {
|
||||
$this->response->addJSON('report_modal', $this->errorReport->getEmptyModal());
|
||||
$this->response->addHTML($this->errorReport->getForm());
|
||||
} else {
|
||||
|
||||
@ -80,11 +80,6 @@ parameters:
|
||||
count: 1
|
||||
path: libraries/classes/Config/Validator.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#5 \\$foreign_limit of method PhpMyAdmin\\\\Relation\\:\\:getForeignData\\(\\) expects string, string\\|null given\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/Controllers/BrowseForeignersController.php
|
||||
|
||||
-
|
||||
message: "#^Argument of an invalid type array\\|null supplied for foreach, only iterables are supported\\.$#"
|
||||
count: 1
|
||||
|
||||
@ -1083,23 +1083,6 @@
|
||||
<code>$params['message']</code>
|
||||
</MixedAssignment>
|
||||
</file>
|
||||
<file src="libraries/classes/Controllers/BrowseForeignersController.php">
|
||||
<MixedArgument occurrences="10">
|
||||
<code>$params['data'] ?? ''</code>
|
||||
<code>$params['db']</code>
|
||||
<code>$params['db']</code>
|
||||
<code>$params['field']</code>
|
||||
<code>$params['field']</code>
|
||||
<code>$params['fieldkey'] ?? ''</code>
|
||||
<code>$params['foreign_filter'] ?? ''</code>
|
||||
<code>$params['foreign_showAll']</code>
|
||||
<code>$params['table']</code>
|
||||
<code>$params['table']</code>
|
||||
</MixedArgument>
|
||||
<PossiblyNullArgument occurrences="1">
|
||||
<code>$foreignLimit ?? null</code>
|
||||
</PossiblyNullArgument>
|
||||
</file>
|
||||
<file src="libraries/classes/Controllers/ChangeLogController.php">
|
||||
<UnusedFunctionCall occurrences="1">
|
||||
<code>readgzfile</code>
|
||||
@ -1110,18 +1093,9 @@
|
||||
<code>$db</code>
|
||||
</MixedArgument>
|
||||
</file>
|
||||
<file src="libraries/classes/Controllers/ColumnController.php">
|
||||
<MixedArgument occurrences="2">
|
||||
<code>$_POST['db']</code>
|
||||
<code>$_POST['table']</code>
|
||||
</MixedArgument>
|
||||
</file>
|
||||
<file src="libraries/classes/Controllers/ConfigController.php">
|
||||
<MixedArgument occurrences="4">
|
||||
<code>$_POST['key']</code>
|
||||
<code>$_POST['key']</code>
|
||||
<code>$_POST['value']</code>
|
||||
<code>json_decode($_POST['value'])</code>
|
||||
<MixedArgument occurrences="1">
|
||||
<code>json_decode($value)</code>
|
||||
</MixedArgument>
|
||||
</file>
|
||||
<file src="libraries/classes/Controllers/Database/CentralColumnsController.php">
|
||||
@ -1861,9 +1835,6 @@
|
||||
</MixedPropertyFetch>
|
||||
</file>
|
||||
<file src="libraries/classes/Controllers/ErrorReportController.php">
|
||||
<MixedArgument occurrences="1">
|
||||
<code>$_POST['exception_type']</code>
|
||||
</MixedArgument>
|
||||
<MixedArrayAccess occurrences="1">
|
||||
<code>$decoded_response['success']</code>
|
||||
</MixedArrayAccess>
|
||||
@ -14130,22 +14101,10 @@
|
||||
</RedundantCondition>
|
||||
</file>
|
||||
<file src="libraries/classes/Routing.php">
|
||||
<MixedArgument occurrences="3">
|
||||
<MixedArgument occurrences="2">
|
||||
<code>$_GET['db']</code>
|
||||
<code>$_GET['table']</code>
|
||||
<code>$controllerName</code>
|
||||
</MixedArgument>
|
||||
<MixedArrayAccess occurrences="2">
|
||||
<code>$action</code>
|
||||
<code>$controllerName</code>
|
||||
</MixedArrayAccess>
|
||||
<MixedAssignment occurrences="2">
|
||||
<code>$controller</code>
|
||||
<code>[$controllerName, $action]</code>
|
||||
</MixedAssignment>
|
||||
<MixedMethodCall occurrences="1">
|
||||
<code>$action</code>
|
||||
</MixedMethodCall>
|
||||
</file>
|
||||
<file src="libraries/classes/Sanitize.php">
|
||||
<MixedArgument occurrences="6">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user