Visitar URL original
Merge #20542 - New respondWithErrorMessage() · phpmyadmin/phpmyadmin@ef2fcd2 · GitHub
Skip to content

Commit ef2fcd2

Browse files
committed
Merge #20542 - New respondWithErrorMessage()
Closes #20542 Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.com.br>
2 parents df0f08f + ef60f1d commit ef2fcd2

40 files changed

Lines changed: 83 additions & 406 deletions

‎src/Controllers/Database/DesignerController.php‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use PhpMyAdmin\Http\Response;
1414
use PhpMyAdmin\Http\ServerRequest;
1515
use PhpMyAdmin\Identifiers\DatabaseName;
16-
use PhpMyAdmin\Message;
1716
use PhpMyAdmin\ResponseRenderer;
1817
use PhpMyAdmin\Routing\Route;
1918
use PhpMyAdmin\Template;
@@ -170,14 +169,7 @@ public function __invoke(ServerRequest $request): Response
170169

171170
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
172171
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
173-
if ($request->isAjax()) {
174-
$this->response->setRequestStatus(false);
175-
$this->response->addJSON('message', Message::error(__('No databases selected.')));
176-
177-
return $this->response->response();
178-
}
179-
180-
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
172+
return $this->response->respondWithErrorMessage(__('No database selected.'));
181173
}
182174

183175
$scriptDisplayField = $this->designerCommon->getTablesInfo();

‎src/Controllers/Database/ExportController.php‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,7 @@ public function __invoke(ServerRequest $request): Response
5252

5353
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
5454
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
55-
if ($request->isAjax()) {
56-
$this->response->setRequestStatus(false);
57-
$this->response->addJSON('message', Message::error(__('No databases selected.')));
58-
59-
return $this->response->response();
60-
}
61-
62-
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
55+
return $this->response->respondWithErrorMessage(__('No database selected.'));
6356
}
6457

6558
UrlParams::$params['goto'] = Url::getFromRoute('/database/export');

‎src/Controllers/Database/ImportController.php‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,7 @@ public function __invoke(ServerRequest $request): Response
5757

5858
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
5959
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
60-
if ($request->isAjax()) {
61-
$this->response->setRequestStatus(false);
62-
$this->response->addJSON('message', Message::error(__('No databases selected.')));
63-
64-
return $this->response->response();
65-
}
66-
67-
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
60+
return $this->response->respondWithErrorMessage(__('No database selected.'));
6861
}
6962

7063
$uploadId = $this->ajax->uploadProgressSetup();

‎src/Controllers/Database/RoutinesController.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __invoke(ServerRequest $request): Response
7575
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
7676
return $this->response->redirectToRoute(
7777
'/',
78-
['reload' => true, 'message' => __('No databases selected.')],
78+
['reload' => true, 'message' => __('No database selected.')],
7979
);
8080
}
8181

@@ -93,7 +93,7 @@ public function __invoke(ServerRequest $request): Response
9393
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
9494
return $this->response->redirectToRoute(
9595
'/',
96-
['reload' => true, 'message' => __('No databases selected.')],
96+
['reload' => true, 'message' => __('No database selected.')],
9797
);
9898
}
9999
}

‎src/Controllers/Database/SearchController.php‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,7 @@ public function __invoke(ServerRequest $request): Response
4848

4949
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
5050
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
51-
if ($request->isAjax()) {
52-
$this->response->setRequestStatus(false);
53-
$this->response->addJSON('message', Message::error(__('No databases selected.')));
54-
55-
return $this->response->response();
56-
}
57-
58-
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
51+
return $this->response->respondWithErrorMessage(__('No database selected.'));
5952
}
6053

6154
if (! $this->config->config->UseDbSearch) {

‎src/Controllers/Database/SqlController.php‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use PhpMyAdmin\Http\Response;
1212
use PhpMyAdmin\Http\ServerRequest;
1313
use PhpMyAdmin\Identifiers\DatabaseName;
14-
use PhpMyAdmin\Message;
1514
use PhpMyAdmin\ResponseRenderer;
1615
use PhpMyAdmin\Routing\Route;
1716
use PhpMyAdmin\SqlQueryForm;
@@ -49,14 +48,7 @@ public function __invoke(ServerRequest $request): Response
4948

5049
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
5150
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
52-
if ($request->isAjax()) {
53-
$this->response->setRequestStatus(false);
54-
$this->response->addJSON('message', Message::error(__('No databases selected.')));
55-
56-
return $this->response->response();
57-
}
58-
59-
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
51+
return $this->response->respondWithErrorMessage(__('No database selected.'));
6052
}
6153

6254
/**

‎src/Controllers/Database/Structure/FavoriteTableController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __invoke(ServerRequest $request): Response
6262
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
6363
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
6464
$this->response->setRequestStatus(false);
65-
$this->response->addJSON('message', Message::error(__('No databases selected.')));
65+
$this->response->addJSON('message', Message::error(__('No database selected.')));
6666

6767
return $this->response->response();
6868
}

‎src/Controllers/Database/Structure/RealRowCountController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __invoke(ServerRequest $request): Response
4949
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
5050
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
5151
$this->response->setRequestStatus(false);
52-
$this->response->addJSON('message', Message::error(__('No databases selected.')));
52+
$this->response->addJSON('message', Message::error(__('No database selected.')));
5353

5454
return $this->response->response();
5555
}

‎src/Controllers/Database/StructureController.php‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use PhpMyAdmin\Http\ServerRequest;
2323
use PhpMyAdmin\Identifiers\DatabaseName;
2424
use PhpMyAdmin\Identifiers\TableName;
25-
use PhpMyAdmin\Message;
2625
use PhpMyAdmin\Query\Utilities;
2726
use PhpMyAdmin\Replication\Replication;
2827
use PhpMyAdmin\Replication\ReplicationInfo;
@@ -155,14 +154,7 @@ public function __invoke(ServerRequest $request): Response
155154

156155
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
157156
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
158-
if ($request->isAjax()) {
159-
$this->response->setRequestStatus(false);
160-
$this->response->addJSON('message', Message::error(__('No databases selected.')));
161-
162-
return $this->response->response();
163-
}
164-
165-
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
157+
return $this->response->respondWithErrorMessage(__('No database selected.'));
166158
}
167159

168160
$this->response->addScriptFiles(['database/structure.js', 'table/change.js']);

‎src/Controllers/Database/TrackingController.php‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,7 @@ public function __invoke(ServerRequest $request): Response
5050

5151
$databaseName = DatabaseName::tryFrom($request->getParam('db'));
5252
if ($databaseName === null || ! $this->dbTableExists->selectDatabase($databaseName)) {
53-
if ($request->isAjax()) {
54-
$this->response->setRequestStatus(false);
55-
$this->response->addJSON('message', Message::error(__('No databases selected.')));
56-
57-
return $this->response->response();
58-
}
59-
60-
return $this->response->redirectToRoute('/', ['reload' => true, 'message' => __('No databases selected.')]);
53+
return $this->response->respondWithErrorMessage(__('No database selected.'));
6154
}
6255

6356
UrlParams::$params['goto'] = Url::getFromRoute('/table/tracking');

0 commit comments

Comments
 (0)