1
0
mirror of https://github.com/phpmyadmin/phpmyadmin.git synced 2026-10-23 18:29:15 +03:00

New respondWithErrorMessage()

Adds a new helper method to remove some visual clutter.

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela
2026-10-19 21:22:39 +01:00
committed by Maurício Meneghini Fauth
parent df0f08fd5d
commit ef60f1df38
40 changed files with 83 additions and 406 deletions

View File

@@ -13,7 +13,6 @@ use PhpMyAdmin\DbTableExists;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing\Route;
use PhpMyAdmin\Template;
@@ -170,14 +169,7 @@ final readonly class DesignerController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$scriptDisplayField = $this->designerCommon->getTablesInfo();

View File

@@ -52,14 +52,7 @@ final readonly class ExportController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
UrlParams::$params['goto'] = Url::getFromRoute('/database/export');

View File

@@ -57,14 +57,7 @@ final readonly class ImportController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$uploadId = $this->ajax->uploadProgressSetup();

View File

@@ -75,7 +75,7 @@ final readonly class RoutinesController implements InvocableController
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
return $this->response->redirectToRoute(
'/',
['reload' => true, 'message' => __('No databases selected.')],
['reload' => true, 'message' => __('No database selected.')],
);
}
@@ -93,7 +93,7 @@ final readonly class RoutinesController implements InvocableController
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
return $this->response->redirectToRoute(
'/',
['reload' => true, 'message' => __('No databases selected.')],
['reload' => true, 'message' => __('No database selected.')],
);
}
}

View File

@@ -48,14 +48,7 @@ final readonly class SearchController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
if (! $this->config->config->UseDbSearch) {

View File

@@ -11,7 +11,6 @@ use PhpMyAdmin\DbTableExists;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing\Route;
use PhpMyAdmin\SqlQueryForm;
@@ -49,14 +48,7 @@ readonly class SqlController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
/**

View File

@@ -62,7 +62,7 @@ final readonly class FavoriteTableController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
$this->response->addJSON('message', Message::error(__('No database selected.')));
return $this->response->response();
}

View File

@@ -49,7 +49,7 @@ final readonly class RealRowCountController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
$this->response->addJSON('message', Message::error(__('No database selected.')));
return $this->response->response();
}

View File

@@ -22,7 +22,6 @@ use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Identifiers\TableName;
use PhpMyAdmin\Message;
use PhpMyAdmin\Query\Utilities;
use PhpMyAdmin\Replication\Replication;
use PhpMyAdmin\Replication\ReplicationInfo;
@@ -155,14 +154,7 @@ final class StructureController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$this->response->addScriptFiles(['database/structure.js', 'table/change.js']);

View File

@@ -50,14 +50,7 @@ final readonly class TrackingController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
UrlParams::$params['goto'] = Url::getFromRoute('/table/tracking');

View File

@@ -35,15 +35,7 @@ final readonly class ExportController implements InvocableController
{
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
$message = __('No database selected.');
if (! $request->isAjax()) {
return $this->responseRenderer->redirectToRoute('/', ['reload' => true, 'message' => $message]);
}
$this->responseRenderer->addJSON('message', $message);
$this->responseRenderer->setRequestStatus(false);
return $this->responseRenderer->response();
return $this->responseRenderer->respondWithErrorMessage(__('No database selected.'));
}
$this->responseRenderer->addScriptFiles(['events.js', 'sql.js']);

View File

@@ -37,15 +37,7 @@ final readonly class IndexController implements InvocableController
{
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
$message = __('No database selected.');
if (! $request->isAjax()) {
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => $message]);
}
$this->response->addJSON('message', $message);
$this->response->setRequestStatus(false);
return $this->response->response();
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$this->response->addScriptFiles(['events.js', 'sql.js']);

View File

@@ -328,7 +328,7 @@ final readonly class JavaScriptMessagesController implements InvocableController
'It seems that the connection to server has been lost. Please check your ' .
'network connectivity and server status.',
),
'strNoDatabasesSelected' => __('No databases selected.'),
'strNoDatabasesSelected' => __('No database selected.'),
'strNoTableSelected' => __('No table selected.'),
'strNoAccountSelected' => __('No accounts selected.'),
'strDroppingColumn' => __('Dropping column'),

View File

@@ -51,7 +51,7 @@ final readonly class CollationController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
$this->response->addJSON('message', Message::error(__('No database selected.')));
return $this->response->response();
}

View File

@@ -225,14 +225,7 @@ final readonly class DatabaseController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
UrlParams::$params['goto'] = Url::getFromRoute('/database/operations');

View File

@@ -81,26 +81,12 @@ final readonly class TableController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
UrlParams::$params['goto'] = UrlParams::$params['back'] = Url::getFromRoute('/table/operations');

View File

@@ -57,26 +57,12 @@ final readonly class ViewController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
UrlParams::$params['goto'] = UrlParams::$params['back'] = Url::getFromRoute('/view/operations');

View File

@@ -59,7 +59,7 @@ final readonly class DestroyController implements InvocableController
&& $database !== $pmadb);
if ($selectedDbs === []) {
$message = Message::error(__('No databases selected.'));
$message = Message::error(__('No database selected.'));
$json = ['message' => $message];
$this->response->setRequestStatus($message->isSuccess());
$this->response->addJSON($json);

View File

@@ -155,26 +155,12 @@ final readonly class AddFieldController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
$this->response->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js']);

View File

@@ -17,7 +17,6 @@ use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Identifiers\TableName;
use PhpMyAdmin\InsertEdit;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing\Route;
use PhpMyAdmin\Template;
@@ -65,26 +64,12 @@ class ChangeController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
$this->setInsertRowsParam($request->getParsedBodyParam('insert_rows'));

View File

@@ -81,29 +81,12 @@ final readonly class ChartController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute(
'/',
['reload' => true, 'message' => __('No databases selected.')],
);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
$urlParams['goto'] = Url::getFromRoute($this->config->config->DefaultTabTable);
@@ -115,17 +98,7 @@ final readonly class ChartController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute(
'/',
['reload' => true, 'message' => __('No databases selected.')],
);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
} else {
$urlParams['goto'] = Url::getFromRoute($this->config->config->DefaultTabServer);
@@ -202,7 +175,7 @@ final readonly class ChartController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
$this->response->addJSON('message', Message::error(__('No database selected.')));
return;
}

View File

@@ -11,7 +11,6 @@ use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Identifiers\TableName;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing\Route;
use PhpMyAdmin\UrlParams;
@@ -52,26 +51,12 @@ final readonly class DeleteConfirmController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
$this->response->render('table/delete/confirm', [

View File

@@ -47,25 +47,11 @@ final readonly class DropColumnConfirmationController implements InvocableContro
}
if (! $this->dbTableExists->selectDatabase($db)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
if (! $this->dbTableExists->hasTable($db, $table)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
$this->response->render('table/structure/drop_confirm', [

View File

@@ -71,26 +71,12 @@ final class FindReplaceController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
$this->loadTableInfo();

View File

@@ -65,14 +65,7 @@ final readonly class GisVisualizationController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
// SQL query for retrieving GIS data

View File

@@ -66,26 +66,12 @@ final readonly class ImportController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
UrlParams::$params['goto'] = Url::getFromRoute('/table/import');

View File

@@ -49,26 +49,12 @@ final readonly class IndexRenameController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
$oldIndexName = $request->getParsedBodyParamAsStringOrNull('old_index');

View File

@@ -61,29 +61,12 @@ final readonly class IndexesController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute(
'/',
['reload' => true, 'message' => __('No databases selected.')],
);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
}

View File

@@ -15,7 +15,6 @@ use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Identifiers\TableName;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing\Route;
use PhpMyAdmin\Sql;
@@ -166,26 +165,12 @@ final class SearchController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
$this->loadTableInfo();

View File

@@ -12,7 +12,6 @@ use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Identifiers\TableName;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing\Route;
use PhpMyAdmin\SqlQueryForm;
@@ -54,26 +53,12 @@ readonly class SqlController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
/**

View File

@@ -64,29 +64,12 @@ final readonly class PrimaryController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute(
'/',
['reload' => true, 'message' => __('No databases selected.')],
);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
$this->response->render('table/structure/primary', [

View File

@@ -23,7 +23,6 @@ use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Identifiers\TableName;
use PhpMyAdmin\Indexes\Index;
use PhpMyAdmin\Message;
use PhpMyAdmin\Partitioning\Partition;
use PhpMyAdmin\Query\Utilities;
use PhpMyAdmin\ResponseRenderer;
@@ -88,26 +87,12 @@ readonly class StructureController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
$primary = Index::getPrimary($this->dbi, Current::$table, Current::$database);

View File

@@ -64,14 +64,7 @@ final readonly class TrackingController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$activeMessage = '';

View File

@@ -16,7 +16,6 @@ use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Identifiers\TableName;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing\Route;
use PhpMyAdmin\Table\Search;
@@ -97,26 +96,12 @@ final class ZoomSearchController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
$tableName = TableName::tryFrom($request->getParam('table'));
if ($tableName === null || ! $this->dbTableExists->hasTable($databaseName, $tableName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No table selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No table selected.')]);
return $this->response->respondWithErrorMessage(__('No table selected.'));
}
$this->loadTableInfo();

View File

@@ -63,7 +63,7 @@ final readonly class IndexController implements InvocableController
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
return $this->response->redirectToRoute(
'/',
['reload' => true, 'message' => __('No databases selected.')],
['reload' => true, 'message' => __('No database selected.')],
);
}
@@ -81,7 +81,7 @@ final readonly class IndexController implements InvocableController
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
return $this->response->redirectToRoute(
'/',
['reload' => true, 'message' => __('No databases selected.')],
['reload' => true, 'message' => __('No database selected.')],
);
}
}

View File

@@ -63,14 +63,7 @@ final class CreateController implements InvocableController
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
if ($request->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error(__('No databases selected.')));
return $this->response->response();
}
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
return $this->response->respondWithErrorMessage(__('No database selected.'));
}
UrlParams::$params['goto'] = Url::getFromRoute('/table/structure');

View File

@@ -461,4 +461,16 @@ class ResponseRenderer
{
$this->addHTML($this->template->render($templatePath, $templateData));
}
public function respondWithErrorMessage(string $errorMessage): Response
{
if ($this->isAjax()) {
$this->setRequestStatus(false);
$this->addJSON('message', Message::error($errorMessage));
return $this->response();
}
return $this->redirectToRoute('/', ['reload' => true, 'message' => $errorMessage]);
}
}

View File

@@ -191,6 +191,7 @@ final class ExportControllerTest extends AbstractTestCase
$dbi = $this->createDatabaseInterface(config: $config);
$events = new Events($dbi, $config);
$responseRenderer = new ResponseRenderer();
$responseRenderer->setAjax(true);
$request = ServerRequestFactory::create()->createServerRequest('GET', 'https://example.com/')
->withHeader('X-Requested-With', 'XMLHttpRequest');
@@ -198,8 +199,12 @@ final class ExportControllerTest extends AbstractTestCase
$response = (new ExportController($responseRenderer, $events, new DbTableExists($dbi)))($request);
self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
self::assertSame('', (string) $response->getBody());
self::assertSame(['message' => 'No database selected.'], $responseRenderer->getJSONResult());
self::assertSame(
'{"success":false,"error":"<div class=\"alert alert-danger\" role=\"alert\">\n'
. ' <img src=\"themes\/dot.gif\" title=\"\" alt=\"\" class=\"icon ic_s_error\"> No database selected.\n'
. '<\/div>\n"}',
(string) $response->getBody(),
);
self::assertFalse($responseRenderer->hasSuccessState());
}
}

View File

@@ -154,6 +154,7 @@ final class IndexControllerTest extends AbstractTestCase
$dbi = $this->createDatabaseInterface(config: $config);
$template = new Template($config);
$responseRenderer = new ResponseRenderer();
$responseRenderer->setAjax(true);
$request = ServerRequestFactory::create()->createServerRequest('GET', 'https://example.com/')
->withHeader('X-Requested-With', 'XMLHttpRequest');
@@ -166,8 +167,12 @@ final class IndexControllerTest extends AbstractTestCase
))($request);
self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
self::assertSame('', (string) $response->getBody());
self::assertSame(['message' => 'No database selected.'], $responseRenderer->getJSONResult());
self::assertSame(
'{"success":false,"error":"<div class=\"alert alert-danger\" role=\"alert\">\n'
. ' <img src=\"themes\/dot.gif\" title=\"\" alt=\"\" class=\"icon ic_s_error\"> No database selected.\n'
. '<\/div>\n"}',
(string) $response->getBody(),
);
self::assertFalse($responseRenderer->hasSuccessState());
}

View File

@@ -56,6 +56,6 @@ class DestroyControllerTest extends AbstractTestCase
self::assertArrayHasKey('message', $actual);
self::assertIsString($actual['message']);
self::assertStringContainsString('<div class="alert alert-danger" role="alert">', $actual['message']);
self::assertStringContainsString(__('No databases selected.'), $actual['message']);
self::assertStringContainsString(__('No database selected.'), $actual['message']);
}
}