From c8c92467cb60dece77eb126e802660f8638afef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 16 Aug 2023 17:26:22 -0300 Subject: [PATCH] Create the DatabaseServerVersionChecking middleware MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- libraries/classes/Application.php | 21 +------- .../DatabaseServerVersionChecking.php | 50 +++++++++++++++++++ phpstan-baseline.neon | 10 ++-- 3 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 libraries/classes/Middleware/DatabaseServerVersionChecking.php diff --git a/libraries/classes/Application.php b/libraries/classes/Application.php index fc60579425..9ced9f9320 100644 --- a/libraries/classes/Application.php +++ b/libraries/classes/Application.php @@ -21,6 +21,7 @@ use PhpMyAdmin\Middleware\ConfigErrorAndPermissionChecking; use PhpMyAdmin\Middleware\ConfigLoading; use PhpMyAdmin\Middleware\CurrentServerGlobalSetting; use PhpMyAdmin\Middleware\DatabaseAndTableSetting; +use PhpMyAdmin\Middleware\DatabaseServerVersionChecking; use PhpMyAdmin\Middleware\DbiLoading; use PhpMyAdmin\Middleware\EncryptedQueryParamsHandling; use PhpMyAdmin\Middleware\ErrorHandling; @@ -124,6 +125,7 @@ class Application $requestHandler->add(new DbiLoading()); $requestHandler->add(new LoginCookieValiditySetting($this->config)); $requestHandler->add(new Authentication($this->config, $this->template, $this->responseFactory)); + $requestHandler->add(new DatabaseServerVersionChecking($this->config, $this->template, $this->responseFactory)); $runner = new RequestHandlerRunner( $requestHandler, @@ -153,14 +155,6 @@ class Application $currentServer = $this->config->getCurrentServer(); if ($currentServer !== null) { - if ($GLOBALS['dbi']->getVersion() < $settings->mysqlMinVersion['internal']) { - return $this->getGenericErrorResponse(sprintf( - __('You should upgrade to %s %s or later.'), - 'MySQL', - $settings->mysqlMinVersion['human'], - )); - } - /** @var mixed $sqlDelimiter */ $sqlDelimiter = $request->getParam('sql_delimiter', ''); if (is_string($sqlDelimiter) && $sqlDelimiter !== '') { @@ -326,15 +320,4 @@ class Application $GLOBALS['urlParams']['table'] = $GLOBALS['table']; $container->setParameter('url_params', $GLOBALS['urlParams']); } - - private function getGenericErrorResponse(string $message): Response - { - $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); - - return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', - 'dir' => $GLOBALS['text_dir'] ?? 'ltr', - 'error_message' => $message, - ])); - } } diff --git a/libraries/classes/Middleware/DatabaseServerVersionChecking.php b/libraries/classes/Middleware/DatabaseServerVersionChecking.php new file mode 100644 index 0000000000..fabd5f5b83 --- /dev/null +++ b/libraries/classes/Middleware/DatabaseServerVersionChecking.php @@ -0,0 +1,50 @@ +config->getSettings(); + if ( + $this->config->getCurrentServer() !== null + && $GLOBALS['dbi']->getVersion() < $settings->mysqlMinVersion['internal'] + ) { + $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); + + return $response->write($this->template->render('error/generic', [ + 'lang' => $GLOBALS['lang'] ?? 'en', + 'dir' => $GLOBALS['text_dir'] ?? 'ltr', + 'error_message' => sprintf( + __('You should upgrade to %s %s or later.'), + 'MySQL', + $settings->mysqlMinVersion['human'], + ), + ])); + } + + return $handler->handle($request); + } +} diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 89523a3836..575a223b98 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -50,11 +50,6 @@ parameters: count: 1 path: libraries/classes/Application.php - - - message: "#^Cannot call method getVersion\\(\\) on mixed\\.$#" - count: 1 - path: libraries/classes/Application.php - - message: "#^Cannot call method postConnectControl\\(\\) on mixed\\.$#" count: 1 @@ -15830,6 +15825,11 @@ parameters: count: 1 path: libraries/classes/Middleware/CurrentServerGlobalSetting.php + - + message: "#^Cannot call method getVersion\\(\\) on mixed\\.$#" + count: 1 + path: libraries/classes/Middleware/DatabaseServerVersionChecking.php + - message: "#^Cannot cast mixed to string\\.$#" count: 1