Create the DatabaseServerVersionChecking middleware

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2023-08-16 17:26:22 -03:00
parent deb3214a55
commit c8c92467cb
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
3 changed files with 57 additions and 24 deletions

View File

@ -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,
]));
}
}

View File

@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Middleware;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Config;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Template;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use function __;
use function sprintf;
final class DatabaseServerVersionChecking implements MiddlewareInterface
{
public function __construct(
private readonly Config $config,
private readonly Template $template,
private readonly ResponseFactory $responseFactory,
) {
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$settings = $this->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);
}
}

View File

@ -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