From 4c789727e9c08db5008230a46bcf02e8a4577d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Mon, 14 Jul 2025 22:12:17 -0300 Subject: [PATCH] Add Response return for UserPreferences::redirect() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- src/Controllers/Preferences/ExportController.php | 3 +-- src/Controllers/Preferences/FeaturesController.php | 3 +-- src/Controllers/Preferences/ImportController.php | 3 +-- src/Controllers/Preferences/MainPanelController.php | 3 +-- src/Controllers/Preferences/ManageController.php | 6 ++---- src/Controllers/Preferences/NavigationController.php | 3 +-- src/Controllers/Preferences/SqlController.php | 3 +-- src/UserPreferences.php | 8 ++++++-- tests/unit/UserPreferencesTest.php | 3 +-- 9 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/Controllers/Preferences/ExportController.php b/src/Controllers/Preferences/ExportController.php index 15cf8ce3f6..018e1044e3 100644 --- a/src/Controllers/Preferences/ExportController.php +++ b/src/Controllers/Preferences/ExportController.php @@ -61,9 +61,8 @@ final readonly class ExportController implements InvocableController // reload config $this->config->loadUserPreferences($this->themeManager); $hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#'); - $this->userPreferences->redirect('index.php?route=/preferences/export', null, $hash); - return $this->response->response(); + return $this->userPreferences->redirect('index.php?route=/preferences/export', null, $hash); } } diff --git a/src/Controllers/Preferences/FeaturesController.php b/src/Controllers/Preferences/FeaturesController.php index ed819e4ba7..755a2732d4 100644 --- a/src/Controllers/Preferences/FeaturesController.php +++ b/src/Controllers/Preferences/FeaturesController.php @@ -61,9 +61,8 @@ final readonly class FeaturesController implements InvocableController // reload config $this->config->loadUserPreferences($this->themeManager); $hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#'); - $this->userPreferences->redirect('index.php?route=/preferences/features', null, $hash); - return $this->response->response(); + return $this->userPreferences->redirect('index.php?route=/preferences/features', null, $hash); } } diff --git a/src/Controllers/Preferences/ImportController.php b/src/Controllers/Preferences/ImportController.php index b6a88e23a3..febd88d890 100644 --- a/src/Controllers/Preferences/ImportController.php +++ b/src/Controllers/Preferences/ImportController.php @@ -61,9 +61,8 @@ final readonly class ImportController implements InvocableController // reload config $this->config->loadUserPreferences($this->themeManager); $hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#'); - $this->userPreferences->redirect('index.php?route=/preferences/import', null, $hash); - return $this->response->response(); + return $this->userPreferences->redirect('index.php?route=/preferences/import', null, $hash); } } diff --git a/src/Controllers/Preferences/MainPanelController.php b/src/Controllers/Preferences/MainPanelController.php index a7bae11495..5f04a2a54a 100644 --- a/src/Controllers/Preferences/MainPanelController.php +++ b/src/Controllers/Preferences/MainPanelController.php @@ -61,9 +61,8 @@ final readonly class MainPanelController implements InvocableController // reload config $this->config->loadUserPreferences($this->themeManager); $hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#'); - $this->userPreferences->redirect('index.php?route=/preferences/main-panel', null, $hash); - return $this->response->response(); + return $this->userPreferences->redirect('index.php?route=/preferences/main-panel', null, $hash); } } diff --git a/src/Controllers/Preferences/ManageController.php b/src/Controllers/Preferences/ManageController.php index c9b711d4d8..b2b36e1440 100644 --- a/src/Controllers/Preferences/ManageController.php +++ b/src/Controllers/Preferences/ManageController.php @@ -219,9 +219,8 @@ final class ManageController implements InvocableController // reload config $this->config->loadUserPreferences($this->themeManager); - $this->userPreferences->redirect($returnUrl ?? '', $redirectParams); - return $this->response->response(); + return $this->userPreferences->redirect($returnUrl ?? '', $redirectParams); } $error = $result; @@ -230,9 +229,8 @@ final class ManageController implements InvocableController $result = $this->userPreferences->save([]); if ($result === true) { $this->config->removeCookie('pma_lang'); - $this->userPreferences->redirect('index.php?route=/preferences/manage'); - return $this->response->response(); + return $this->userPreferences->redirect('index.php?route=/preferences/manage'); } return $this->response->response(); diff --git a/src/Controllers/Preferences/NavigationController.php b/src/Controllers/Preferences/NavigationController.php index a3502fafa5..543b162de6 100644 --- a/src/Controllers/Preferences/NavigationController.php +++ b/src/Controllers/Preferences/NavigationController.php @@ -61,9 +61,8 @@ final readonly class NavigationController implements InvocableController // reload config $this->config->loadUserPreferences($this->themeManager); $hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#'); - $this->userPreferences->redirect('index.php?route=/preferences/navigation', null, $hash); - return $this->response->response(); + return $this->userPreferences->redirect('index.php?route=/preferences/navigation', null, $hash); } } diff --git a/src/Controllers/Preferences/SqlController.php b/src/Controllers/Preferences/SqlController.php index b5c93a3537..146e1da47c 100644 --- a/src/Controllers/Preferences/SqlController.php +++ b/src/Controllers/Preferences/SqlController.php @@ -61,9 +61,8 @@ final readonly class SqlController implements InvocableController // reload config $this->config->loadUserPreferences($this->themeManager); $hash = ltrim($request->getParsedBodyParamAsString('tab_hash'), '#'); - $this->userPreferences->redirect('index.php?route=/preferences/sql', null, $hash); - return $this->response->response(); + return $this->userPreferences->redirect('index.php?route=/preferences/sql', null, $hash); } } diff --git a/src/UserPreferences.php b/src/UserPreferences.php index 1fe533f73b..b60e55f27b 100644 --- a/src/UserPreferences.php +++ b/src/UserPreferences.php @@ -9,6 +9,7 @@ use PhpMyAdmin\Config\Forms\User\UserFormList; use PhpMyAdmin\ConfigStorage\Relation; use PhpMyAdmin\Dbal\ConnectionType; use PhpMyAdmin\Dbal\DatabaseInterface; +use PhpMyAdmin\Http\Response; use PhpMyAdmin\Identifiers\DatabaseName; use function __; @@ -259,7 +260,7 @@ class UserPreferences string $fileName, array|null $params = null, string|null $hash = null, - ): void { + ): Response { // redirect $urlParams = ['saved' => 1]; if (is_array($params)) { @@ -270,9 +271,12 @@ class UserPreferences $hash = '#' . urlencode($hash); } - ResponseRenderer::getInstance()->redirect( + $responseRenderer = ResponseRenderer::getInstance(); + $responseRenderer->redirect( './' . $fileName . Url::getCommonRaw($urlParams, ! str_contains($fileName, '?') ? '?' : '&') . $hash, ); + + return $responseRenderer->response(); } /** diff --git a/tests/unit/UserPreferencesTest.php b/tests/unit/UserPreferencesTest.php index 787d2ed92f..96de41381a 100644 --- a/tests/unit/UserPreferencesTest.php +++ b/tests/unit/UserPreferencesTest.php @@ -327,13 +327,12 @@ class UserPreferencesTest extends AbstractTestCase $dbi = DatabaseInterface::getInstance(); $userPreferences = new UserPreferences($dbi, new Relation($dbi), new Template()); - $userPreferences->redirect( + $response = $userPreferences->redirect( 'file.html', ['a' => 'b'], 'h ash', ); - $response = $responseStub->getResponse(); self::assertSame(['/phpmyadmin/file.html?a=b&saved=1&server=2#h+ash'], $response->getHeader('Location')); self::assertSame(302, $response->getStatusCode()); }