Skip to content

Commit b2a3e41

Browse files
Merge pull request #19087 from MauricioFauth/navigation-config-handling
Remove Config\(G|S)etConfigController controllers
2 parents e4cf5ab + d4cdfbe commit b2a3e41

10 files changed

Lines changed: 145 additions & 188 deletions

File tree

app/services_controllers.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PhpMyAdmin\Controllers\CheckRelationsController;
99
use PhpMyAdmin\Controllers\CollationConnectionController;
1010
use PhpMyAdmin\Controllers\ColumnController;
11-
use PhpMyAdmin\Controllers\Config;
1211
use PhpMyAdmin\Controllers\Console;
1312
use PhpMyAdmin\Controllers\Database;
1413
use PhpMyAdmin\Controllers\DatabaseController;
@@ -22,6 +21,7 @@
2221
use PhpMyAdmin\Controllers\LicenseController;
2322
use PhpMyAdmin\Controllers\LintController;
2423
use PhpMyAdmin\Controllers\LogoutController;
24+
use PhpMyAdmin\Controllers\Navigation\UpdateNavWidthConfigController;
2525
use PhpMyAdmin\Controllers\NavigationController;
2626
use PhpMyAdmin\Controllers\Normalization;
2727
use PhpMyAdmin\Controllers\Operations;
@@ -73,12 +73,8 @@
7373
'class' => ColumnController::class,
7474
'arguments' => ['$response' => '@response', '$template' => '@template', '$dbi' => '@dbi'],
7575
],
76-
Config\GetConfigController::class => [
77-
'class' => Config\GetConfigController::class,
78-
'arguments' => ['$response' => '@response', '$template' => '@template', '$config' => '@config'],
79-
],
80-
Config\SetConfigController::class => [
81-
'class' => Config\SetConfigController::class,
76+
UpdateNavWidthConfigController::class => [
77+
'class' => UpdateNavWidthConfigController::class,
8278
'arguments' => ['$response' => '@response', '$template' => '@template', '$config' => '@config'],
8379
],
8480
Console\Bookmark\AddController::class => [

psalm-baseline.xml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -854,16 +854,6 @@
854854
<code><![CDATA[Config::getInstance()]]></code>
855855
</DeprecatedMethod>
856856
</file>
857-
<file src="src/Controllers/Config/GetConfigController.php">
858-
<PossiblyUnusedMethod>
859-
<code><![CDATA[__construct]]></code>
860-
</PossiblyUnusedMethod>
861-
</file>
862-
<file src="src/Controllers/Config/SetConfigController.php">
863-
<PossiblyUnusedMethod>
864-
<code><![CDATA[__construct]]></code>
865-
</PossiblyUnusedMethod>
866-
</file>
867857
<file src="src/Controllers/Console/Bookmark/AddController.php">
868858
<DeprecatedMethod>
869859
<code><![CDATA[Config::getInstance()]]></code>
@@ -12570,6 +12560,12 @@
1257012560
<code><![CDATA[Config::getInstance()]]></code>
1257112561
</DeprecatedMethod>
1257212562
</file>
12563+
<file src="tests/unit/Controllers/Navigation/UpdateNavWidthConfigControllerTest.php">
12564+
<PossiblyUnusedMethod>
12565+
<code><![CDATA[invalidParamsProvider]]></code>
12566+
<code><![CDATA[validParamsProvider]]></code>
12567+
</PossiblyUnusedMethod>
12568+
</file>
1257312569
<file src="tests/unit/Controllers/NavigationControllerTest.php">
1257412570
<DeprecatedMethod>
1257512571
<code><![CDATA[Config::getInstance()]]></code>

resources/js/src/modules/functions/config.ts

Lines changed: 0 additions & 99 deletions
This file was deleted.

resources/js/src/modules/navigation.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import $ from 'jquery';
22
import { CommonParams } from './common.ts';
33
import { Config } from './config.ts';
44
import { ajaxRemoveMessage, ajaxShowMessage } from './ajax-message.ts';
5-
import { getConfigValue, setConfigValue } from './functions/config.ts';
5+
import updateNavigationWidthConfig from './navigation/updateNavigationWidthConfig.ts';
66
import handleRedirectAndReload from './functions/handleRedirectAndReload.ts';
77
import isStorageSupported from './functions/isStorageSupported.ts';
88

@@ -908,7 +908,7 @@ const ResizeHandler = function () {
908908
*/
909909
this.mouseup = function (event): void {
910910
$('body').css('cursor', '');
911-
setConfigValue('NavigationWidth', event.data.resize_handler.getPos(event));
911+
updateNavigationWidthConfig(event.data.resize_handler.getPos(event));
912912
$('#topmenu').menuResizer('resize');
913913
$(document)
914914
.off('mousemove')
@@ -941,7 +941,7 @@ const ResizeHandler = function () {
941941
panelWidth = 240;
942942
}
943943

944-
setConfigValue('NavigationWidth', panelWidth);
944+
updateNavigationWidthConfig(panelWidth);
945945
event.data.resize_handler.setWidth(panelWidth);
946946
event.data.resize_handler.panelWidth = width;
947947
};
@@ -985,27 +985,19 @@ const ResizeHandler = function () {
985985
$(document).on('mousedown', '#pma_navigation_resizer', { 'resize_handler': this }, this.mousedown);
986986
$(document).on('click', '#pma_navigation_collapser', { 'resize_handler': this }, this.collapse);
987987

988+
const navigationDiv = $('#pma_navigation');
988989
// Add the correct arrow symbol to the collapser
989-
$('#pma_navigation_collapser').html(this.getSymbol($('#pma_navigation').width()));
990+
$('#pma_navigation_collapser').html(this.getSymbol(navigationDiv.width()));
990991
// Fix navigation tree height
991992
$(window).on('resize', this.treeResize);
992993
// need to call this now and then, browser might decide
993994
// to show/hide horizontal scrollbars depending on page content width
994995
setInterval(this.treeResize, 2000);
995996
this.treeResize();
996-
const callbackSuccessGetConfigValue = (data) => {
997-
this.setWidth(data);
998-
$('#topmenu').menuResizer('resize');
999-
};
1000-
1001-
// Skip mobile
1002-
if (isLoadedOnMobile === false) {
1003-
// Make an init using the default found value
1004-
const initialResizeValue = $('#pma_navigation').data('config-navigation-width');
1005-
callbackSuccessGetConfigValue(initialResizeValue);
1006-
}
1007997

1008-
getConfigValue('NavigationWidth', false, callbackSuccessGetConfigValue);
998+
const initialResizeValue = Number(navigationDiv.data('config-navigation-width'));
999+
this.setWidth(initialResizeValue);
1000+
$('#topmenu').menuResizer('resize');
10091001
};
10101002

10111003
this.treeInit();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import $ from 'jquery';
2+
import { ajaxShowMessage } from '../ajax-message.ts';
3+
import { CommonParams } from '../common.ts';
4+
5+
export default function updateNavigationWidthConfig (value: number): void {
6+
$.ajax({
7+
url: 'index.php?route=/navigation/update-width',
8+
type: 'POST',
9+
dataType: 'json',
10+
data: {
11+
'ajax_request': true,
12+
server: CommonParams.get('server'),
13+
value: value,
14+
},
15+
success: function (data) {
16+
if (data.success !== true) {
17+
// Try to find a message to display
18+
if (data.error || data.message) {
19+
ajaxShowMessage(data.error || data.message);
20+
}
21+
}
22+
}
23+
});
24+
}

src/Controllers/Config/GetConfigController.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/Controllers/Config/SetConfigController.php renamed to src/Controllers/Navigation/UpdateNavWidthConfigController.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace PhpMyAdmin\Controllers\Config;
5+
namespace PhpMyAdmin\Controllers\Navigation;
66

77
use PhpMyAdmin\Config;
88
use PhpMyAdmin\Controllers\AbstractController;
@@ -11,31 +11,27 @@
1111
use PhpMyAdmin\ResponseRenderer;
1212
use PhpMyAdmin\Template;
1313

14-
use function json_decode;
14+
use function __;
15+
use function is_numeric;
1516

16-
final class SetConfigController extends AbstractController
17+
final class UpdateNavWidthConfigController extends AbstractController
1718
{
18-
public function __construct(ResponseRenderer $response, Template $template, private Config $config)
19+
public function __construct(ResponseRenderer $response, Template $template, private readonly Config $config)
1920
{
2021
parent::__construct($response, $template);
2122
}
2223

2324
public function __invoke(ServerRequest $request): void
2425
{
25-
/** @var string|null $key */
26-
$key = $request->getParsedBodyParam('key');
27-
/** @var string|null $value */
2826
$value = $request->getParsedBodyParam('value');
29-
30-
if (! isset($key, $value)) {
27+
if (! is_numeric($value) || $value < 0) {
3128
$this->response->setRequestStatus(false);
32-
$this->response->addJSON(['message' => Message::error()]);
29+
$this->response->addJSON(['message' => Message::error(__('Unexpected parameter value.'))]);
3330

3431
return;
3532
}
3633

37-
$result = $this->config->setUserValue(null, $key, json_decode($value));
38-
34+
$result = $this->config->setUserValue(null, 'NavigationWidth', (int) $value);
3935
if ($result === true) {
4036
return;
4137
}

src/Routing/Routes.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PhpMyAdmin\Controllers\CheckRelationsController;
1111
use PhpMyAdmin\Controllers\CollationConnectionController;
1212
use PhpMyAdmin\Controllers\ColumnController;
13-
use PhpMyAdmin\Controllers\Config;
1413
use PhpMyAdmin\Controllers\Console\Bookmark;
1514
use PhpMyAdmin\Controllers\Console\UpdateConfigController;
1615
use PhpMyAdmin\Controllers\Database;
@@ -25,6 +24,7 @@
2524
use PhpMyAdmin\Controllers\LicenseController;
2625
use PhpMyAdmin\Controllers\LintController;
2726
use PhpMyAdmin\Controllers\LogoutController;
27+
use PhpMyAdmin\Controllers\Navigation\UpdateNavWidthConfigController;
2828
use PhpMyAdmin\Controllers\NavigationController;
2929
use PhpMyAdmin\Controllers\Normalization;
3030
use PhpMyAdmin\Controllers\Operations;
@@ -54,10 +54,6 @@ public static function collect(RouteCollector $routes): void
5454
$routes->addRoute(['GET', 'POST'], '/check-relations', CheckRelationsController::class);
5555
$routes->post('/collation-connection', CollationConnectionController::class);
5656
$routes->post('/columns', ColumnController::class);
57-
$routes->addGroup('/config', static function (RouteCollector $routes): void {
58-
$routes->post('/get', Config\GetConfigController::class);
59-
$routes->post('/set', Config\SetConfigController::class);
60-
});
6157
$routes->addGroup('/console', static function (RouteCollector $routes): void {
6258
$routes->addGroup('/bookmark', static function (RouteCollector $routes): void {
6359
$routes->post('/add', Bookmark\AddController::class);
@@ -143,7 +139,10 @@ public static function collect(RouteCollector $routes): void
143139
$routes->addRoute(['GET', 'POST'], '/lint', LintController::class);
144140
$routes->addRoute(['GET', 'POST'], '/logout', LogoutController::class);
145141
$routes->get('/messages', JavaScriptMessagesController::class);
146-
$routes->addRoute(['GET', 'POST'], '/navigation', NavigationController::class);
142+
$routes->addGroup('/navigation', static function (RouteCollector $routes): void {
143+
$routes->addRoute(['GET', 'POST'], '', NavigationController::class);
144+
$routes->post('/update-width', UpdateNavWidthConfigController::class);
145+
});
147146
$routes->addGroup('/normalization', static function (RouteCollector $routes): void {
148147
$routes->addRoute(['GET', 'POST'], '', Normalization\MainController::class);
149148
$routes->post('/1nf/step1', Normalization\FirstNormalForm\FirstStepController::class);

0 commit comments

Comments
 (0)