diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-11-09 20:55:14 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-11-09 20:55:14 +0300 |
commit | 77f9ebb61a9a7f03ddb184d6b5d3b51cc152c001 (patch) | |
tree | 60b0472c41aeaa002585ee80466c72da7c1f5795 | |
parent | c337b72d5657d33c0f516f93c068d77dfeef5d2f (diff) |
Improve error message when UseDbSearch config is disabled
Replaces Html\Generator::mysqlDie() to avoid calling the exit construct.
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
-rw-r--r-- | libraries/classes/Controllers/Database/SearchController.php | 22 | ||||
-rw-r--r-- | psalm-baseline.xml | 5 | ||||
-rw-r--r-- | templates/error/simple.twig | 11 |
3 files changed, 27 insertions, 11 deletions
diff --git a/libraries/classes/Controllers/Database/SearchController.php b/libraries/classes/Controllers/Database/SearchController.php index 07ab737a03..0fb26dab85 100644 --- a/libraries/classes/Controllers/Database/SearchController.php +++ b/libraries/classes/Controllers/Database/SearchController.php @@ -7,8 +7,9 @@ namespace PhpMyAdmin\Controllers\Database; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\Database\Search; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\Html\MySQLDocumentation; use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Message; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\Template; use PhpMyAdmin\Url; @@ -49,14 +50,21 @@ class SearchController extends AbstractController return; } - // If config variable $cfg['UseDbSearch'] is on false : exit. if (! $GLOBALS['cfg']['UseDbSearch']) { - Generator::mysqlDie( - __('Access denied!'), - '', - false, - $GLOBALS['errorUrl'] + $errorMessage = __( + 'Searching inside the database is disabled by the [code]$cfg[\'UseDbSearch\'][/code] configuration.' ); + $errorMessage .= MySQLDocumentation::showDocumentation('config', 'cfg_UseDbSearch'); + $this->response->setRequestStatus(false); + if ($this->response->isAjax()) { + $this->response->addJSON('message', Message::error($errorMessage)->getDisplay()); + + return; + } + + $this->render('error/simple', ['error_message' => $errorMessage, 'back_url' => $GLOBALS['errorUrl']]); + + return; } $GLOBALS['urlParams']['goto'] = Url::getFromRoute('/database/search'); diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 832def3006..6a888b10e0 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -13388,10 +13388,7 @@ </PossiblyNullArgument> </file> <file src="libraries/classes/Table.php"> - <DeprecatedMethod occurrences="49"> - <code>escapeString</code> - <code>escapeString</code> - <code>escapeString</code> + <DeprecatedMethod occurrences="46"> <code>escapeString</code> <code>escapeString</code> <code>escapeString</code> diff --git a/templates/error/simple.twig b/templates/error/simple.twig new file mode 100644 index 0000000000..8655f7f76b --- /dev/null +++ b/templates/error/simple.twig @@ -0,0 +1,11 @@ +<div class="container"> + <h2>{{ 'Something went wrong'|trans }}</h2> + <div class="card"> + <div class="card-body"> + {{ error_message|error }} + {% if back_url != '' %} + <a class="card-link" href="{{ back_url }}">{{ 'Go back'|trans }}</a> + {% endif %} + </div> + </div> +</div> |