Skip to content

Commit c2018c4

Browse files
committed
Extract /console/bookmark/refresh action from ImportController
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 2076d52 commit c2018c4

6 files changed

Lines changed: 51 additions & 13 deletions

File tree

js/src/modules/console.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,11 +1051,10 @@ var ConsoleBookmarks = {
10511051
}
10521052
},
10531053
refresh: function () {
1054-
$.get('index.php?route=/import',
1054+
$.get('index.php?route=/console/bookmark/refresh',
10551055
{
10561056
'ajax_request': true,
10571057
'server': window.CommonParams.get('server'),
1058-
'console_bookmark_refresh': 'refresh'
10591058
},
10601059
function (data) {
10611060
if (data.console_message_bookmark) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Controllers\Console\Bookmark;
6+
7+
use PhpMyAdmin\Console;
8+
use PhpMyAdmin\Controllers\AbstractController;
9+
use PhpMyAdmin\Http\ServerRequest;
10+
11+
final class RefreshController extends AbstractController
12+
{
13+
public function __invoke(ServerRequest $request): void
14+
{
15+
$this->response->addJSON('console_message_bookmark', Console::getBookmarkContent());
16+
}
17+
}

libraries/classes/Controllers/Import/ImportController.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use PhpMyAdmin\Bookmark;
88
use PhpMyAdmin\ConfigStorage\Relation;
9-
use PhpMyAdmin\Console;
109
use PhpMyAdmin\Controllers\AbstractController;
1110
use PhpMyAdmin\Core;
1211
use PhpMyAdmin\DatabaseInterface;
@@ -119,16 +118,6 @@ public function __invoke(ServerRequest $request): void
119118
$GLOBALS['local_import_file'] = $_POST['local_import_file'] ?? null;
120119
$GLOBALS['show_as_php'] = $_POST['show_as_php'] ?? null;
121120

122-
// If it's a refresh console bookmarks request
123-
if (isset($_GET['console_bookmark_refresh'])) {
124-
$this->response->addJSON(
125-
'console_message_bookmark',
126-
Console::getBookmarkContent()
127-
);
128-
129-
return;
130-
}
131-
132121
// If it's a console bookmark add request
133122
if (isset($_POST['console_bookmark_add'])) {
134123
if (! isset($_POST['label'], $_POST['db'], $_POST['bookmark_query'], $_POST['shared'])) {

libraries/routes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpMyAdmin\Controllers\CollationConnectionController;
1010
use PhpMyAdmin\Controllers\ColumnController;
1111
use PhpMyAdmin\Controllers\Config;
12+
use PhpMyAdmin\Controllers\Console\Bookmark\RefreshController;
1213
use PhpMyAdmin\Controllers\Database;
1314
use PhpMyAdmin\Controllers\DatabaseController;
1415
use PhpMyAdmin\Controllers\ErrorReportController;
@@ -53,6 +54,7 @@
5354
$routes->post('/get', Config\GetConfigController::class);
5455
$routes->post('/set', Config\SetConfigController::class);
5556
});
57+
$routes->get('/console/bookmark/refresh', RefreshController::class);
5658
$routes->addGroup('/database', static function (RouteCollector $routes): void {
5759
$routes->addGroup('/central-columns', static function (RouteCollector $routes): void {
5860
$routes->addRoute(['GET', 'POST'], '', Database\CentralColumnsController::class);

libraries/services_controllers.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpMyAdmin\Controllers\CollationConnectionController;
99
use PhpMyAdmin\Controllers\ColumnController;
1010
use PhpMyAdmin\Controllers\Config;
11+
use PhpMyAdmin\Controllers\Console;
1112
use PhpMyAdmin\Controllers\Database;
1213
use PhpMyAdmin\Controllers\DatabaseController;
1314
use PhpMyAdmin\Controllers\ErrorReportController;
@@ -95,6 +96,10 @@
9596
'$config' => '@config',
9697
],
9798
],
99+
Console\Bookmark\RefreshController::class => [
100+
'class' => Console\Bookmark\RefreshController::class,
101+
'arguments' => ['$response' => '@response', '$template' => '@template'],
102+
],
98103
Database\CentralColumns\PopulateColumnsController::class => [
99104
'class' => Database\CentralColumns\PopulateColumnsController::class,
100105
'arguments' => [
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Tests\Controllers\Console\Bookmark;
6+
7+
use PhpMyAdmin\Controllers\Console\Bookmark\RefreshController;
8+
use PhpMyAdmin\Http\ServerRequest;
9+
use PhpMyAdmin\Template;
10+
use PhpMyAdmin\Tests\AbstractTestCase;
11+
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
12+
13+
/**
14+
* @covers \PhpMyAdmin\Controllers\Console\Bookmark\RefreshController
15+
*/
16+
class RefreshControllerTest extends AbstractTestCase
17+
{
18+
public function testDefault(): void
19+
{
20+
$GLOBALS['dbi'] = $this->createDatabaseInterface();
21+
$response = new ResponseRenderer();
22+
$controller = new RefreshController($response, new Template());
23+
$controller($this->createStub(ServerRequest::class));
24+
$this->assertSame(['console_message_bookmark' => ''], $response->getJSONResult());
25+
}
26+
}

0 commit comments

Comments
 (0)